summaryrefslogtreecommitdiffstats
path: root/perl-install/my_gtk.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/my_gtk.pm')
-rw-r--r--perl-install/my_gtk.pm287
1 files changed, 152 insertions, 135 deletions
diff --git a/perl-install/my_gtk.pm b/perl-install/my_gtk.pm
index a6f1101d5..1205a7eda 100644
--- a/perl-install/my_gtk.pm
+++ b/perl-install/my_gtk.pm
@@ -6,7 +6,7 @@ use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK);
@ISA = qw(Exporter);
%EXPORT_TAGS = (
- all => [ qw(create_window create_yesorno createScrolledWindow create_menu create_notebook create_packtable create_hbox create_adjustment mymain my_signal_connect mypack mypack_ myappend myadd label_align myset_usize myset_justify myshow mysync myflush mydestroy) ],
+ all => [ qw(ask_warn ask_yesorno ask_from_entry ask_from_list create_yesorno createScrolledWindow create_menu create_notebook create_packtable create_hbox create_adjustment gtksignal_connect gtkpack gtkpack_ gtkappend gtkadd gtkset_usize gtkset_justify gtkshow gtkdestroy) ],
);
@EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
@@ -14,101 +14,118 @@ use Gtk;
1;
-
+################################################################################
+# OO stuff
+################################################################################
sub new {
my ($type, $title, @opts) = @_;
Gtk->init;
parse Gtk::Rc "$ENV{HOME}/etc/any/Gtkrc";
my $o = bless { @opts }, $type;
- $o->{window} = $o->create_window($title);
+ $o->{window} = $o->_create_window($title);
$o;
}
+sub main($) {
+ my $o = shift;
+ $o->{window}->show;
+ Gtk->main;
+ $o->destroy;
+ $o->{retval}
+}
sub destroy($) {
my ($o) = @_;
$o->{window}->destroy;
- myflush();
+ flush();
}
+sub sync($) {
+ my ($o) = @_;
+ $o->{window}->show;
-sub ask_from_entry($$@) {
- my ($o, @msgs) = @_;
- my $entry = new Gtk::Entry;
- my $f = sub { $o->{retval} = $entry->get_text; Gtk->main_quit };
-
- myadd($o->{window},
- mypack($o->create_box_with_title(@msgs),
- my_signal_connect($entry, 'activate' => $f),
- ($o->{hide_buttons} ? () : mypack(new Gtk::HBox(0,0),
- my_signal_connect(new Gtk::Button('Ok'), 'clicked' => $f),
- my_signal_connect(new Gtk::Button('Cancel'), 'clicked' => sub { $o->{retval} = undef; Gtk->main_quit }),
- )),
- ),
- );
- $entry->grab_focus();
- mymain($o);
+ my $h = Gtk->idle_add(sub { Gtk->main_quit; 1 });
+ map { Gtk->main } (1..4);
+ Gtk->idle_remove($h);
+}
+sub flush(;$) {
+ Gtk->main_iteration while Gtk::Gdk->events_pending;
+}
+sub bigsize($) {
+ $_[0]->{window}->set_usize(600,400);
}
-sub ask_from_list($\@$@) {
- my ($o, $l, @msgs) = @_;
- my $f = sub { $o->{retval} = $_[1]; Gtk->main_quit };
- my @l = map { my_signal_connect(new Gtk::Button($_), "clicked" => $f, $_) } @$l;
+sub gtkshow($) { $_[0]->show; $_[0] }
+sub gtkdestroy($) { $_[0] and $_[0]->destroy }
+sub gtkset_usize($$$) { $_[0]->set_usize($_[1],$_[2]); $_[0] }
+sub gtkset_justify($$) { $_[0]->set_justify($_[1]); $_[0] }
-# myadd($o->{window},
-# mypack_(myset_usize(new Gtk::VBox(0,0), 0, 200),
-# 0, $o->create_box_with_title(@msgs),
-# 1, createScrolledWindow(mypack(new Gtk::VBox(0,0), @l))));
- myadd($o->{window},
- mypack($o->create_box_with_title(@msgs), @l));
- $l[0]->grab_focus();
- mymain($o)
+sub gtksignal_connect($@) {
+ my $w = shift;
+ $w->signal_connect(@_);
+ $w
+}
+sub gtkpack($@) {
+ my $box = shift;
+ foreach (@_) {
+ my $l = $_;
+ ref $l or $l = new Gtk::Label($l);
+ $box->pack_start($l, 1, 1, 0);
+ $l->show;
+ }
+ $box
+}
+sub gtkpack_($@) {
+ my $box = shift;
+ for (my $i = 0; $i < @_; $i += 2) {
+ my $l = $_[$i + 1];
+ ref $l or $l = new Gtk::Label($l);
+ $box->pack_start($l, $_[$i], 1, 0);
+ $_[$i + 1]->show;
+ }
+ $box
+}
+sub gtkappend($@) {
+ my $w = shift;
+ foreach (@_) {
+ my $l = $_;
+ ref $l or $l = new Gtk::Label($l);
+ $w->append($l);
+ $l->show;
+ }
+ $w
+}
+sub gtkadd($@) {
+ my $w = shift;
+ foreach (@_) {
+ my $l = $_;
+ ref $l or $l = new Gtk::Label($l);
+ $w->add($l);
+ $l->show;
+ }
+ $w
}
-sub ask_warn($@) {
- my ($o, @msgs) = @_;
-
- myadd($o->{window},
- mypack($o->create_box_with_title(@msgs),
- my_signal_connect(my $w = new Gtk::Button("Ok"), "clicked" => sub { Gtk->main_quit }),
- ),
- );
- $w->grab_focus();
- mymain($o)
-}
-sub ask_yesorno($@) {
- my ($o, @msgs) = @_;
- myadd($o->{window},
- mypack(create_box_with_title($o, @msgs),
- create_yesorno($o),
- )
- );
- $o->{ok}->grab_focus();
- mymain($o)
-}
+################################################################################
+# createXXX functions
-sub create_window($$) {
- my ($o, $title) = @_;
- $o->{window} = new Gtk::Window;
- $o->{window}->set_title($title);
- $o->{window}->signal_connect("delete_event" => sub { $o->{retval} = undef; Gtk->main_quit });
- $o->{window}
-}
+# these functions return a widget
+################################################################################
sub create_yesorno($) {
my ($w) = @_;
- myadd(create_hbox(),
- my_signal_connect($w->{ok} = new Gtk::Button("Ok"), "clicked" => sub { $w->{retval} = 1; Gtk->main_quit }),
- my_signal_connect(new Gtk::Button("Cancel"), "clicked" => sub { $w->{retval} = 0; Gtk->main_quit }),
+ gtkadd(create_hbox(),
+ gtksignal_connect($w->{ok} = new Gtk::Button("Ok"), "clicked" => sub { $w->{retval} = 1; Gtk->main_quit }),
+ gtksignal_connect(new Gtk::Button("Cancel"), "clicked" => sub { $w->{retval} = 0; Gtk->main_quit }),
);
}
sub create_box_with_title($@) {
my $o = shift;
- $o->{box} = mypack(new Gtk::VBox(0,0),
+ $o->{box} = gtkpack(new Gtk::VBox(0,0),
map({ new Gtk::Label(" $_ ") } @_),
new Gtk::HSeparator,
)
@@ -125,7 +142,7 @@ sub createScrolledWindow($) {
sub create_menu($@) {
my $title = shift;
my $w = new Gtk::MenuItem($title);
- $w->set_submenu(myshow(myappend(new Gtk::Menu, @_)));
+ $w->set_submenu(gtkshow(gtkappend(new Gtk::Menu, @_)));
$w
}
@@ -174,88 +191,88 @@ sub create_hbox {
$w;
}
-sub mymain($) {
- my $o = shift;
- $o->{window}->show;
- Gtk->main;
- $o->{window}->destroy;
- myflush();
- $o->{retval}
+sub _create_window($$) {
+ my ($o, $title) = @_;
+ $o->{window} = new Gtk::Window;
+ $o->{window}->set_title($title);
+ $o->{window}->signal_connect("delete_event" => sub { $o->{retval} = undef; Gtk->main_quit });
+ $o->{window}
}
-sub my_signal_connect($@) {
- my $w = shift;
- $w->signal_connect(@_);
- $w
-}
-sub mypack($@) {
- my $box = shift;
- foreach (@_) {
- my $l = $_;
- ref $l or $l = new Gtk::Label($l);
- $box->pack_start($l, 1, 1, 0);
- $l->show;
- }
- $box
-}
-sub mypack_($@) {
- my $box = shift;
- for (my $i = 0; $i < @_; $i += 2) {
- my $l = $_[$i + 1];
- ref $l or $l = new Gtk::Label($l);
- $box->pack_start($l, $_[$i], 1, 0);
- $_[$i + 1]->show;
- }
- $box
+
+################################################################################
+# ask_XXX
+
+# just give a title and some args, and it will return the value given by the user
+################################################################################
+
+sub ask_warn { my $w = my_gtk->new(shift @_); $w->_ask_warn(@_); main($w); }
+sub ask_yesorno { my $w = my_gtk->new(shift @_); $w->_ask_yesorno(@_, "Is it ok?"); main($w); }
+sub ask_from_entry { my $w = my_gtk->new(shift @_); $w->_ask_from_entry(@_); main($w); }
+sub ask_from_list { my $w = my_gtk->new(shift @_); $w->_ask_from_list(pop @_, @_); main($w); }
+
+sub _ask_from_entry($$@) {
+ my ($o, @msgs) = @_;
+ my $entry = new Gtk::Entry;
+ my $f = sub { $o->{retval} = $entry->get_text; Gtk->main_quit };
+
+ gtkadd($o->{window},
+ gtkpack($o->create_box_with_title(@msgs),
+ gtksignal_connect($entry, 'activate' => $f),
+ ($o->{hide_buttons} ? () : gtkpack(new Gtk::HBox(0,0),
+ gtksignal_connect(new Gtk::Button('Ok'), 'clicked' => $f),
+ gtksignal_connect(new Gtk::Button('Cancel'), 'clicked' => sub { $o->{retval} = undef; Gtk->main_quit }),
+ )),
+ ),
+ );
+ $entry->grab_focus();
}
+sub _ask_from_list($\@$@) {
+ my ($o, $l, @msgs) = @_;
+ my $f = sub { $o->{retval} = $_[1]; Gtk->main_quit };
+ my @l = map { gtksignal_connect(new Gtk::Button($_), "clicked" => $f, $_) } @$l;
-sub myappend($@) {
- my $w = shift;
- foreach (@_) {
- my $l = $_;
- ref $l or $l = new Gtk::Label($l);
- $w->append($l);
- $l->show;
- }
- $w
+# gtkadd($o->{window},
+# gtkpack_(myset_usize(new Gtk::VBox(0,0), 0, 200),
+# 0, $o->create_box_with_title(@msgs),
+# 1, createScrolledWindow(gtkpack(new Gtk::VBox(0,0), @l))));
+ gtkadd($o->{window},
+ gtkpack($o->create_box_with_title(@msgs), @l));
+ $l[0]->grab_focus();
}
-sub myadd($@) {
- my $w = shift;
- foreach (@_) {
- my $l = $_;
- ref $l or $l = new Gtk::Label($l);
- $w->add($l);
- $l->show;
- }
- $w
+
+sub _ask_warn($@) {
+ my ($o, @msgs) = @_;
+ gtkadd($o->{window},
+ gtkpack($o->create_box_with_title(@msgs),
+ gtksignal_connect(my $w = new Gtk::Button("Ok"), "clicked" => sub { Gtk->main_quit }),
+ ),
+ );
+ $w->grab_focus();
}
-sub myshow($) { $_[0]->show; $_[0] }
-sub mysync(;$) {
- my ($o) = @_;
- $o and $o->{window}->show;
+sub _ask_yesorno($@) {
+ my ($o, @msgs) = @_;
- my $h = Gtk->idle_add(sub { Gtk->main_quit; 1 });
- map { Gtk->main } (1..4);
- Gtk->idle_remove($h);
-}
-sub myflush(;$) {
- Gtk->main_iteration while Gtk::Gdk->events_pending;
+ gtkadd($o->{window},
+ gtkpack(create_box_with_title($o, @msgs),
+ create_yesorno($o),
+ )
+ );
+ $o->{ok}->grab_focus();
}
+################################################################################
+# rubbish
+################################################################################
-sub bigsize($) { $_[0]->{window}->set_usize(600,400); }
-sub myset_usize($$$) { $_[0]->set_usize($_[1],$_[2]); $_[0] }
-sub myset_justify($$) { $_[0]->set_justify($_[1]); $_[0] }
-sub mydestroy($) { $_[0] and $_[0]->destroy }
-
-sub label_align($$) {
- my $w = shift;
- local $_ = shift;
- $w->set_alignment(!/W/i, !/N/i);
- $w
-}
+#sub label_align($$) {
+# my $w = shift;
+# local $_ = shift;
+# $w->set_alignment(!/W/i, !/N/i);
+# $w
+#}