After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 156026 - glade_xml_get_widget() returns the wrong widget
glade_xml_get_widget() returns the wrong widget
Status: RESOLVED NOTABUG
Product: libglade
Classification: Deprecated
Component: general
2.0.x
Other Linux
: Normal normal
: ---
Assigned To: James Henstridge
James Henstridge
Depends on:
Blocks:
 
 
Reported: 2004-10-21 05:45 UTC by Daniel Kasak
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daniel Kasak 2004-10-21 05:45:53 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.
Comment 1 James Henstridge 2004-10-21 14:49:24 UTC
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?