perlgtkgtkbuilder

How do i get the name (or id) on an widget which was created with Gtk2::Builder?


I am converting an app from using Gtk2::GladeXML to Gtk2::Builder. When getting all widgets with

@widgets = $glade_object->get_widget_prefix('')

I could get the name (set in Glade) of a widget with

$widgets[0]->get_widget_name

With Gtk2::Builder I fetch all widgets with

@widgets = $builder_object->get_objects

But $widgets[0]->get_widget_name is not known. $widgets[0]->get_name just gives me the widget class, e.g. GtkImage.

So my question is: How do i get the name (or id) of an widget which was created with Gtk2::Builder?

Thanks for any help.


Solution

  • thanks @johannes-sasongko! this really works. so what i do now is:

    # save original package, e.g.: 'Gtk2::Image'
    my $ref = ref $widgets[0]; 
    
    # get the id
    my $id = ( bless $widgets[0], "Gtk2::Buildable" )->get_name;  
    
    # restore package
    bless $widgets[0], $ref;                                         
    

    this is kind of a hack, but it works. better/cleaner solutions welcome!