Domanda

Sto convertendo un'app dall'uso GTK2 :: GLADEXML a GTK2 :: Builder. Quando si ottiene tutti i widget con

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

Potrei ottenere il nome (impostato in radura) di un widget con

$widgets[0]->get_widget_name

Con gtk2 :: builder prendo tutti i widget con

@widgets = $builder_object->get_objects

Ma $widgets[0]->get_widget_name non è noto. $widgets[0]->get_name Mi dà solo la classe widget, ad esempio gtkimage.

Quindi la mia domanda è: come posso ottenere il nome (o l'ID) di un widget che è stato creato con GTK2 :: Builder?

Grazie per qualsiasi aiuto.

È stato utile?

Soluzione

grazie @johannes-sasongko! Questo funziona davvero. Quindi quello che faccio ora è:

# 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;                                         

Questo è una specie di hack, ma funziona. Soluzioni migliori/più pulite benvenute!

Altri suggerimenti

$ widget-> gtk2 :: buildable :: get_name () dovrebbe fare il trucco se hai bisogno del nome di widget

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top