Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Passing multiple user data GLADE

by hakim-djz (Novice)
on Mar 14, 2014 at 17:43 UTC ( #1078369=perlquestion: print w/replies, xml ) Need Help??
hakim-djz has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

I am making a gui with glade at the moment. Now I've got the gui setup the way I want, but all that's left is to run my scripts from the events.

So I have four text entry boxes that are sitting in a container box. I want the values from them, however in glade you can only pass a single parameter as user data to the callback function.

Is there any way, or how do you pass the multiple text entry boxes to the callback function?

Here is my callback function:

sub OK_clicked_cb { my ( $widget, $entry) = @_; my $entry_text = $entry->get_text(); foreach (@entry){ my $entry_text = $entry[$i]->get_text(); print "$entry_text"; $i++; }



Okay I've advanced a bit and got this below

sub OK_clicked_cb { my ( $widget, $entry) = @_; ##Testing stuff my $vbox4 = $builder->get_object('vbox4'); #Have 5 elements, but n +eed 4 my @children = $vbox4->get_children('vbox4'); #Line 40 print "@children\n"; my $i = 0; for ($i < 3){ my $entry_text = $children[$i]->get_text(); print "$entry_text\n"; $i++; } }

This however gives me part of what I need, as it gives the value of the first entry. Here's the terminal output

*** Gtk3::Container::get_children: passed too many parameters (expecte +d 1, got 2); ignoring excess at line 40 Gtk3::Entry=HASH(0x8ad5e60) Gtk3::Entry=HASH(0x8bda0e8) Gtk3::Entry=HA +SH(0x8bda1ec) Gtk3::Entry=HASH(0x8bda084) Gtk3::Label=HASH(0x8b9641c)


I just used the id's of the children and used the following code.

sub OK_clicked_cb { ##Testing stuff my @entry_widgets =0; my @object_names = ("ip-value","ssid-value","psk-value","device-va +lue"); $entry_widgets[0] = $builder->get_object( $object_names[0])->get_t +ext(); $entry_widgets[1] = $builder->get_object( $object_names[1])->get_t +ext(); $entry_widgets[2] = $builder->get_object( $object_names[2])->get_t +ext(); $entry_widgets[3] = $builder->get_object( $object_names[3])->get_t +ext(); print $entry_widgets[0]."\n"; print $entry_widgets[1]."\n"; print $entry_widgets[2]."\n"; print $entry_widgets[3]."\n"; }

For some reason when I was trying to assign values through a loop it wouldn't work, so just did it manually as above. Thanks for all the replies

Replies are listed 'Best First'.
Re: Passing multiple user data GLADE
by Anonymous Monk on Mar 15, 2014 at 07:00 UTC

    Usually, you do something like pass $app, which keeps track of the children, $app->{left_text}, $app->{right_text} ...

    You can always  $widget->GetParent->FindWindowById('right_text')

Re: Passing multiple user data GLADE
by sam_bakki (Pilgrim) on Mar 16, 2014 at 14:10 UTC


      Well I have 4 text entry boxes:


      SSID:My Router

      PSK: Passphrase

      Device: Gadget1

      Where the values in the '[]' I need when the okay is clicked, and passed to my callback routine. And these are stored in a 4 element vbox.

      Now in Glade's properties window in the signals tab you can put the routine in the 'handler' box, and the data you want passed to the routine in the 'user data' box, but only allows you to add one object. So I'm stuck in passing it to the callback routine.

      I am using Glade 3.14.2 and Gtk3. As well Glade and Perl are both quite new to me. Thanks for your help


        Ok. Then expose the text entry boxes as a global variables like below,

        my $GuiBuilder = Gtk2::Builder->new (); $GuiBuilder->add_from_file(''); my $text_ip_entry = $GuiBuilder->get_object('text_ip_entry'); my $text_ssid_entry = $GuiBuilder->get_object('text_ssid_entry'); ..... sub on_some_click { my $widget=shift @_; my $userData = shift @_; my $text_ip = $text_ip_entry->get_text(); }

        Thanks & Regards,
        Bakkiaraj M
        My Perl Gtk2 technology demo project - , contributions are welcome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1078369]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2017-11-21 03:06 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (295 votes). Check out past polls.