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 591085 - GtkBuilder object ID bounded to GtkWidget "name" property
GtkBuilder object ID bounded to GtkWidget "name" property
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
2.16.x
Other All
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
: 607221 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-08-07 17:35 UTC by Alexey Kurochkin
Modified: 2010-02-18 07:05 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
Set the widget name if not set, other use object data (815 bytes, patch)
2009-10-16 16:47 UTC, Christian Dywan
needs-work Details | Review
Always use object data (612 bytes, patch)
2009-11-27 16:24 UTC, Christian Dywan
accepted-commit_now Details | Review
Always use object data, copy and update docs (1.56 KB, patch)
2009-11-30 13:54 UTC, Christian Dywan
none Details | Review
Use a quark to store the name (2.42 KB, patch)
2009-12-01 17:02 UTC, Christian Dywan
none Details | Review

Description Alexey Kurochkin 2009-08-07 17:35:53 UTC
Please describe the problem:
Widgets' property "name" is being set from the object's ID during widget creation by GtkBuilder.

Steps to reproduce:
1. Create GtkBuilder file defining some widget with id set to "myUniqueID" and the property "name" set to "myWidgetName".
2. Build the widget from the file with GtkBuilder.
3. Observe the "name" property value.

Actual results:
The property "name" is set to "myUniqueID".

Expected results:
The property "name" is set to "myWidgetName".

Does this happen every time?
Yes.

Other information:
According to documentation the widgets' "name" property should be used to "apply a style to widgets with a particular name in the gtkrc file". It implies that the name does not have to be unique. As it is now, the property in fact is bounded to GtkBuilder's unique object ID at the widget creation time with GtkBuilder. This defeats the original documented purpose of the widgets' "name" property. At the least if the "name" property is explicitly defined in the interface file, its value should be respected.

As a workaround for custom widgets you can implement your own GtkBuildableIface set_name and get_name functions. (I think they should have been properly called set_id and get_id to prevent any confusion,
but what's done is done - they're part of the API).
Comment 1 Christian Dywan 2009-10-15 09:24:51 UTC
I'm running into the same problem. GtkBuilder breaks my theming by overwriting widget names. As a quick hack, I modified GTK+ to use an object data "gtk-builder-name" in the default gtk_buildable_set/get_name, and it seems to work, with correct theming.
Comment 2 Claudio Saavedra 2009-10-15 11:12:09 UTC
Maemo bug as a consequence of this: https://bugs.maemo.org/show_bug.cgi?id=4718
Comment 3 Alexey Kurochkin 2009-10-15 15:08:29 UTC
Glade Bug 591076 is also related to this.
Comment 4 Christian Dywan 2009-10-16 16:47:54 UTC
Created attachment 145623 [details] [review]
Set the widget name if not set, other use object data
Comment 5 Christian Dywan 2009-10-16 16:49:50 UTC
From discussing this with Tristan, conditionally setting the widget name seems to be a compatible approach. Of course this still needs testing to see if it works.
Comment 6 Michael Natterer 2009-11-06 13:52:07 UTC
I remember a discussion on irc from the time before gtkbuilder was
integrated, and already then the point was bought up that using
the widget's *name* for the bulidable's *ID* is a really bad idea.

They have completely different semantics and mixing them like
that is calling for trouble. I'm all for fixing that by storing
the builder ID separately.

