# Need to bind each item's hotkey to trigger change tool,
passing its ID
# (position + 1 in the list, basically)
ac = []
for x, item in enumerate(self.util.items):
blah = lambda evt, y=x + 1: self.on_change_tool(evt, y)
_id = wx.NewId()
ac.append((wx.ACCEL_NORMAL, ord(item.hotkey.upper()), _id))
self.Bind(wx.EVT_MENU, blah, id=_id)
tbl = wx.AcceleratorTable(ac)
self.SetAcceleratorTable(tbl)
self is a Frame.
self.util.items is a list of classes, like: [Pen, Rectangle, Circle, Zoom]
each of which has a string "hotkey" class attribute, like "p", "r", "c", "z"
This works great on Windows, but on GTK nothing happens, my lambda
method is not called.
Similarly, I have the following code
class MyFrame(wx.Frame):
.....
self.Bind(wx.EVT_CHAR_HOOK, self.close_fullscreen)
def close_fullscreen(self, event=None):
""" Toggles fullscreen """
if not event.GetKeyCode() in [wx.WXK_ESCAPE]:
event.Skip() # propogate
else:
if self.IsFullScreen():
flag = (wx.FULLSCREEN_NOBORDER | wx.FULLSCREEN_NOCAPTION |
wx.FULLSCREEN_NOSTATUSBAR)
self.ShowFullScreen(False, flag)
menu = self.menu.FindItemById(ID_FULLSCREEN)
menu.Check(False)
Again, this works on Windows, but not on GTK. Placing a print statement
before "if not event.GetKeyCode()..." does not give any output,
regardless of which key of press.
Any ideas or suggestions would be welcomed, thanks.
Steven Sproat
Are you sure that some widget within the frame has the keyboard focus?
You might try adding a timer event that prints the results of
wx.Window.FindFocus() to verify where the focus is.
--
Robin Dunn
Software Craftsman
http://wxPython.org
Probably the same issue with focus.
>
>
> I tried giving the Frame the wx.WANTS_CHARS style, but it made no
> difference. I'm pretty stumped with this, it's the first an error is
> happening on Linux that works on Windows (it's usually the other way
> around!)
The wx.WANTS_CHARS style won't have any effect, as it's only used on MSW.
Can you reduce this problem to a small sample? In every case I've tried
once the focus is in the frame or some widget within the frame then it
stays there.
Adding a cpanel.SetFocus() here seems to take care of it for me. (The
panel will automatically pass the focus to its first child that accepts
the focus.)
This didn't solve my accelerator issue, but I made do by changing the
code so that it's caught in the EVT_CHAR_HOOK and processed there.
Thanks again :)