Wednesday, April 28, 2010

python gtk and Glade

I spent a few hours yesterday figuring out this problem.

Given a simple glade3 (gtk.Builder) window, setting the on_window1_destroy signal to gtk.quit didn't seem to work. The window itself would disappear, but the process would continue to run in the background.

After fiddling with it, I finally identified the problem.  It turns out that you have to set on_window1_destroy in the .glade file as well.  The tutorials were unclear, but I guess that kind of makes sense.  I had assumed that the "on_OBJECT_command" format was being parsed so as to hook directly to the OBJECT.  That is, it knew which object to attach the signal to by parsing the signal name. But, instead, you need to set the signal in the glade file so that it is attached to the GtkWindow.

Seems like it will be a pain to set the signals for every object in the glade file.  Hopefully there is an easier way and I'm just missing it.