wx.Frame not getting keyboard events on Ubuntu 12.04

161 views
Skip to first unread message

Dane Larsen

unread,
Oct 1, 2012, 4:22:09 PM10/1/12
to wxpytho...@googlegroups.com
Hi all,

I'm trying to get a wxpython app running on Ubuntu. It was developed on Mac OSX, and runs perfectly fine there.
My problem is that wx.Frame and GLCanvas don't seem to receive keyboard events on Ubuntu.

Here's some example code that exhibits the problem:

#!/usr/bin/env python
import wx

class Frame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title="", size=(200,100))
        
        self.Bind(wx.EVT_CHAR, self.keyEvent)
        self.Bind(wx.EVT_MOTION, self.motionEvent)

        self.SetFocus()
        self.Show(True)

    def keyEvent(self, event):
        print "Key event"

    def motionEvent(self, event):
        print "Motion event"

app = wx.App(False)
frame = Frame(None)
app.MainLoop()


The motionEvent works just fine, but keyEvent is never called.
Is this a bug in wxwidgets or wxpython, or am I just doing something wrong? 
I'm relatively new to the wx world, so it's entirely possible I've just missed something obvious. 

Thanks,
Dane Larsen

Robin Dunn

unread,
Oct 3, 2012, 7:06:12 PM10/3/12
to wxpytho...@googlegroups.com
Whether wx.Frames are able to catch key events is not defined by wx and
therefore implementation dependent. The fact that it may work on some
platforms is basically just a happy coincidence. I'm not sure about the
GLCanvas class, but I would expect it to be able to if it has the focus.
You may want to double check where the focus is at by doing something
like "print wx.Window.FindFocus()" from a timer or something.


--
Robin Dunn
Software Craftsman
http://wxPython.org

Dane Larsen

unread,
Oct 4, 2012, 12:44:09 PM10/4/12
to wxpytho...@googlegroups.com
Interesting. I wasn't aware of that. I'll see if I can force the GLCanvas to take the focus.

Thanks for the help,
Dane
Reply all
Reply to author
Forward
0 new messages