I’m trying to set up a global keyboard shortcut for my application. I know how to do this by associating the shortcut with a menu item, but I want to do it without a corresponding menu item. As per the instructions here (http://lists.wxwidgets.org/pipermail/wxpython-users/2003-August/021655.html), I should be able to do this with an accelerator table, but I can’t get it to work.
I’ve included a small, self-contained sample that attempts to bind an event handler with the Ctrl-L shortcut. Can anybody see what I’m doing wrong? Thanks in advance.
I am running wxPython 2.8.8.1 on Ubuntu 8.04.1 Hardy.
···
import wx
class MainWindow(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init (self, parent, -1, title, size=(500,200))
self.panel = wx.Panel(self, -1)
EVT_TEST_ID = wx.NewId()
wx.EVT_MENU(self, EVT_TEST_ID, self.OnTestEvent)
aTable = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('L'), EVT_TEST_ID)
])
self.SetAcceleratorTable(aTable)
self.Show(True)
def OnTestEvent(self, event):
print "OnTestEvent fired"
app = wx.App()
frame = MainWindow(None, -1, “Test”)
app.MainLoop()