Re: how to catch window manager close



On Fri, 2010-01-08 at 10:43 -0500, Chris Bare wrote:
Can anyone point me to a tutorial or something on how to catch the window
manager close in GTK?

I'm creating an app with glade, and I've got a GtkAboutDialog. my About menu
item's activate singal calls gtk_widget_show which works as expected.

I've attached gtk_widget hide to the about dialog's close, response and
destroy signal.

The close button works fine, but if you close it with the window manager,
there's apparently some default callback that actually destroys the window, so
the next time I select About from the menu I get the following error:

(spiral:9162): GLib-GObject-WARNING **: invalid unclassed pointer in cast to
`GtkAboutDialog'

I want to be able to catch the close even and just hide the window.

In general, you should connect to the delete-event signal to catch the
user closing a window via the window manager. However, for dialogs, this
should be unnecessary. The dialog should be handling things itself, if
you "run" it.

An example from my own project, in Python, but should be easy to
understand for other bindings:

    def on_about_menuitem_activate(self, *args):
        w = self.widgets['aboutdialog']
        w.set_version(dimbola.version)
        w.show()
        w.run()
        w.hide()

While the run() method is being called, the program processes events in
the event loop normally. When the dialog is closed, the call to run()
finishes.

gtk_dialog_run is probably the C name of the function.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]