Enable: Adding letter keys to Key Map

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Enable: Adding letter keys to Key Map

Tony S Yu
I recently ran into some problems when trying to add a key listener to a chaco plot.

Currently, letters aren't defined in Enable's key map for the QT4 backend. Undefined keys end up getting set to the text value, but key modifiers (control, alt, shift,...) can alter the letter being pressed.

For, example, pressing the shift key and the letter "a" doesn't match

>>> KeySpec("a", "shift"),

but it would match

>>> KeySpec("A", "shift").

If this key combination matched KeySpec("A"), then I could see this behavior possibly being a feature, but it doesn't match. What's worse is that the option (alt) key on OS X modifies letters into special characters (i.e. the matching KeySpec would be uglier and not very portable).

Adding letters to the key map (see diff output below) fixes this issue. I assume the same issue arises with WX, but I don't have it working on my system, so I can't really check.

Best,
-Tony


Index: enthought/enable/qt4_backend/constants.py
===================================================================
--- enthought/enable/qt4_backend/constants.py (revision 25616)
+++ enthought/enable/qt4_backend/constants.py (working copy)
@@ -107,4 +107,30 @@
    Qt.Key_F22:  "F22",
    Qt.Key_F23:  "F23",
    Qt.Key_F24:  "F24",
+    Qt.Key_A:  "a",
+    Qt.Key_B:  "b",
+    Qt.Key_C:  "c",
+    Qt.Key_D:  "d",
+    Qt.Key_E:  "e",
+    Qt.Key_F:  "f",
+    Qt.Key_G:  "g",
+    Qt.Key_H:  "h",
+    Qt.Key_I:  "i",
+    Qt.Key_J:  "j",
+    Qt.Key_K:  "k",
+    Qt.Key_L:  "l",
+    Qt.Key_M:  "m",
+    Qt.Key_N:  "n",
+    Qt.Key_O:  "o",
+    Qt.Key_P:  "p",
+    Qt.Key_Q:  "q",
+    Qt.Key_R:  "r",
+    Qt.Key_S:  "s",
+    Qt.Key_T:  "t",
+    Qt.Key_U:  "u",
+    Qt.Key_V:  "v",
+    Qt.Key_W:  "w",
+    Qt.Key_X:  "x",
+    Qt.Key_Y:  "y",
+    Qt.Key_Z:  "z",
}

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Enable: Adding letter keys to Key Map

Peter Wang
Thanks, Tony!  I have committed your suggested patch, as r25644.

-Peter


On Tue, Jul 6, 2010 at 11:48 AM, Tony S Yu <[hidden email]> wrote:

> I recently ran into some problems when trying to add a key listener to a chaco plot.
>
> Currently, letters aren't defined in Enable's key map for the QT4 backend. Undefined keys end up getting set to the text value, but key modifiers (control, alt, shift,...) can alter the letter being pressed.
>
> For, example, pressing the shift key and the letter "a" doesn't match
>
>>>> KeySpec("a", "shift"),
>
> but it would match
>
>>>> KeySpec("A", "shift").
>
> If this key combination matched KeySpec("A"), then I could see this behavior possibly being a feature, but it doesn't match. What's worse is that the option (alt) key on OS X modifies letters into special characters (i.e. the matching KeySpec would be uglier and not very portable).
>
> Adding letters to the key map (see diff output below) fixes this issue. I assume the same issue arises with WX, but I don't have it working on my system, so I can't really check.
>
> Best,
> -Tony
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev