wx.Frame not getting keyboard events on Ubuntu 12.04

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

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.

···

On 10/1/12 1:22 PM, Dane Larsen wrote:

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.

--
Robin Dunn
Software Craftsman

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

···

On Wednesday, October 3, 2012 5:06:17 PM UTC-6, Robin Dunn wrote:

On 10/1/12 1:22 PM, Dane Larsen wrote:

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.

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