# Gtk 2.20, Gtk::Builder and 'name'

**URL:** <https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447>\
**Category:** Ruby-Gnome 2\
**Created:** [April 7, 2010, 10:50am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447 "2010-04-07T10:50:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [April 7, 2010, 10:50am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/1 "2010-04-07T10:50:59Z")

</div>

Hi

I struggled with this bug for a few hours, so I’m sharing it here.

With gtk 2.20, Gtk::Builder does NOT set the name property anymore.  
I don’t really understand yet the diference between  
gtk\_widget\_get\_name and gtk\_buildable\_get\_name, but for RG2, it means  
you cannot anymore call #name to get the object id you set in glade,  
if that object inherits from Gtk::Widget.

As a workaround, I wrote this in my code, since I have no use for  
Gtk::Widget#name.

class Gtk::Widget  
remove\_method :name  
end

I tried to find where in the code this method gets added to  
Gtk::Widget, but I never found.

I also added to gtk/src/gtkbuildable.c :

rb\_define\_method(cGtkBuildable, “name”, buildable\_get\_name, 0);  
+rb\_define\_alias(cGtkBuildable, “builder\_id”, “name”);

And calling builder\_id works too.

Hope it helps people with Gtk 2.20.

Simon

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [April 7, 2010, 11:50am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/2 "2010-04-07T11:50:06Z")

</div>

Le mercredi 07 avril 2010 à 10:50 +0200, Simon A. a écrit :

> Hi
> 
> I struggled with this bug for a few hours, so I’m sharing it here.
> 
> With gtk 2.20, Gtk::Builder does NOT set the name property anymore.  
> I don’t really understand yet the diference between  
> gtk\_widget\_get\_name and gtk\_buildable\_get\_name, but for RG2, it means  
> you cannot anymore call #name to get the object id you set in glade,  
> if that object inherits from Gtk::Widget.

id should get exposed

Name of GtkWidget is mostly used for theming and does not have to be  
unique

Name of GtkBuildable is its id, and should never have been setting the  
name property imho

> rb\_define\_method(cGtkBuildable, “name”, buildable\_get\_name, 0);  
> +rb\_define\_alias(cGtkBuildable, “builder\_id”, “name”);

I don’t really like to keep “name” poiting to buildable name, hiding the  
widget name but I’m not sure what would be right

C does not have this issue as user as to explicitly call  
gtk\_buildable\_get\_name or gtk\_widget\_get\_name…

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [April 7, 2010, 12:10pm UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/3 "2010-04-07T12:10:36Z")

</div>

2010/4/7 Pascal T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> id should get exposed

I agree.

> Name of GtkWidget is mostly used for theming and does not have to be  
> unique

I don’t use it at all, but that’s what I’ve seen while trying to solve  
my problem.

> Name of GtkBuildable is its id, and should never have been setting the  
> name property imho

I agree.

> I don’t really like to keep “name” poiting to buildable name, hiding the  
> widget name but I’m not sure what would be right

It was just an experiment. I also think we should just get rid of  
‘name’ in the builder.  
‘id’ does not seems very smart. I would prefer ‘ui\_id’ or ‘builder\_id’.  
I don’t like ‘glade\_id’, since you can generate the xml with any tool.

Maybe create a struct/object for builder specific info. So you would  
call widget.builder.id. Though, I’m not sure there is much info only  
available for ‘built’ objects.

> C does not have this issue as user as to explicitly call  
> gtk\_buildable\_get\_name or gtk\_widget\_get\_name…

Indeed, even if I think it’s not very smart to get the ‘id’ property  
with ‘get\_name’.

What do you all think ?

Simon

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [May 3, 2010, 7:18pm UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/4 "2010-05-03T19:18:21Z")

</div>

Hei,

thanks for the tip, I spent a good couple of hours trying to  
understand  
what was going on before reading this thread 🙂  
Will the method “builder\_name” be present in the next release? I checked  
out trunk and the fix isn’t there. I modified the source myself and  
everything works fine but I’d be really nice to have users in the  
position that they can just download and build the latest release  
without tweaking the source.

Thanks again, this was pure gold 🙂

–  
Andrea D.

> **[GitHub - bolthar/freightrain: Ruby desktop development made easy](https://github.com/bolthar/freightrain)**
>
> Ruby desktop development made easy. Contribute to bolthar/freightrain development by creating an account on GitHub.

> **[using (IMHO)](https://usingimho.wordpress.com)**
>
> Andrea Dallera 's blog

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [May 4, 2010, 12:56am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/5 "2010-05-04T00:56:07Z")

</div>

Hi,

In [1272907061.1530.4.camel@VEGETA](mailto:1272907061.1530.4.camel@VEGETA)  
“Re: [ruby-gnome2-devel-en] Gtk 2.20, Gtk::Builder and ‘name’” on Mon,  
03 May 2010 19:17:41 +0200,  
Andrea D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hei,
> 
> thanks for the tip, I spent a good couple of hours trying to understand  
> what was going on before reading this thread 🙂  
> Will the method “builder\_name” be present in the next release? I checked  
> out trunk and the fix isn’t there. I modified the source myself and  
> everything works fine but I’d be really nice to have users in the  
> position that they can just download and build the latest release  
> without tweaking the source.

It was just my opinion.  
I’ve committed it now. You will be able to use  
“builder\_name” in the next release.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [March 4, 2012, 12:35am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/6 "2012-03-04T00:35:11Z")

</div>

Thank for all your great work, kou, Simon and Andrea!

You guys have helped me again.

In this situation, it seems like setting the “name” property to the name  
given in glade good because, the current “name” property in my program  
always returns nil anyway. Also, because glade identifies this field in  
their GUI as “Name.”

Thanks again.  
Eric

---

<div class="post-metadata">

**Author:** ![mazwak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mazwak](https://www.ruby-forum.com/u/mazwak)\
**Post date:** [April 29, 2010, 5:10am UTC](https://www.ruby-forum.com/t/gtk-2-20-gtk-builder-and-name/186447/7 "2010-04-29T05:10:13Z")

</div>

Hi,

Sorry for my late response.

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Gtk 2.20, Gtk::Builder and ‘name’” on Wed,  
7 Apr 2010 12:10:06 +0200,  
Simon A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ‘id’ does not seems very smart. I would prefer ‘ui\_id’ or ‘builder\_id’.  
> with ‘get\_name’.
> 
> What do you all think ?

I think this is a good solution because GTK+ 20.0 uses  
‘builder name’ as key for it internally:

# Index: gtk/src/rbgtkbuildable.c

— gtk/src/rbgtkbuildable.c (revision 3766)  
+++ gtk/src/rbgtkbuildable.c (working copy)  
@@ -100,8 +100,8 @@

```
 cGtkBuildable = G_DEF_CLASS(GTK_TYPE_BUILDABLE, "Buildable", mGtk);

```

- rb\_define\_method(cGtkBuildable, “name”, buildable\_get\_name, 0);
- rb\_define\_method(cGtkBuildable, “set\_name”, buildable\_set\_name, 1);

- rb\_define\_method(cGtkBuildable, “builder\_name”, buildable\_get\_name,  
0);
- rb\_define\_method(cGtkBuildable, “set\_builder\_name”,  
buildable\_set\_name, 1);  
rb\_define\_method(cGtkBuildable, “add\_child”, buildable\_add\_child,  
-1);  
rb\_define\_method(cGtkBuildable, “set\_buildable\_property”,  
buildable\_set\_buildable\_property, 3);

## Thanks,

kou
