Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Passing multiple user data GLADE

by hakim-djz (Novice)
on Mar 14, 2014 at 17:43 UTC ( [id://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++; }

Thanks!

UPDATE!!

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 my-gui.pl line 40 Gtk3::Entry=HASH(0x8ad5e60) Gtk3::Entry=HASH(0x8bda0e8) Gtk3::Entry=HA +SH(0x8bda1ec) Gtk3::Entry=HASH(0x8bda084) Gtk3::Label=HASH(0x8b9641c) 192.168.0.2

SOLVED!!!

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

      Hi,

      Well I have 4 text entry boxes:

      ip: 192.168.0.2

      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

        Hi

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

        my $GuiBuilder = Gtk2::Builder->new (); $GuiBuilder->add_from_file('test.glade'); 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 - http://code.google.com/p/saaral-soft-search-spider/ , contributions are welcome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1078369]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found