Gtk 2.20, Gtk::Builder and 'name'

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

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…

2010/4/7 Pascal T. [email protected]:

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

Hei,

thanks for the tip, I spent a good couple of hours trying to
understand
what was going on before reading this thread :slight_smile:
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 :slight_smile:


Andrea D.
http://github.com/bolthar/freightrain
http://usingimho.wordpress.com

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk 2.20, Gtk::Builder and ‘name’” on Mon,
03 May 2010 19:17:41 +0200,
Andrea D. [email protected] wrote:

Hei,

thanks for the tip, I spent a good couple of hours trying to understand
what was going on before reading this thread :slight_smile:
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

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

Hi,

Sorry for my late response.

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk 2.20, Gtk::Builder and ‘name’” on Wed,
7 Apr 2010 12:10:06 +0200,
Simon A. [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs