Using the destroy method does not work properly, since the delete-event callbacks are not called in the destroyed window, so the editor, for example, will not be able to ask the user if there is a file to save.
[3| zap@zap |~]python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gtk >>> w = gtk.Window() >>> w.show() >>> def cb(w,e): ... print "cb", w, e ... return True ... >>> w.connect ('delete-event', cb) >>> w.destroy()
In the above example, calling w.destroy () will not cause a callback, and when you click the close button, it is called (and the window will not close because the callback returns True).
Thus, you must both emit a signal and then destroy the widget if the signal handlers return False, for example:
if not w.emit("delete-event", gtk.gdk.Event(gtk.gdk.DELETE)): w.destroy()
zap
source share