LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2004, 07:43 AM   #1
spuzzzzzzz
Member
 
Registered: Sep 2003
Location: Australia
Distribution: Gentoo
Posts: 465

Rep: Reputation: 30
help with gtk_ui_manager


I'm trying to write a small program using gtk+-2.4 but I'm having some problems with gtk_ui_manager. I can get the initial menus to display, but I'm having trouble changing the menus while the program is running. Here's some sample code:
Code:
#include <gtk/gtk.h>

int main(int argc, char **argv)
{
    GtkUIManager *ui;
    GtkActionGroup *menuactions;
    GtkAction *action;
    GtkWidget *main_window;
    GtkWidget *menubar;
    GError *error = NULL;
    
    gtk_init(&argc, &argv);
    
    ui = gtk_ui_manager_new();
    
    menuactions = gtk_action_group_new("MenuActions");
    action = gtk_action_new("MenuAction", "Menu", NULL, NULL);
    gtk_action_group_add_action(menuactions, action);
    action = gtk_action_new("SubMenuAction", "Submenu", NULL, NULL);
    gtk_action_group_add_action(menuactions, action);
    action = gtk_action_new("ItemAction", "Item", NULL, NULL);
    gtk_action_group_add_action(menuactions, action);
    action = gtk_action_new("ItemAction2", "Item2", NULL, NULL);
    gtk_action_group_add_action(menuactions, action);
    gtk_ui_manager_insert_action_group(ui, menuactions, 1);
    
    gtk_ui_manager_add_ui_from_file(ui, "menus.xml", &error);
    gtk_ui_manager_add_ui(ui, gtk_ui_manager_new_merge_id(ui),
                          "/ui/menubar/File/SubMenu", "Item2", "ItemAction2",
                          GTK_UI_MANAGER_MENUITEM, TRUE);
    //gtk_ui_manager_add_ui_from_file(ui, "moremenus.xml", &error);
    menubar = gtk_ui_manager_get_widget(ui, "/menubar");
    
    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_add(GTK_CONTAINER(main_window), menubar);
    gtk_widget_show_all(main_window);
    
    gtk_main();
}
And here is the menus.xml file:
Code:
<ui>
  <menubar>
    <menu name="Menu" action="MenuAction">
      <menu name="SubMenu" action="SubMenuAction">
        <menuitem name="MenuItem" action="ItemAction" />
      </menu>
    </menu>
  </menubar>
</ui>
And the moremenus.xml file:
Code:
<ui>
  <menubar>
    <menu name="Menu" action="MenuAction">
      <menu name="SubMenu" action="SubMenuAction">
        <menuitem name="Item2" action="ItemAction2" />
      </menu>
    </menu>
  </menubar>
</ui>
The problem is that Item2 doesn't appear in the Submenu. If I delete the gtk_ui_manager_add_ui() function call and uncomment the gtk_ui_manager_add_ui_from_file() call, it works. But its really inconvenient for me to have to specify all the menus in a file - I want to be able to insert menu items using a pathname. Does anyone know how to use gtk_ui_manager_add_ui() properly?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration