Re: [gtk-list] Re: reading an optionmenu setting



Jeremy Weatherford wrote:
> 
> This may wind up being pretty messy/overkill for your app.  For mine, it
> happened to work out well this way.
> 
> What I do is to give each GtkMenuItem I create an 'activate' event which
> calls a function unique to the option menu with the ID number of the item
> as the data.  In my case, that function does something as soon as the item
> is picked.  In your case, you might want it to just store the item id or
> its contents in a global variable.
> 
> This is obviously not a 'reasonable' solution, but it does work.
> 
> Jeremy Weatherford
> xidus@xidus.net
> http://xidus.net/
> 
> On Mon, 7 Feb 2000, jca wrote:
> 
> >
> >   I've looked through the reference docs for this, but no luck so far...
> >
> >
> >   How do you find out what value the user set your optionmenu to?
> > There's no gtk_option_menu_get_history()...
> >
Hi, in Glade's FAQ I found:

3.5 How do I get the value of a GtkOptionMenu?

Call gtk_menu_get_active() with the GtkOptionMenu's menu to get the currently
selected menu item. You can use g_list_index() to find its index in the menu:

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *option_menu, *menu, *active_item;
  gint active_index;

  option_menu = lookup_widget (GTK_WIDGET (button), "optionmenu1");
  menu = GTK_OPTION_MENU (option_menu)->menu;
  active_item = gtk_menu_get_active (GTK_MENU (menu));
  active_index = g_list_index (GTK_MENU_SHELL (menu)->children, active_item);

  g_print ("Active index: %i\n", active_index);
}



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