FW: keyboard control of wxPython applications ?

Hi,

I am developing Python applications and considering WxPython as its user
interface and I have some key (excuse the pun) requirements that must be
addressed.

The applications will mainly be used on a Windows desktop (with portability
a goal) for high thruput and repetitive tasks therefore performance and
efficiency is important.

The ideal solution would be that the various features and functions of the
application be driven via the keyboard using Tab, Enter, Alt+key, Ctrl+key
and Fn keys while navigating the various on screen widgets including
buttons, controls, input fields and menus. It would be significantly less
efficient to have to continually flip between a mouse for navigation and the
keyboard for data entry.

Does anyone have pros and cons of wxPython in terms of keyboarding ability ?

Many thanks,

Alan Sheehan
Chief Technology Officer
Interactive Enterprise

email: adsheehan@iel.ie
cell: +353 87 9271111
desk: +353 1 4491907
chat: adsheehan@jabber.iel.ie

7 Riverwalk
National Digital Park
Citywest
Dublin 24
Ireland
Tel: +353 1 4491900
Fax: +353 1 4491901

I've just been writing an application that uses a bunch of user-defined
key presses (particularly CTRL+<key> ones), and I found wxPython really
good for it. (As opposed to java+swing, which made me want to hurl my
computer through a window).

I simply intercepted the 'EVT_KEY_DOWN' event (which provides handy
methods to find out what modifier keys are down) and used a
keycode-to-function dictionary to associate keys with methods.

   ctrl_presses = { ord('A') : self.SpawnNasalDemons,
                    ord('B') : self.HaltAndCatchFire, ... etc. }

No problem at all.

···

On Wed, 5 Jan 2005, Alan Sheehan wrote:

Does anyone have pros and cons of wxPython in terms of keyboarding
ability ?

--
<<<Alexspudros Potatopoulos>>>
Defender of Spudkind

Alan Sheehan wrote:
...

Does anyone have pros and cons of wxPython in terms of keyboarding ability ?

Generally speaking, wxPython is fine, however you'll find that some composite controls have counter-intuitive or even broken keyboard functionality (though it's been a while since I've played with wxPython, so that may have improved, calendar controls were the worst back in my day). wxoo has a composite control hierarchy which makes it easier to get around that when writing new controls, but that doesn't help you with already-written ones.

Getting the tab-ordering correct is a bit of a pain sometimes, but probably not more than in any other GUI kit which doesn't have explicit setting of orders (it's all implicitly done (unless you add in modules that support setting the tab-order, which is something I never did)).

All that said, for a minimal application using primarily core controls, you're probably fine out-of-the-box.

Good luck,
Mike

···

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

In our wxPython UI we do something similar, a table to map key events into method calls. This makes it very straightforward to handle any key event in any wxPython (sub)class.

The table is a Python dict and is created at the time the class is instantiated. All methods of the class are scanned and each method name starting with OnKeyDown_... creates an entry in the table. For example, method OnKeyDown_Ctrl_Shift_B(self, event) maps Ctrl+Shift+B into a call to this method.

The EVT_KEY_DOWN event is bound a generic key event handler method. At run time, that handler determines the key and the state of the Alt, Ctrl, and Shift keys from the event object and simply calls the method for that key combination in the table.

A similar table is used for shortcuts in menus, except that the shortcut string from the menu item is mapped to a method.

Another, probably more important benefit is that basic user-level documentation can be generated from the table, automatically. In our case, we create a list with the key combination and doc string of the method and show that list in an HtmlWindow.

/Jean Brouwers
ProphICy Semiconductor, Inc.

Alex Panayotopoulos wrote:

···

On Wed, 5 Jan 2005, Alan Sheehan wrote:

Does anyone have pros and cons of wxPython in terms of keyboarding
ability ?
   
I've just been writing an application that uses a bunch of user-defined key presses (particularly CTRL+<key> ones), and I found wxPython really good for it. (As opposed to java+swing, which made me want to hurl my computer through a window).

I simply intercepted the 'EVT_KEY_DOWN' event (which provides handy methods to find out what modifier keys are down) and used a keycode-to-function dictionary to associate keys with methods.

  ctrl_presses = { ord('A') : self.SpawnNasalDemons,
                   ord('B') : self.HaltAndCatchFire, ... etc. }

No problem at all.

Mike C. Fletcher wrote:

Alan Sheehan wrote:
...

Does anyone have pros and cons of wxPython in terms of keyboarding ability ?

Generally speaking, wxPython is fine, however you'll find that some composite controls have counter-intuitive or even broken keyboard functionality (though it's been a while since I've played with wxPython, so that may have improved, calendar controls were the worst back in my day).

The have been improvements, but it's probably still not perfect.

wxoo has a composite control hierarchy which makes it easier to get around that when writing new controls, but that doesn't help you with already-written ones.

Getting the tab-ordering correct is a bit of a pain sometimes, but probably not more than in any other GUI kit which doesn't have explicit setting of orders (it's all implicitly done (unless you add in modules that support setting the tab-order, which is something I never did)).

wxWidgets now has the ability to change the tab order using the MoveAfterInTabOrder and MoveBeforeInTabOrder methods of wx.Window.

···

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