Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

GTK2+glade and knowing who called

by ultibuzz (Monk)
on Jan 21, 2013 at 19:25 UTC ( #1014509=perlquestion: print w/ replies, xml ) Need Help??
ultibuzz has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

right now i'm wondering if there is a way to find out which button called the sub.

I got 3 Button's labeled 1..3 and all call the same sub "clicked".
Is there a way to know which button called the sub ?


I'm currently using 3 sub's which call the 1 sub with parameters to get which button was pressed.
This is all prototyping, for the main purpose of an auto generated glade GUI,where the majority of button's do nearly the same thing,
like Display info x, where x is the label of the button.


kind regard
Alex

Comment on GTK2+glade and knowing who called
Re: GTK2+glade and knowing who called
by Anonymous Monk on Jan 22, 2013 at 03:41 UTC

      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

Re: GTK2+glade and knowing who called
by Anonymous Monk on Jan 22, 2013 at 13:30 UTC

    I haven't used Glade but can't you set the "user data" argument in Glade? That's the usual way of passing the useful data to callbacks. There also should be the $self argument which (IIRC) contains the widget that initiated the signal. Perhaps not very useful by itself.

    # passing an anonymous array as user data $button->signal_connect(clicked => \&btn_search, [$searchbox, $res_vbo +x]); sub btn_search { my ($self, $args) = @_; # unpacking user data my ($entry, $box) = @$args; # ...

      that would be the object next to the handler in the xml,
      the docs on glade state that you can not get that user data unless you create custom signals for everything.
      For my purpose the Object who called is enough to work with,
      at least for now ;), maybe i'll do the whole thing in c++ or go back to TK

      kind regards
      Alex

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1014509]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-08-23 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (174 votes), past polls