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 | |
Re: Passing multiple user data GLADE
by sam_bakki (Pilgrim) on Mar 16, 2014 at 14:10 UTC | |
by hakim-djz (Novice) on Mar 16, 2014 at 14:35 UTC | |
by sam_bakki (Pilgrim) on Mar 17, 2014 at 08:29 UTC | |
by hakim-djz (Novice) on Mar 17, 2014 at 17:31 UTC |