Re: perl-gtk newbie question



Luis Villa <liv duke edu> writes:
So, I've searched these lists for a while and been unable to find a good
answer to this question: given an OptionMenu, how can I figure out what
the selected option is? I'm a gtk newbie, and while I'm reasonably good
with perl, none of it has been in an OO environment, so there are some
issues with classes and the like that I think I'm missing. Here is what
I'm trying to do (code more or less verbatim):

$motor_dir_option_menu = $g->get_widget('motor_dir');
$dir_menu = $motor_dir_option_menu->get_menu();
$dir = ($dir_menu->get_active->children)[0]->get;
print STDERR 'DIR:'.$dir;

This dies, telling me (when get_active is called on $dir_menu) that
$dir_menu is not actually a menu, but a widget, and so it can't locate the
method get_active via package "Gtk::Widget". Upon looking through the gtk
perl docs, I realize that this is the "correct" behavior: get_menu should
return a widget. So, I guess my question breaks down into two parts:

1) Can I turn the widget returned by get_menu into an actual menu object 
so that I can call the get_active method?

Don't know.
 
and 

2) this seems ugly and un-intuitive. Is there a better way to figure
out which menu item has been selected? I gather from the lists (this one,
gtk, and gtk-devel) that there is not (see:
http://mail.gnome.org/archives/gtk-perl-list/2000-September/msg00035.html
 among others) but one can dream ;)

Be tricky.

Without GladeXML:

my $value;
my $label = "foo";
$menu_item = new_with_label Gtk::RadioMenuItem( $label, $previous_menu_item);
$menu_item->signal_connect('activate', sub{$value=$_[1];} , $label);

With GladeXML:

be trickier.

BrYan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]