Forwarded conversation Subject: Setting up global keybindings without corresponding menu items ------------------------
From: *mercado mercado* <[EMAIL PROTECTED]> Date: Fri, Aug 1, 2008 at 4:15 PM To: [EMAIL PROTECTED] 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() ---------- From: *Mike Driscoll* <[EMAIL PROTECTED]> Date: Sat, Aug 2, 2008 at 12:15 PM To: [EMAIL PROTECTED] mercado mercado wrote: > I am running wxPython 2.8.8.1 <http://2.8.8.1> on Ubuntu 8.04.1 Hardy. Hmmm...this works on Windows XP, '2.8.7.1 (msw-unicode)', Python 2.5.2. Try changing the event binding to this instead: self.Bind(wx.EVT_MENU, self.OnTestEvent, id=EVT_TEST_ID) That's the way I was told to do it...by Robin, I think. ------------------- Mike Driscoll Blog: http://blog.pythonlibrary.org Python Extension Building Network: http://www.pythonlibrary.org _______________________________________________ wxpython-users mailing list [EMAIL PROTECTED] http://lists.wxwidgets.org/mailman/listinfo/wxpython-users ---------- From: *mercado mercado* <[EMAIL PROTECTED]> Date: Sat, Aug 2, 2008 at 4:02 PM To: [EMAIL PROTECTED] Thanks for the response Mike. Unfortunately, the alternative syntax doesn't work for me either. ??? ---------- From: *Mike Driscoll* <[EMAIL PROTECTED]> Date: Mon, Aug 4, 2008 at 8:56 AM To: [EMAIL PROTECTED] mercado mercado wrote: > On Sat, Aug 2, 2008 at 1:15 PM, Mike Driscoll <[EMAIL PROTECTED]<mailto: > [EMAIL PROTECTED]>> wrote: > > Hmmm...this works on Windows XP, '2.8.7.1 <http://2.8.7.1> > (msw-unicode)', Python 2.5.2. <http://2.5.2.> I loaded Ubuntu Hardy in my VM and confirmed that it does not work with your sample code. Weird. I did find a recipe in the wiki that might work for you: http://wiki.wxpython.org/Using%20Multi-key%20Shortcuts It's a little bit above my head, but it seems to be using an alternative technique. Maybe it can be modified to work for you? ---------- From: *Robin Dunn* <[EMAIL PROTECTED]> Date: Mon, Aug 4, 2008 at 1:31 PM To: [EMAIL PROTECTED] Try adding a widget to the frame that can have the keyboard focus. The focus needs to be on some widget within the frame for accelerators attached to the frame to be active. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! ---------- From: *mercado mercado* <[EMAIL PROTECTED]> Date: Mon, Aug 4, 2008 at 1:48 PM To: [EMAIL PROTECTED] I tried adding a button to the panel, and giving the button focus, and now the accelerator table is working as expected. Thanks Mike and Robin, for your prompt and helpful responses. ---------- From: *mercado mercado* <[EMAIL PROTECTED]> Date: Mon, Nov 24, 2008 at 6:58 PM To: python dev <[EMAIL PROTECTED]>
-- http://mail.python.org/mailman/listinfo/python-list