http://www.perlmonks.org?node_id=1014617


in reply to Re: GTK2+glade and knowing who called
in thread GTK2+glade and knowing who called

no tutorial, im just experimenting with glade GUI

if i do the whole gtk2 gui in perl code, there is no problem getting what called,but while using a glade GUI,
it looks like it just calls the sub without any additional info

some example of the glade file

<child> <widget class="GtkButton" id="btnNum1"> <property name="label" translatable="yes">1</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <signal name="clicked" handler="btnNUM_clicked"/> </widget> </child> <child> <widget class="GtkButton" id="btnNum2"> <property name="label" translatable="yes">2</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <signal name="clicked" handler="btnNUM_clicked"/> </widget> </child>

the sub is "btnNUM_clicked", which gets called without problem,but does not tell the code who called ;)

If changed to "btnNUM_clicked1..3", i know who called, but i want to avoid generating anonymous subs or endless prototyp's,
if there is a way within glade to pass the who called information.

kind regard
Alex

Replies are listed 'Best First'.
Re^3: GTK2+glade and knowing who called
by Anonymous Monk on Jan 22, 2013 at 10:18 UTC

      Not a very helpful link. Many broken links, and of the ones that worked, I didn't see anything showing a solution to the problem mentioned. (I may have missed a page, I can't be certain with all the broken links.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      the glade itself is describing the form in an XML file,it does not generate perl code.

      example minimal code

      use warnings; use strict; use Gtk2 -init; use Gtk2::GladeXML; my $gladexml = Gtk2::GladeXML->new('register_test.glade'); $gladexml->signal_autoconnect_from_package('main'); Gtk2->main; sub btnNUM_clicked { print "yay clicked"; } sub gtk_main_quit { Gtk2->main_quit; }

      an alternative would be
      use warnings; use strict; use Gtk2 -init; use Gtk2::GladeXML; my $gladexml = Gtk2::GladeXML->new('register_test.glade'); $gladexml->signal_autoconnect_from_package('main'); Gtk2->main; sub btnNUM_clicked { my $self = $_; print "yay,you clicked $self"; } sub gtk_main_quit { Gtk2->main_quit; } sub btnNUM_clicked1 { btnNUM_clicked(1); } sub btnNUM_clicked2 { btnNUM_clicked(2); }

      this would work and can also be automaticaly generated,and inserted in the XML definition,
      but that i would want to avoid, if there is a way from glade telling me who called the event.

      kind regards
      Alex

        Read perlvar#@_ and use @_, seems to work fine for me,  print "!!!@_\n"; yields

        !!!! Gtk2::Button=HASH(0xc6fbf4) Gtk2::Dialog=HASH(0xc70094)

        While you're at it read perlintro and the links from my first reply