Hi, 2008/7/17 zentara <[EMAIL PROTECTED]>: > On Wed, 16 Jul 2008 14:43:53 -0400 (EDT) > Well the idea is not just for color. I'm looking for a general purpose > popup that returns whatever I want, instead of integers(like a dialog). > I might want a textbox, or entries, etc.
Rather than making a whole new class of dialogs, I usually use a wrapper package that does the work for me. For instance, if I want a dialog that asks for a single line of input, that package might have a sub like: sub ask { my $self = shift; my ($question) = @_; my $dlg = Gtk2::Dialog->new(....); # Set up the dialog how you want. In this case we'd put a label and an entry in. # The entry is important, so I'll keep that bit of code here my $ent = Gtk2::Entry->new; # Pack everything, and then ready to go my $res = $dlg->run; $dlg->hide; # If your 'get the result' section is a bit long, you might want to do a # Gtk2->main_iteration while (Gtk2->events_pending); # to make the dialog hide _now_ if ($res eq 'ok') { $res = $ent->get_text; } else { $res = undef; } $dlg->destroy; return $res; } This package is normally called something like TOP::LEVEL::Dialog (where TOP::LEVEL is the namespace my app is using), and then you can just add subs like the above to do the work for you, instantiate that package (with important details like the window to be modal on etc), and then just do stuff like: my $txt = $dialogs->ask("Enter planet to destroy: "); if (defined($txt)) {...} More complex dialogs might have their own callback package as well - this method allows you to have dialogs as complex as you want that return exactly the data you want without having to fill your main code with all the 'build the dialog' details. Oh, and I used to use a jerry-rigged version of Tk's waitVariable for custom dialogs as well, but the whole $dlg->run thing is much better. MB _______________________________________________ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list