title: LIBDBUSMENU-GLIB-WARNING
body: <p>I created recently a piece of code that always showed me a message like this twice when I closed it:</p>
  
  <blockquote>
    <p>(python:11712): LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.</p>
  </blockquote>
  
  <p>What I want is to get rid from that warning.
  This piece of code reproduce such behaviour (the message appears once when closed):</p>
  
  <pre><code>import wx
  
  class MyFrame(wx.Frame):
    def __init__(self, parent):
      wx.Frame.__init__(self, parent, title="Sample")
      menuBar = wx.MenuBar()
      filemenu = wx.Menu()
      filemenu.Append(wx.ID_ANY,"&amp;Pass")
      menuBar.Append(filemenu,"&amp;File")
      self.SetMenuBar(menuBar)
  
  app = wx.PySimpleApp()
  frame = MyFrame(None)
  frame.Show()
  app.MainLoop()
  </code></pre>
  
  <p>It works perfectly, yet the warning message appears when I close the app.
  That's a Linux-only message, nothing appears when I tried it on Windows.</p>
  
  <p>A work around I used was to bind a close event handler in my frame</p>
  
  <pre><code>  def __init__(self, parent):
      ... # Previous code here
      self.Bind(wx.EVT_CLOSE, self.OnClose)
  </code></pre>
  
  <p>And make such event handler as</p>
  
  <pre><code>  def OnClose(self, evt):
      for menu in self.GetMenuBar().GetMenus(): # (wx.Menu, caption) tuples
        menu[0].Destroy() # Bad parents won't remove you, you'll DIE before!!!
      evt.Skip()
  </code></pre>
  
  <p>That worked ok in that simple app on Linux, however it crashed when I tried on Windows. So I wanted to see what was happening in the runtime while on Linux, replacing the line</p>
  
  <pre><code>      menu[0].Destroy()
  </code></pre>
  
  <p>to</p>
  
  <pre><code>      print menu[0].Parent
  </code></pre>
  
  <p>And it showed me "None" as answer. However I couldn't make that:</p>
  
  <pre><code>      menu[0].Parent = self
  </code></pre>
  
  <p>And neither:</p>
  
  <pre><code>      menu[0].Parent = self.GetMenuBar()
  </code></pre>
  
  <p>Since both raises TypeError:</p>
  
  <blockquote>
    <p>TypeError: in method 'Menu_SetParent', expected argument 2 of type 'wxMenu *'</p>
  </blockquote>