[Glade-users] Getting value from an option menu



If you use Glade to define your GUI and Libglade to display 
it, how can you get the value of an option menu item in your 
C/C++ code?

This is easy to do with a GtkComboBox because you can just
call gtk_entry_get_text on the entry field part of the combo
box, but I haven't been able to figure out how to get the
value from a GtkOptionMenu.

Someone on the gtk-app-devel-list said that you just connect 
callbacks to the "activate" signals on the individual menu 
items, like you do for any other menu. However, Glade does 
not allow you to define signal handlers for the individual
items on an option menu like it does for other menus. It just 
lets you list the items. And since Libglade is generating the
interface from Glade's XML file, I don't have access to the 
menu items it creates to be able to connect signal handlers 
myself.

I thought I could just get to the label on the menu item
by referring to the child of the active menu item (as
shown below), but that just returns a NULL pointer.

        GtkWidget *option_menu;
        GtkWidget *menu;
        GtkWidget *menu_item_active;
        GtkWidget *label;
        gchar *label_value;

        option_menu = glade_xml_get_widget(xml, "optionmenu1");
        menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
        menu_item_active = gtk_menu_get_active(GTK_MENU(menu));
        assert(GTK_IS_MENU_ITEM(menu_item_active));
        assert(menu_item_active != NULL);
        
        label = GTK_BIN(menu_item_active)->child;
        assert(label != NULL);          /* ASSERTION FAILS */
        gtk_label_get(GTK_LABEL(label), &label_value);


Any ideas?

Thanks,
--
Dean Schumacher                 Email: dean schumacher usa alcatel com
Software Engineering Tools      Phone: 972.519.3252
Alcatel USA





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