I would even go so far to unconditionally store the ID elsewhere
because the application is free to set the widget's name at any
point, and should not destroy the builder ID by doing so.
Comment 7 Claudio Saavedra 2009-11-06 14:13:49 UTC
(In reply to comment #6)

> I would even go so far to unconditionally store the ID elsewhere
> because the application is free to set the widget's name at any
> point, and should not destroy the builder ID by doing so.

I'm with Mitch here.
Comment 8 Thomas Perl 2009-11-06 15:49:48 UTC
(In reply to comment #6)
> I would even go so far to unconditionally store the ID elsewhere
> because the application is free to set the widget's name at any
> point, and should not destroy the builder ID by doing so.

Yes, storing the ID elsewhere would also fix the Maemo bug Claudio was referring to in comment 2. Especially when the widget name is used for themeing, and the ID from GtkBuilder is needed to identify the correct object one is looking for.

+1 from me for this solution.
Comment 9 Tristan Van Berkom 2009-11-06 15:59:25 UTC
Mitch, 
  what exactly do you mean storing it elsewhere ?

FWIW, totally agree that we just should not set
the widget name based on the builder id at all, can
we just stop doing that (and leave the id be the
id and leave the name be the name ?) ?
Comment 10 Michael Natterer 2009-11-17 09:59:19 UTC
By elsewhere i mean using g_object_set_data() as in the attached
patch, just unconditionally (no matter if the widget's name is
set or not).
Comment 11 Michael Natterer 2009-11-17 10:01:30 UTC
Comment on attachment 145623 [details] [review]
Set the widget name if not set, other use object data

This patch should use set/get_qdata(), and it should do that unconditionally.
Comment 12 Christian Dywan 2009-11-27 16:24:43 UTC
Created attachment 148604 [details] [review]
Always use object data
Comment 13 Matthias Clasen 2009-11-28 07:39:28 UTC
Comment on attachment 148604 [details] [review]
Always use object data

Looks good to me.
Comment 14 Christian Dywan 2009-11-30 13:54:06 UTC
Created attachment 148740 [details] [review]
Always use object data, copy and update docs

When I was about to commit, I noticed two things: we probably should copy the name, since we can't rely on the string being static, and I forgot to update the documentation earlier. It should say that object data is used, not the widget name. The updated patch does both.
Comment 15 Michael Natterer 2009-12-01 15:31:08 UTC
The patch looks good, but should still use set_qdata()/get_qdata() to
avoid the string -> quark conversion all the time.
Comment 16 Christian Dywan 2009-12-01 17:02:04 UTC
Created attachment 148835 [details] [review]
Use a quark to store the name
Comment 17 Michael Natterer 2009-12-02 19:19:44 UTC
That looks perfect now.
Comment 18 Christian Dywan 2009-12-03 12:15:11 UTC
Pushed to master.
Comment 19 Johan (not receiving bugmail) Dahlin 2009-12-08 17:05:11 UTC
This will cause at least a little bit confusing to pygtk programs which expects widget.get_name() to return the theme/buildable name. They would have to use gtk.Widget.get_name(widget) and gtk.Buildable(widget).get_name() to be sure that the right name is actually fetched, now when they are diverged. 
Over and out.
Comment 20 Christian Dywan 2009-12-08 17:36:04 UTC
For what I want, such pyGTK+ programs have been obviously wrong and just worked coincidentally. Same for applications in any language making such assumptions.
Comment 21 Wouter Bolsterlee (uws) 2010-01-02 14:44:02 UTC
(In reply to comment #19)
> This will cause at least a little bit confusing to pygtk programs which expects
> widget.get_name() to return the theme/buildable name. They would have to use
> gtk.Widget.get_name(widget) and gtk.Buildable(widget).get_name() to be sure
> that the right name is actually fetched, now when they are diverged. 

Fwiw, invoking unbound methods with an object instance is indeed ugly... a better approach would be an API addition like get_buildable_name() that calls into the right method, just like the panel applet bindings do for the set_flags() method. See e.g. http://mail.gnome.org/archives/gnome-devel-list/2009-December/msg00002.html and http://mail.gnome.org/archives/gnome-devel-list/2010-January/msg00001.html
Comment 22 Javier Jardón (IRC: jjardon) 2010-01-17 19:07:19 UTC
*** Bug 607221 has been marked as a duplicate of this bug. ***
Comment 23 Jean Bréfort 2010-02-18 07:05:09 UTC
GtkUIManager also use gtk_widget_set_name, is this a bug too?