Problem with EVT_KEY_DOWN under wxGTK

Hi

I am trying to catch key events in a fullscreen window for showing a slideshow of images.
However I am struggling to catch key events at all under wxPython with GTK on Linux

The following test code catches key events on Windows (Python 2.3.3, wxPython 2.4.2.4)

from wxPython.wx import *
app = wxPySimpleApp()
frame = wxFrame(None, -1, "Hello World")
def OnKeyDown(event):
  print "got it!"
EVT_KEY_DOWN(frame, OnKeyDown)
frame.Show(1)
app.MainLoop()

But on Linux (Python 2.3.3, wxPythonGTK-py2.3-2.4.2.4-1) it fails to catch key events at all.
I read somewhere that you shold catch key events using panels, not frames.
So I tried the following code, which also works on Window, but fails on Linux

from wxPython.wx import *
app = wxPySimpleApp()
frame = wxFrame(None, -1, "Hello World")
panel = wxPanel(frame, -1)
def OnKeyDown(event):
  print "got it!"
EVT_KEY_DOWN(panel, OnKeyDown)
frame.Show(1)
app.MainLoop()

Am I doing the wrong thing? Any hints?

David

David Fraser wrote:

Hi

I am trying to catch key events in a fullscreen window for showing a slideshow of images.
However I am struggling to catch key events at all under wxPython with GTK on Linux

[...]

But on Linux (Python 2.3.3, wxPythonGTK-py2.3-2.4.2.4-1) it fails to catch key events at all.
I read somewhere that you shold catch key events using panels, not frames.
So I tried the following code, which also works on Window, but fails on Linux

[...]

Key events are delivered to the window with the focus. I think you'll find that if you click on the window that it will then start reporting the key events. For a general fix, call panel.SetFocus()

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Can forms on OS X get key events if the only controls on them are buttons, combos, etc., that don't get focus?

      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com

···

On Apr 6, 2004, at 2:42 PM, Robin Dunn wrote:

Key events are delivered to the window with the focus. I think you'll find that if you click on the window that it will then start reporting the key events. For a general fix, call panel.SetFocus()

Ed Leafe wrote:

···

On Apr 6, 2004, at 2:42 PM, Robin Dunn wrote:

Key events are delivered to the window with the focus. I think you'll find that if you click on the window that it will then start reporting the key events. For a general fix, call panel.SetFocus()

    Can forms on OS X get key events if the only controls on them are buttons, combos, etc., that don't get focus?

I think so. See the KeyEvents sample in the demo for an example. The Blue panel will change when it has the focus.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

David Fraser wrote:

Hi

I am trying to catch key events in a fullscreen window for showing a slideshow of images.
However I am struggling to catch key events at all under wxPython with GTK on Linux

[...]

But on Linux (Python 2.3.3, wxPythonGTK-py2.3-2.4.2.4-1) it fails to catch key events at all.
I read somewhere that you shold catch key events using panels, not frames.
So I tried the following code, which also works on Window, but fails on Linux

[...]

Key events are delivered to the window with the focus. I think you'll find that if you click on the window that it will then start reporting the key events. For a general fix, call panel.SetFocus()

Thanks for the explanation Robin.
I think the problem was in trying to get the focus I was calling frame.SetFocus() but it didn't get the keypresses... clicking or panel.SetFocus seems to work

David