Re: dialog close signal and hiding dialog...
- From: Ross McFarland <rwmcfa1 neces com>
- To: Gtk-Perl-List <gtk-perl-list gnome org>
- Subject: Re: dialog close signal and hiding dialog...
- Date: 12 Aug 2003 21:36:15 -0400
On Tue, 2003-08-12 at 21:00, muppet wrote:
Am I capturing the signals correctly?
nope. the delete-event gets routed through response as a certain
response code, but the event continues to propagate, resulting in the
destruction of the window. you simply need to bind to delete-event a
signal handler that returns TRUE, to stop the propagation.
this is if you call show which in most cases with dialog's you
shouldn't.
-=-=-=-=-=-=-
#!/usr/bin/perl -w
use Gtk2 -init;
my $win = Gtk2::Window->new;
$win->signal_connect (delete_event => sub { Gtk2->main_quit; 1; });
my $button = Gtk2::Button->new ('click me');
$button->signal_connect (clicked => \&do_dialog, $win);
$win->add ($button);
$win->show_all;
Gtk2->main;
# we'll reuse one dialog, just showing and hiding it
$dialog = undef;
sub do_dialog {
my ($widget, $parent) = @_;
if (not defined $dialog) {
$dialog = Gtk2::Dialog->new ('Test', $parent, 'modal',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok');
my $label = Gtk2::Label->new ('here i am, rock you like a hurricane');
$label->show;
$dialog->vbox->add ($label);
# inhibit destruction by pretending to handle delete-event
$dialog->signal_connect (delete_event => sub {1});
# handle the response, and hide the window, never destroy it
$dialog->signal_connect (response => sub {
my ($self, $response) = @_;
print "response is $response\n";
$self->hide;
1;
});
}
$dialog->show;
}
unless you're doing something really fancy and specialized you shouldn't
do this, as that's pretty much part of what run will do for you.
cutup version of gtk_dialog_run:
gtk_dialog_run (GtkDialog *dialog)
{
// init code removed
response_handler =
g_signal_connect (dialog,
"response",
G_CALLBACK (run_response_handler),
&ri);
unmap_handler =
g_signal_connect (dialog,
"unmap",
G_CALLBACK (run_unmap_handler),
&ri);
delete_handler =
g_signal_connect (dialog,
"delete_event",
G_CALLBACK (run_delete_handler),
&ri);
destroy_handler =
g_signal_connect (dialog,
"destroy",
G_CALLBACK (run_destroy_handler),
&ri);
// main loop stuff removed
// code that if dialog wasn't destroyed intentionally by app
// remove all of the signals
// response_id was set by the above callbacks according to
// their defined behavior
return ri.response_id;
}
C code on a perl list, oh well.
-rm
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]