Glade Gotchas May 18, 2008

Glade is awesome, no denying that. It’s clean, unlike any other ‘GUI building tool’ I’ve seen. It generates an XML description of the GUI, which is parsed at runtime. It’s simple, and hence easy to use (by virtue of the previous two attributes). At the same time, it does have it’s idiosyncrasies (and limitations) as well, only I’ve never really used the signal callback connector it provides to discover it for myself. It took a bit of googling before I could figure it out.

  1. The argument (userdata) provided to the callback handler sends an object containing a GtkWidget registered with the same name in the Glade file (so it would be the returned value of glade_xml_get_widget("name");
  2. Most irritatingly, the arguments sent to the callback are swapped, so instead of callback_fn (GtkWidget *widget, GtkWidget *glade_widget); it is callback_fn (GtkWidget *glade_widget, GtkWidget *widget); even if glade_value is NULL.

It’s easy to understand why you can’t specify the userdata; how do you specify the scope of the argument? Perhaps just the code block in which you make the glade_xml_auto_connect call, but that wouldn’t work out either because glade files are processed at runtime; you won’t have the variable names to work with. I’m thinking maybe this could be implemented by using a GObject’s property (say a special “name” property that is unique). Does that even sound possible / a good way to do it?