[Glade-users] callbacks and signals from GtkOptionMenu?

Joe Van Andel wrote:

I'm using Python 1.5.2, gnome-python-1.0.53, libgtk+1.2.8 with
glade-0.5.11 and libglade-0.14 on Redhat 6.2.

I've used 'glade' to build a user interface.  My application has a
GtkOptionMenu (called 'filter_option') with three items.  I want to
attach handlers that will be called when one of the menu items is
selected so my Python application can react to the user's choices.

The FAQ covers this:

3.6 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 "deactivate"
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);

I hope that still works in Python.


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