title: With wxPython, How can I get an event from a popup menu to the calling window?
body: <p>I've been working on getting data from a popup menu back to another control. I've setup a custom menu class, and from there I catch the EVT_MENU, and raise another custom event so I can return some customized data from the menu, rather than just the menu item id or text.</p>
  
  <p>The problem I'm running into is that the event handler I've bound to the custom event I'm creating isn't being called. Here's a distilled example that displays the behavior in question.</p>
  
  <pre><code>import wx
  import wx.lib.newevent
  
  class Example(wx.Frame):
      def __init__(self, parent):
          super(Example, self).__init__(parent, wx.ID_ANY)
          self.panel = wx.Panel(self)
          self.panel.Bind(wx.EVT_CONTEXT_MENU, self._showMenu)
  
          self.Bind(RClickMenu.EVT_CHANGE, self._eventReciever)
  
      def _eventReciever(self, evt):
          print 'notified'
  
      def _showMenu(self, evt):
          pos = evt.GetPosition()
          pos = self.panel.ScreenToClient(pos)
          self.panel.PopupMenu(RClickMenu(), pos)
  
  class RClickMenu(wx.Menu):
      ChangeEvent, EVT_CHANGE = wx.lib.newevent.NewEvent()
      vals = (('Item 1', 8),
              ('Item 2', None))
  
      def __init__(self):
          super(RClickMenu, self).__init__()
          for name, val in self.vals:
              item = self.Append(wx.ID_ANY, name)
              self.Bind(wx.EVT_MENU, self._notify, item)
  
      def _notify(self, event):
          item = self.FindItemById(event.GetId())
          text = item.GetText()
          for name, val in self.vals:
              if name == text:
                  value = val
                  break
  
          print 'do_notify'
          evt = self.ChangeEvent(value=value)
          wx.PostEvent(self, evt)
  
  app = wx.App(False)
  Example(None).Show()
  app.MainLoop()
  </code></pre>
  
  <p>What I'm seeing is that RClickMenu._notify is being called, but the event it raises, RClickMenu.EVT_CHANGE is never picked in Example, so Example._eventReciever is never called. Any ideas as to why?</p>
  
  <p><strong>Edit:</strong> So it seems this is a parenting issue, where the RClickMenu or the popup menu that's created with Panel.PopupMenu isn't technically a child of Example. I'd still much rather be able to do something in the nature of this example, but for now I'm just creating the wx.Menu and populating it inside of Example, and catching the wx.EVT_MENU there. Not really ideal, but it works.</p>