Photoshop-like Focus with wxPython

Greets,

What's the best way to implement a photoshop-like focus policy?

What do I mean by that?

* Most key events get handled at the top level (E.g. a plain 'V' key
switches to the move tool pretty much no matter what you are doing at
the given moment.)

* But sometimes something has full focus and consumes key events (like
when you're editing text on the canvas, 'V' inserts a V character).

Initially I tried just forcing focus to the canvas all the time, but
that messes up transient popups and also interferes with having some
items be focusable (like a text box where you can type in the zoom
level, say).

wx.EVT_CHAR_HOOK seems like it might be able to help, but on Windows
it doesn't trap plain alpha-numeric keys, just special ones. It seems
to get all key strokes on Linux, though. Googling I found this issue
was reported by Robin previously and the response was "I thought that
only worked on Windows -- I think it should be private" and there the
conversation ended.
(http://lists.wxwidgets.org/archive/wx-dev/msg00153.html -- But in
fact it seems to work fine on Linux at least.)

So EVT_CHAR_HOOK won't do it. At least not in wx 2.8.4.

So what's a reasonable way to make all key events find their way to
the main app handler? The only other thing I can think to do is to
subclass every button or widget I use to do special key handling. Or
have the top-level frame bind wx.EVT_KEY_DOWN/UP for every single
widget.

Thanks for any help.

--bb

Bill Baxter wrote:

Greets,

What's the best way to implement a photoshop-like focus policy?

What do I mean by that?

* Most key events get handled at the top level (E.g. a plain 'V' key
switches to the move tool pretty much no matter what you are doing at
the given moment.)

* But sometimes something has full focus and consumes key events (like
when you're editing text on the canvas, 'V' inserts a V character).

I would try using a wx.AcceleratorTable, then all matching keys are turned into a menu event regardless of what widget in the app has the focus. When you have some widget active where you want the keys to behave normally then you can set a new accelerator table that doesn't have those items defined, and then switch it back when done.

ยทยทยท

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