dwhitney67
December 21st, 2010, 03:31 AM
I'm evaluating gtkmm to see how it compares with OSF Motif in as far as developing a GUI is concerned. One thing that has me stumped is how to get a reference to a ToggleButton that has been created as a menu item in a UIManager.
Here's a snip of the code I am using:
...
m_refActionGroup = ActionGroup::create();
...
m_refActionGroup->add(Action::create("OptionsMenu", "Options"));
m_refActionGroup->add(ToggleAction::create("AlarmNotif", "Alarm Notification"), sigc::mem_fun(*this, &EventDisplay::alarmNotificationCB));
...
m_refUIManager = UIManager::create();
m_refUIManager->insert_action_group(m_refActionGroup);
add_accel_group(m_refUIManager->get_accel_group());
Glib::ustring ui_info = "<ui>"
" <menubar name='MenuBar'>"
...
" <menu action='OptionsMenu'>"
" <menuitem action='AlarmNotif'/>"
...
" </menubar>"
"</ui>";
try
{
m_refUIManager->add_ui_from_string(ui_info);
Widget* menubar = m_refUIManager->get_widget("/MenuBar"); // works!
Widget* togBut1 = m_refUIManager->get_widget("/AlarmNotif"); // fails!
...
}
catch (const Glib::Error& e)
{
std::cerr << "Building menus failed: " << e.what() << std::endl;
}
As shown above, I can successfully get the MenuBar, which is then packed into the VBox. However, when I attempt to get the AlarmNotif menu item, I get a NULL pointer result.
What is the proper way to get a reference to this object? During initialization of my Window, I want to set the ToggleButton using set_active().
Btw, I am currently referencing the following gtkmm documentation (http://library.gnome.org/devel/gtkmm-tutorial/stable/); is there anything else that is better and more comprehensive in scope?
Here's a snip of the code I am using:
...
m_refActionGroup = ActionGroup::create();
...
m_refActionGroup->add(Action::create("OptionsMenu", "Options"));
m_refActionGroup->add(ToggleAction::create("AlarmNotif", "Alarm Notification"), sigc::mem_fun(*this, &EventDisplay::alarmNotificationCB));
...
m_refUIManager = UIManager::create();
m_refUIManager->insert_action_group(m_refActionGroup);
add_accel_group(m_refUIManager->get_accel_group());
Glib::ustring ui_info = "<ui>"
" <menubar name='MenuBar'>"
...
" <menu action='OptionsMenu'>"
" <menuitem action='AlarmNotif'/>"
...
" </menubar>"
"</ui>";
try
{
m_refUIManager->add_ui_from_string(ui_info);
Widget* menubar = m_refUIManager->get_widget("/MenuBar"); // works!
Widget* togBut1 = m_refUIManager->get_widget("/AlarmNotif"); // fails!
...
}
catch (const Glib::Error& e)
{
std::cerr << "Building menus failed: " << e.what() << std::endl;
}
As shown above, I can successfully get the MenuBar, which is then packed into the VBox. However, when I attempt to get the AlarmNotif menu item, I get a NULL pointer result.
What is the proper way to get a reference to this object? During initialization of my Window, I want to set the ToggleButton using set_active().
Btw, I am currently referencing the following gtkmm documentation (http://library.gnome.org/devel/gtkmm-tutorial/stable/); is there anything else that is better and more comprehensive in scope?