Confused about a widget's name

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Confused about a widget's name

Skip Montanaro-3
I'm returning to PyGTK programming after a long hiatus.  When last I
visited these waters, I used Gtk 2.12.  Now I use 2.22 and this
Builder thing, which, I must admit, has me a bit confused.

In a signal callback for a radio button, if I ask for its name
(rb.get_name()) I always get "GtkRadioButton".  If I call get_property
with "name" as the argument, I get the empty string.  Looking at the
docs for gtk.Builder, I saw this:

"Objects must be given a name with the "id" attribute, which allows
the application to retrieve them from the builder with get_object().
An id is also necessary to use the object as property value in other
parts of the UI definition.

Note: Prior to GTK+ 2.20, gtk.Builder was setting the "name" property
of constructed widgets to the "id" attribute. In GTK+ 2.20 or newer,
you have to use gtk.Buildable.get_name() instead of
gtk.Widget.get_name() to obtain the "id", or set the "name" property
in your UI definition."

I can't tell what object gtk.Buildable is supposed to refer to.  I
have a reference to a widget (in this case, a radio button, but I
think the problem is more general than that).  How do I retrieve the
name I gave it in Glade?

Thx,

Skip Montanaro
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/
Reply | Threaded
Open this post in threaded view
|

Re: Confused about a widget's name

Skip Montanaro-3
> In a signal callback for a radio button, if I ask for its name
> (rb.get_name()) I always get "GtkRadioButton".  If I call get_property
> with "name" as the argument, I get the empty string.  Looking at the
> docs for gtk.Builder, I saw this:
>
> "Objects must be given a name with the "id" attribute, which allows
> the application to retrieve them from the builder with get_object().
> An id is also necessary to use the object as property value in other
> parts of the UI definition.
>
> Note: Prior to GTK+ 2.20, gtk.Builder was setting the "name" property
> of constructed widgets to the "id" attribute. In GTK+ 2.20 or newer,
> you have to use gtk.Buildable.get_name() instead of
> gtk.Widget.get_name() to obtain the "id", or set the "name" property
> in your UI definition."

I am going to answer my own question and report a documentation bug.
The gtk.Buildable.get_name() function takes a widget as an argument,
but the documentation omits that fact. See:

http://www.pygtk.org/docs/pygtk/class-gtkbuildable.html#method-gtkbuildable--set-name

More generally, shouldn't the widget's name property be populated by
the builder?  This change seems like it would cause a lot of needless
breakage to existing code ported from libglade to the builder stuff.

Skip
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/