in reply to Re: Perl/Tk Oddities
in thread Perl/Tk Oddities
In Gtk2, the preferred method is to wrap the dialog like this. It can be done because the destroy is handled by you outside of the Dialog object. Thanks to muppet and Mathew Braid, for showing me this.WAIT: $self->waitVariable(\$self->{RESULT}); #test result my $string = $self->{RESULT}; if( $string lt '#333333' ){ goto WAIT } else{ $self->grabRelease; $self->withdraw; &$old_focus; &$old_grab; return $self->{RESULT}; } } # end Show method
It may be possible to subclass the Tk::Dialogbox, and override the default button presses. It has the wait Show and exit methods available, so you should be able to redefine them in a subclass, usesub get_string { my ($title, $parent, $prompt, $initial_value, $default_cancel) = @_; my $dialog = Gtk2::Dialog->new ($title, $parent, [], 'gtk-cancel' => 'cancel', 'gtk-ok' => 'accept'); my $label = Gtk2::Label->new ($prompt || ''); $dialog->vbox->add ($label); $label->show (); my $entry = Gtk2::Entry->new (); $entry->set_text ($initial_value) if defined $initial_value; $dialog->vbox->add ($entry); $entry->show (); $dialog->set_default_response ($default_ok ? 'accept' : 'cancel'); my $ret; if ('accept' eq $dialog->run ()) { $ret = $entry->get_text (); } $dialog->destroy (); return $ret; }
You can google for Tk::Derived and find examples how to do it. Basically you just make a package called MyDialog, copy the Show() sub from the Dialogbox.pm into it, and modify it to your liking. You will see where I got the idea for my code in the Dialogbox.pm. :-)use base qw/Tk::Derived Tk::DialogBox/;
Probably the best solution, is to emulate Gtk2's wrapping of the dialog, by redefining exit() in your subclassed DialogBox, so it is controlled from outside the object.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl/Tk Oddities
by TomKane (Beadle) on Jul 23, 2008 at 09:33 UTC |