Fwd: [wxpython-users] Setting up global keybindings without corresponding menu items
mercado mercado
mercado949 at gmail.com
Mon Nov 24 19:00:27 EST 2008
Forwarded conversation
Subject: Setting up global keybindings without corresponding menu items
------------------------
From: *mercado mercado* <mercado949 at gmail.com>
Date: Fri, Aug 1, 2008 at 4:15 PM
To: wxpython-users at lists.wxwidgets.org
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* <mike at pythonlibrary.org>
Date: Sat, Aug 2, 2008 at 12:15 PM
To: wxpython-users at lists.wxwidgets.org
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
wxpython-users at lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
----------
From: *mercado mercado* <mercado949 at gmail.com>
Date: Sat, Aug 2, 2008 at 4:02 PM
To: wxpython-users at lists.wxwidgets.org
Thanks for the response Mike. Unfortunately, the alternative syntax doesn't
work for me either.
???
----------
From: *Mike Driscoll* <mike at pythonlibrary.org>
Date: Mon, Aug 4, 2008 at 8:56 AM
To: wxpython-users at lists.wxwidgets.org
mercado mercado wrote:
> On Sat, Aug 2, 2008 at 1:15 PM, Mike Driscoll <mike at pythonlibrary.org<mailto:
> mike at pythonlibrary.org>> 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* <robin at alldunn.com>
Date: Mon, Aug 4, 2008 at 1:31 PM
To: wxpython-users at lists.wxwidgets.org
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* <mercado949 at gmail.com>
Date: Mon, Aug 4, 2008 at 1:48 PM
To: wxpython-users at lists.wxwidgets.org
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* <mercado949 at gmail.com>
Date: Mon, Nov 24, 2008 at 6:58 PM
To: python dev <python.dev.9 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081124/43d2c08a/attachment.html>
More information about the Python-list
mailing list