Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

strange menu event generated by panel

Open daidai-up opened this issue 2 years ago • 4 comments

  • windows LTSC 2019
  • Python 3.7.9
  • wxPython 4.2.0 msw (phoenix) wxWidgets 3.2.0
import wx


class Frame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        panel = wx.Panel(self)
        self.Bind(wx.EVT_MENU, self.OnMenu)

    def OnMenu(self, event):
        print(event.GetId())          # 1
        print(event.GetEventObject())   # <wx._core.Panel object at 0x00000210DF4FA318>


class App(wx.App):
    def OnInit(self):
        frame = Frame(None)
        frame.Center()
        frame.Show()
        return super().OnInit()


def main():
    app = App()
    app.MainLoop()


if __name__ == '__main__':
    main()

run and press Enter, Frame will receive a menu event generated by Panel, why?

daidai-up avatar Feb 13 '23 02:02 daidai-up

EVT_MENU is a command event (from the docu)

Note that CommandEvents and CommandEvent-derived event classes by default and unlike other Event-derived classes propagate upward from the source window (the window which emits the event) up to the first parent which processes the event. Be sure to read How Events Propagate Upwards.

da-dada avatar Feb 24 '23 21:02 da-dada

EVT_MENU is a command event (from the docu)

Note that CommandEvents and CommandEvent-derived event classes by default and unlike other Event-derived classes propagate upward from the source window (the window which emits the event) up to the first parent which processes the event. Be sure to read How Events Propagate Upwards.

What puzzles me is that there is no menubar, but press key triggers a menu event

daidai-up avatar Apr 26 '23 02:04 daidai-up

well, you may (or may not) be surprised how many events are going through the system! the logic is the other way round: you Bind those events you are interested in..

da-dada avatar Apr 26 '23 15:04 da-dada

@daidai-up

return super().OnInit()

should be 

return True

Metallicow avatar Apr 27 '23 20:04 Metallicow