[Glade-users] gtk option menu

This is from the Glade FAQ.  I haven't messed with menu stuff yet, so I hope 
this helps.


4.8 How do I get a GtkOptionMenu to call a function when it changes?

Glade doesn't support this at present, but you can set it up manually.

When you create the window, get the option menu and connect to the 
signal emitted by its menu:

  window1 = create_window1 ();
  option_menu = lookup_widget (window1, "optionmenu1");
  gtk_signal_connect (GTK_OBJECT (GTK_OPTION_MENU (option_menu)->menu),
                      "deactivate", GTK_SIGNAL_FUNC (on_option_selected),

Then add a handler to callbacks.c. You can get the index of the selected item
just like the previous answer:

static void
on_option_selected (GtkMenuShell *menu_shell,
                    gpointer data)
  GtkWidget *active_item;
  gint item_index;
  active_item = gtk_menu_get_active (GTK_MENU (menu_shell));
  item_index = g_list_index (menu_shell->children, active_item);

  g_print ("In on_option_selected active: %i\n", item_index);


On Thursday 04 October 2001 02:03 am, yannis1976 wrote:

how can I read which is the index of the currently selected item
in a GtkOptionMenu? (that is, 0 if the first is selected, 1 if the
second item is seletced, etc.)

Yannis Tsakiris

������ �� �����! - http://search.pathfinder.gr
������ mail ��� ��� Pathfinder - http://www.pathfinder.gr

Glade-users maillist  -  Glade-users ximian com

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