OSDN Git Service

Normalise gesture identifiers in the process of binding them so that they match other...
authorJames Teh <jamie@jantrid.net>
Wed, 6 Oct 2010 08:04:01 +0000 (18:04 +1000)
committerJames Teh <jamie@jantrid.net>
Wed, 6 Oct 2010 08:04:01 +0000 (18:04 +1000)
This is necessary because the order of the modifiers in a keyboard gesture (e.g. control+shift+alt) doesn't matter as far as the user is concerned, but NVDA needs them to be in a determinate order so they match other identifiers.
Currently, this is implemented in inputCore.normalizeGestureIdentifier(). This also converts the string to lower case, which used ot be done in ScriptableObject.bindGesture().
This may need to be made specific to the type of gesture in future; e.g. braille gesture identifiers might need different normalisation. However, this can be done later if necessary.

source/baseObject.py
source/inputCore.py

index d0abe1b..8ac08e9 100755 (executable)
@@ -8,7 +8,7 @@
 """\r
 \r
 import weakref\r
-from keyUtils import key\r
+import inputCore\r
 from logHandler import log\r
 \r
 class Getter(object):\r
@@ -148,7 +148,7 @@ class ScriptableObject(AutoPropertyObject):
                func = getattr(self, "script_%s" % scriptName, None)\r
                if not func:\r
                        raise LookupError("No such script: %s" % func)\r
-               self._gestureMap[gestureIdentifier.lower()] = func\r
+               self._gestureMap[inputCore.normalizeGestureIdentifier(gestureIdentifier)] = func\r
 \r
        def bindGestures(self, gestureMap):\r
                """Bind multiple input gestures to scripts.\r
index e800cfc..75c20d3 100644 (file)
@@ -4,6 +4,7 @@
 #See the file COPYING for more details.\r
 #Copyright (C) 2010 James Teh <jamie@jantrid.net>\r
 \r
+import itertools\r
 import baseObject\r
 import scriptHandler\r
 import queueHandler\r
@@ -156,3 +157,14 @@ class InputManager(baseObject.AutoPropertyObject):
 #: The singleton input manager instance.\r
 #: @type: L{InputManager}\r
 manager = InputManager()\r
+\r
+def normalizeGestureIdentifier(identifier):\r
+       """Normalize a gesture identifier so that it matches other identifiers for the same gesture.\r
+       """\r
+       prefix, main = identifier.split(":", 1)\r
+       main = main.split("+")\r
+       # The order of all parts except the last doesn't matter as far as the user is concerned,\r
+       # but we need them to be in a determinate order so they will match other gesture identifiers.\r
+       # Rather than sorting, just use Python's set ordering.\r
+       main = "+".join(itertools.chain(frozenset(main[:-1]), main[-1:]))\r
+       return "{1}:{2}".format(prefix, main).lower()\r