Re: [gtk-list] Attaching callbacks for hscale and optionmenu



Vaibhav Vaish wrote:
> 
> Hello,
> 
> I'm building a GUI with gtk+ 1.2.6 and glade 0.5.3 on RedHat 6.1. I am
> using the optionmenu and horizontal scale widget. I would like to attach a
> callback which is invoked whenever the option in the menu is changed, and
> another which is invoked whenever the value of the hscale is changed.
> 
> Could somebody please tell me for which events I should attach the
> callback with gtk_signal_connect in order to do this ? I searched the
> reference docs, tutorial, and /usr/include/gtk, but couldn't figure it
> out.

These are both covered in the Glade FAQ, which should be included in all
packages of Glade, but you can also find at

  http://cvs.gnome.org/lxr/source/glade/FAQ


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),
                      NULL);


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);
}



3.7 How do I connect to GtkAdjustment signals?

Glade doesn't support this at present, but you can set it up manually, in a
similar way to question 3.6.

When you create the window, get a pointer to the widget containing the
adjustment, and connect to the "changed" or "value_changed" signals:

  window1 = create_window1 ();
  hscale = lookup_widget (window1, "hscale1");
  gtk_signal_connect (GTK_OBJECT (GTK_RANGE (hscale)->adjustment),
                      "changed", GTK_SIGNAL_FUNC (on_adjustment_changed),
                      NULL);


Damon




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