Re: cancel gtk_main_quit and return to the main window
- From: muppet <scott asofyet org>
- To: deloptes yahoo com
- Cc: gtk-perl-list gnome org
- Subject: Re: cancel gtk_main_quit and return to the main window
- Date: Thu, 22 Jan 2009 23:30:11 -0500
On Jan 22, 2009, at 5:44 PM, Emanoil Kotsev wrote:
the problem is, as far as I understand it, that I create a gtk
obejct from
glade. when I hit the [x] button on the window
(window1::gtk_main_quit )
the gtk widget ($Gtk2->{Gtk2Main}) related to this window seems to
die. I
want to cancel it so I call a function quit which returns true if
data is
saved and false if data is modified but not stored.
Doesn't really matter, but when it receives false from quit() and I
call
show an empty gray window appears.
You have the return value's meaning backwards.
http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-delete-event
"Returns: TRUE to stop other handlers from being invoked for the
event. FALSE to propagate the event further."
But your code was
sub window1::gtk_main_quit {
# TODO: recreate the SaveAllWindow on destroy
if ( ! quit() ) {
$Gtk2->{MainWindow}->show();
$Gtk2->{SaveAllWindow}->hide();
return FALSE;
} else {
Gtk2->main_quit();
return TRUE;
}
}
Which says, if we don't want to quit, show the main window, hide the
saveall window, and propagate to the default handler which will
destroy the window. Else, kill the main loop and inhibit destruction
of the window.
We recently added some constants intended to disambiguate this kind of
stuff. So, you should rework that as
sub window1::gtk_main_quit {
# TODO: recreate the SaveAllWindow on destroy
if ( ! quit() ) {
$Gtk2->{MainWindow}->show();
$Gtk2->{SaveAllWindow}->hide();
return Gtk2::EVENT_STOP; # true
} else {
Gtk2->main_quit();
return Gtk2::EVENT_PROPAGATE; # false
}
}
and it ought to work as you wanted.
Basically I was thinking to recreate the window (using destroy and
new), but
destroying the first window/gtk object it destroys also the notebook
as
being part of the widget (window1), so I was thinking to put the
notebook
into a separate widget and pack it into the window
That doesn't really work with stuff created by glade. Once you
destroy it, you must reload it from the xml file. So, people
typically just hide their glade-created windows instead of destroying
them.
--
I hate to break it to you, but magic data pixies don't exist.
-- Simon Cozens
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]