GNOME Bugzilla – Bug 156026
glade_xml_get_widget() returns the wrong widget
Last modified: 2004-12-22 21:47:04 UTC
I have a relatively complex ( ie many windows, and many, many widgets ) application with a GUI created in Glade. glade_xml_get_widget() is returning the wrong widget if there are multiple widgets with the same name. My app is written in Gtk-Perk. Example: --- In Glade, I have 2 windows, called "MainMenu" and "Batches". In Perl, I create them: $mainmenu = Gtk2::GladeXML->new($gladefile, "MainMenu"); $mainmenu->signal_autoconnect_from_package; $batches = Gtk2::GladeXML->new($gladefile, "Batches"); $batches->signal_autoconnect_from_package; Now, my MainMenu form has a *button* on it, called "Batches" ... because it's the batches button, which opens the batches form. If I try to get hold of the "Batches" window, via: $batches->get_widget("Batches") I instead get the Batches *button*, on the MainMenu form. --- The explanation I've been given on the gtk-perl list is: "libglade uses a GHashTable to hold the mapping of widget names to widgets; duplicate names will hash to the same table entry, and therefore the last-created widget will be the one found in the hash." I think it's unreasonable to force all names of widgets to be unique throughout the entire glade project. I can understand having unique names in a single window, but widget names should be able to be repeated across multiple windows.
If you have multiple widgets with the same name, then your glade file is invalid. If you pass libglade invalid data, you may get unexpected results. If you want to use the same names for different windows, I suggest you use multiple glade files. Your particular problem is in the following call: $batches = Gtk2::GladeXML->new($gladefile, "Batches"); From your description, it sounds like you have two widgets called "Batches". Libglade has simply built a different subtree of the glade file than you expected (ie. an instance of the button in the MainMenu form rather than the Batches toplevel window). Without any extra information, how should libglade know what you wanted?