Re: accessing selected item from OptionMenu



Chris Phillips said:

Hi, I've scoured the docs and must have missed somethign somewhere as I'm
tryign to find a way to get the currently selected value of an OptionMenu
but can't see any way. the option menu itself is derived from a button, so
button->get_label would have worked i'd assume, but i can't find any way  at
all to get the current item. is this possible or do i need to rely on
callbacks for each individual item?

you didn't mention whether you were using gtk-perl or gtk2-perl, so i've
answered for both.

gtk+-2.x adds the incredibly useful gtk_option_menu_get_history function. 
recall that gtk_option_menu_set_history has always been the way to set which
item in the menu is selected --- get_history tells you the index of the one
that is selected.

so, in gtk2-perl, that would be INTEGER = $optionmenu->get_history.


unfortunately, this doesn't exist in gtk+-1.x, so it doesn't exist in
gtk-perl.  that means you actually have to have your menuitems connected to
callbacks which keep the currently selected option up to date.  personally,
i've always found that annoying.


p.s. from the gtk tutorial "Now that we've shown you the hard way, here's
how you do it using the gtk_item_factory calls." I spent about 2 hours o  my
life trying to create an option menu with an item factory.... ack...  the
"hard" way is so so much easier to understand!

the GtkOptionMenu widget itself is a button, because you click the button to
pop up the menu.  the menu is stored with the widget, but you don't have any
actual connection to the menu once it has been attached.

so you'd use the item factory to create (suprise) $optionmenu->set_menu.

i've never done it this way, myself (for various reasons), so take that with a
grain of salt.

-- 
muppet <scott at asofyet dot org>





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