I have an OpenGL wxpython app that I’m trying to get working in Ubuntu. It was developed (by someone else) on Mac OSX, and works just fine there.
The last outstanding problem I have is that keyboard events aren’t getting captured.
The code looks something like this:
class GLFrame(wx.Frame):
def __init__(...):
...
self.canvas.Bind(wx.EVT_MOTION, self.mouseMotion)
self.canvas.Bind(wx.EVT_CHAR, self.character)
...
def character(self, evt):
print "EVT_CHAR"
# do stuff
def mouseMotion(self, evt):
print "EVT_MOTION"
# do stuff
I’ve grepped the entire codebase for Bind calls, and nothing else is using EVT_CHAR, EVT_KET_DOWN or EVT_KEY_UP. I’ve also tried both EVT_KEY_DOWN and EVT_KEY_UP, and neither of them work.
I’ve also tried changing the bind calls from
self.canvas.Bind(...)
to
self.Bind(...)
This breaks EVT_MOTION, and the EVT_CHAR callback still doesn’t get called.
Are there any calls that might capture keyboard events before they get to GLFrame? I’m new to wxpython, and while it mostly makes sense to me, I’m sure there are ‘gotchas’ that I am unaware of.
According to the wxpython Google group, whether or not wx.Frame receives keyboard events is implementation-dependent. The Ubuntu implementation does not receive them.
From: https://groups.google.com/d/msg/wxpython-users/dF2gf5KvFhE/M_-aRuG3aWUJ
Turns out, the GLCanvas can receive keyboard events just fine. For whatever reason, it wasn’t getting focus. Calling
fixed the problem.