tags:

views:

53

answers:

2

How do I get a widget's "name"?

When I define a GUI using Glade, I can "name" the widgets of the window but how do I recover that property when I have a widget object instance?

I've tried get_property(), get_name() and $widget.name to no avail.

Update: I am using GtkBuilder file format (i.e. XML format).

Resolution: a fix I have used: use the set_property("name", name) method on the widget just after getting it from GtkBuilder.

A: 

Given the widget w, what does w.get_name() return? If None, that means the widget has no name property. Maybe you want gtk.glade.get_widget_name(w) instead? (I'm not sure if the name property of the widget and the name for it in the Glade XML from which it was created are the same thing...).

Alex Martelli
They return "None", as well as `gtk.glade.get_widget_name(w)`.
jldupont
@jdupont, and yet you're certain `w` was built from a named entry in a Glade XML file? Then I'm out of ideas...:-(
Alex Martelli
+2  A: 

There has been a long standing bug where GTKBuilder sets the widget name to be the builder ID, or (somehow) doesn't set it at all. See this Ubuntu bug and this GNOME bug.

(I have no idea why the bug says that it sets the ID instead of the name — personally, I've only ever seen the name not set at all.)

I use the class-method form: gtk.Buildable.get_name(widget), which seems to work for me.

detly
that's exactly what has been happening on my end! Thanks for the heads-up!
jldupont