title: What causes assertion 'GTK_IS_MENU_ITEM (child)' failed?
body: <p>I am trying to create a Gtk.MenuBar in my Python application. <a href="http://python-gtk-3-tutorial.readthedocs.org/en/latest/menus.html" rel="nofollow">This</a> is what I've used as a tutorial. The following is my code for creating the MenuBar:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  import GTKSignal
  
  __author__ = 'xiaolong'
  
  from gi.repository import Gtk
  
  
  class XLDMenuBar(Gtk.MenuBar):
      MENUBAR_UI_INFO = """&lt;ui&gt;
              &lt;menubar name='MenuBar'&gt;
                  &lt;menu action='FileMenu'&gt;
  
                      &lt;menu action='File_New'&gt;
                          &lt;menuitem action='File_New_Dictionary' /&gt;
                      &lt;/menu&gt;
  
                      &lt;separator /&gt;
  
                      &lt;menuitem action='File_Open' /&gt;
  
                      &lt;menuitem action='File_Save' /&gt;
  
                      &lt;menu action='File_SaveAs'&gt;
                          &lt;menuitem action='File_SaveAs_Dictionary' /&gt;
                          &lt;menuitem action='File_SaveAs_SearchResult' /&gt;
                          &lt;menuitem action='File_SaveAs_SelectedVocables' /&gt;
                      &lt;/menu&gt;
  
                      &lt;menuitem action='File_Exit' /&gt;
  
                  &lt;/menu&gt;
              &lt;/menubar&gt;
          &lt;/ui&gt;"""
  
      def __init__(self, parent):
          super().__init__()
  
          self.parent = parent
          self.toplevel_menubar_action_group = Gtk.ActionGroup("toplevel_menubar_action_group")
  
          self.initialize_file_menu()
          self.add_file_menu()
          self.add_menu_action_handlers()
  
          # TODO: add other actions, so far only file menu
  
          self.load_ui_info()
  
      def initialize_file_menu(self):
          self.action_filemenu = Gtk.Action(name='FileMenu', label='File', tooltip='opens the file menu', stock_id=None)
  
          # file -&gt; new
          self.action_filemenu_new = Gtk.Action(name='File_New', label='New', tooltip=None, stock_id=None)
          self.action_filemenu_new_dictionary = Gtk.Action(
              name='File_New_Dictionary',
              label='New dictionary …',
              tooltip='opens the dialog for creating a new dictionary',
              stock_id=Gtk.STOCK_NEW
          )
  
          # file -&gt; open
          self.action_filemenu_open = Gtk.Action(
              name='File_Open',
              label='Open …',
              tooltip='opens the dialog for opening files',
              stock_id=Gtk.STOCK_OPEN
          )
  
          # file -&gt; save
          self.action_filemenu_save = Gtk.Action(
              name='File_Save',
              label='Save',
              tooltip='saves current changes of the dictionary to the dictionary file',
              stock_id=Gtk.STOCK_SAVE
          )
  
          # file -&gt; saveas
          self.action_filemenu_saveas = Gtk.Action(name='File_SaveAs', label='Save As', tooltip=None, stock_id=None)
          self.action_filemenu_saveas_dictionary = Gtk.Action(
              name='File_SaveAs_Dictionary',
              label='Save dictionary as …',
              tooltip='saves the current dictionary with current changes to a specified file',
              stock_id=Gtk.STOCK_SAVE_AS
          )
          self.action_filemenu_saveas_searchresult = Gtk.Action(
              name='File_SaveAs_SearchResult',
              label='Save search result as …',
              tooltip='saves the current search result to a specified file',
              stock_id=Gtk.STOCK_SAVE_AS
          )
          self.action_filemenu_saveas_selectedvocables = Gtk.Action(
              name='File_SaveAs_SelectedVocables',
              label='Save selected vocables as …',
              tooltip='saves the currently selected vocables to a specified file',
              stock_id=Gtk.STOCK_SAVE_AS
          )
  
          # file -&gt; exit
          self.action_filemenu_exit = Gtk.Action(
              name='File_Exit',
              label='Exit',
              tooltip='Closes the application',
              stock_id=Gtk.STOCK_QUIT
          )
  
      def add_file_menu(self):
          self.toplevel_menubar_action_group.add_action(self.action_filemenu)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_new)
          self.toplevel_menubar_action_group.add_action_with_accel(action=self.action_filemenu_new_dictionary, accelerator=None)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_open)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_save)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_saveas)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_saveas_dictionary)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_saveas_searchresult)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_saveas_selectedvocables)
          self.toplevel_menubar_action_group.add_action(self.action_filemenu_exit)
  
      def add_menu_action_handlers(self):
          self.action_filemenu_new_dictionary.connect(GTKSignal.ACTIVATE, lambda widget: print('You\'ve clicked \"New dictionary\"!'))
          self.action_filemenu_exit.connect(GTKSignal.ACTIVATE, lambda widget: print('You\'ve clicked Exit!'))
          # TODO: add other action handlers
  
      def load_ui_info(self):
          uimanager = self.parent.create_ui_manager()
          uimanager.insert_action_group(self.toplevel_menubar_action_group)
  
          menubar = uimanager.get_widget("/MenuBar")
  
          vertical_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
          vertical_box.pack_start(child=menubar, expand=False, fill=False, padding=0)
  
          self.add(vertical_box)
  </code></pre>
  
  <p>However, when I try to instanciate and add to my main window, I get the following assertion fail:</p>
  
  <pre><code>(__main__.py:12392): Gtk-CRITICAL **: gtk_menu_shell_insert: assertion 'GTK_IS_MENU_ITEM (child)' failed
  </code></pre>
  
  <p>To me it sounds, as if it says, that I am trying to add a non <code>MenuItem</code> to a <code>Menu</code>, but I cannot find that in my code. In the example on the tutorial website, they added <code>Gtk.Action</code>s to <code>Gtk.ActionGroups</code> just like I do, but their code does not cause this assertion to fail. I also checked the UI XML multiple times already and there is no <code>menu</code> to which I am trying to add a non <code>menuitem</code> or non <code>menu</code>, so I don't really know what's happening.</p>
  
  <p>Where is the mistake I am making?</p>
  
  <p><strong>EDIT#1</strong></p>
  
  <p>To add a working example, I'll insert the code for the main application window and the call of it.</p>
  
  <p>The main application window:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  from gi.repository import Gtk
  from gui.XLDMenuBar import XLDMenuBar
  
  __author__ = 'xiaolong'
  
  
  class XLDMainWindow(Gtk.Window):
  
      WINDOW_TITLE = 'Xiaolong Dictionary'
      DEFAULT_X_SIZE = 400
      DEFAULT_Y_SIZE = 300
      menubar = None
  
      def __init__(self):
          # super().__init__(title='Xiaolong Dictionary')
          super(XLDMainWindow, self).__init__(title=self.WINDOW_TITLE)
  
          self.set_default_size(self.DEFAULT_X_SIZE, self.DEFAULT_Y_SIZE)
  
          self.initialize_widgets()
          self.add_widgets()
  
      def initialize_widgets(self):
          self.menubar = XLDMenuBar(self)
  
      def add_widgets(self):
          self.add(self.menubar)
  
      def connect_signals(self):
          pass
  
      def create_ui_manager(self):
          uimanager = Gtk.UIManager()
  
          # Throws exception if something went wrong
          uimanager.add_ui_from_string(XLDMenuBar.MENUBAR_UI_INFO)
  
          # Add the accelerator group to the toplevel window
          accelgroup = uimanager.get_accel_group()
          self.add_accel_group(accelgroup)
          return uimanager
  </code></pre>
  
  <p>And the call for creating the application itself:</p>
  
  <pre><code>from gi.repository import Gtk
  from gtkplustool import GTKSignal
  from gtkplustool.gui.XLDMainWindow import XLDMainWindow
  
  __author__ = 'xiaolong'
  
  if __name__ == '__main__':
      xld_main_window = XLDMainWindow()
      xld_main_window.connect(GTKSignal.DELETE, Gtk.main_quit)
      xld_main_window.show_all()
      Gtk.main()
  </code></pre>
  
  <p>and the GTKSignal file I created:</p>
  
  <pre><code>__author__ = 'xiaolong'
  
  DELETE = 'delete-event'
  CLICKED = 'clicked'
  ACTIVATE = 'activate'
  </code></pre>
  
  <p>Inserted into the correct directory structure, these files should be a working example. I have the directories set up as follows:</p>
  
  <pre><code>gtkplustool --&gt; __main__.py
  gtkplustool --&gt; GTKSignal.py
  gtkplustool --&gt; gui --&gt; XLDMainWindow.py
  gtkplustool --&gt; gui --&gt; XLDMenuBar.py
  </code></pre>