Обработчик события всплывающего меню wxpython не работает - PullRequest
0 голосов
/ 24 ноября 2018

Итак, у меня есть некоторый простой код кадра, обратите внимание, что wx.Frame имеет не подкласс, а кадр работает в глобальной области видимости:

import wx

app = wx.App()

def OnSettings(event):
    print ("'Settings...' selected")

def OnDefaults(event):
    print ("'Defaults...' selected")

def OnPrefs(event):
    print ("'Preferences' selected")

def OnOpen(event):
    print ("'Open...' selected")

def OnClose(event):
    print ("'Close' selected")

def OnCloseAll(event):
    print ("'CloseAll' selected")

def OnNew(event):
    print ("'New...' selected")

def OnQuit(event):
    print ("Quit selected")
    top.Close(True)

def OnExit(event):
    dlg = wx.MessageDialog(top, "Do you really want to close this application?", "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
    result = dlg.ShowModal()
    dlg.Destroy()
    if result == wx.ID_OK:
       top.Destroy()
    top.Close(True)

def OnRightDown(event):
    top.PopupMenu(rootMenu, event.GetPosition())

rootMenu = wx.Menu()
fileMenu = wx.Menu()

itemNew = wx.MenuItem(fileMenu, wx.NewId(), "New...","Create a new instance of something")
fileMenu.Bind(wx.EVT_MENU, OnNew, itemNew)
fileMenu.Append(itemNew)

itemOpen = wx.MenuItem(fileMenu, wx.NewId(), "Open...","Open an existing instance of something")
fileMenu.Bind(wx.EVT_MENU, OnOpen, itemOpen)
fileMenu.Append(itemOpen)

fileMenu.AppendSeparator()

itemClose = wx.MenuItem(fileMenu, wx.NewId(), "Close","Close whatever is open on top")
fileMenu.Bind(wx.EVT_MENU, OnClose, itemClose)
fileMenu.Append(itemClose)

itemCloseAll = wx.MenuItem(fileMenu, wx.NewId(), "Close All","Close everything")
fileMenu.Bind(wx.EVT_MENU, OnCloseAll, itemCloseAll)
fileMenu.Append(itemCloseAll)

rootMenu.AppendSubMenu(fileMenu,"Manage Data","Open, close, or create resources")

configMenu = wx.Menu()

itemSettings = wx.MenuItem(configMenu, wx.NewId(), "Settings...","Configure environmental operating parameters")
configMenu.Bind(wx.EVT_MENU, OnSettings, itemSettings)
configMenu.Append(itemSettings)

itemDefaults = wx.MenuItem(configMenu,wx.NewId(), "Defaults...","Configure default data sources, views, and processing options")
configMenu.Bind(wx.EVT_MENU, OnDefaults, itemDefaults)
configMenu.Append(itemDefaults)

itemPrefs = wx.MenuItem(configMenu,wx.NewId(), "Preferences...","Configure User Interface Cosmetics")
configMenu.Bind(wx.EVT_MENU, OnPrefs, itemPrefs)
configMenu.Append(itemPrefs)

rootMenu.AppendSubMenu(configMenu,"Manage Configuration","Configure Application for operations")

terminalMenu = wx.Menu()

itemExit = wx.MenuItem(terminalMenu,wx.NewId(), "Exit","Terminate after updating and closing anything that's open.")
terminalMenu.Bind(wx.EVT_MENU, OnExit, itemExit)
terminalMenu.Append(itemExit)

itemQuit = wx.MenuItem(terminalMenu,wx.NewId(), "Quit","Close the root window and abandon anything unsaved.")
terminalMenu.Bind(wx.EVT_MENU, OnQuit, itemQuit)
terminalMenu.Append(itemQuit)

rootMenu.AppendSubMenu(terminalMenu,"Terminate Operations","Exit Session")

top =wx.Frame(None, title="Base Window",size=((1400,875)), style=wx.CAPTION|wx.RESIZE_BORDER|wx.WS_EX_PROCESS_IDLE)
top.Bind(wx.EVT_RIGHT_DOWN, OnRightDown)
top.Centre()
top.Show()
app.SetTopWindow(top)
app.MainLoop()

Проблема в том,ни один из обработчиков событий для меню фактически не срабатывает.Они должны быть там, если я закомментирую их, я получу ожидаемую ошибку, но обработчики-заглушки не выводятся на консоль, а диалоговое окно события «Выход» (добавлено для целей тестирования) не запускается.

Какого черта я пропускаю?

Приветствия

...