OSDN Git Service

baum driver: Simplify key handling code. There should be no functional change.
authorJames Teh <jamie@jantrid.net>
Wed, 2 Feb 2011 03:34:44 +0000 (13:34 +1000)
committerJames Teh <jamie@jantrid.net>
Wed, 2 Feb 2011 03:34:44 +0000 (13:34 +1000)
source/brailleDisplayDrivers/baum.py

index d91e614..b4a5d9b 100644 (file)
@@ -199,26 +199,29 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
                return command, arg\r
 \r
        def _handleResponse(self, command, arg):\r
-               updateKeys = False\r
-               executeKeys = False\r
-\r
                if command == BAUM_CELL_COUNT:\r
                        self.numCells = ord(arg)\r
                elif command == BAUM_DEVICE_ID:\r
                        self._deviceID = arg\r
 \r
                elif command in KEY_NAMES:\r
-                       updateKeys = True\r
                        arg = sum(ord(byte) << offset * 8 for offset, byte in enumerate(arg))\r
                        if arg < self._keysDown.get(command, 0):\r
                                # Release.\r
                                if not self._ignoreKeyReleases:\r
                                        # The first key released executes the key combination.\r
-                                       executeKeys = True\r
+                                       try:\r
+                                               inputCore.manager.executeGesture(InputGesture(self._keysDown))\r
+                                       except inputCore.NoInputGestureAction:\r
+                                               pass\r
+                                       # Any further releases are just the rest of the keys in the combination being released,\r
+                                       # so they should be ignored.\r
+                                       self._ignoreKeyReleases = True\r
                        else:\r
                                # Press.\r
                                # This begins a new key combination.\r
                                self._ignoreKeyReleases = False\r
+                       self._keysDown[command] = arg\r
 \r
                elif command == BAUM_POWERDOWN:\r
                        log.debug("Power down")\r
@@ -228,19 +231,6 @@ class BrailleDisplayDriver(braille.BrailleDisplayDriver):
                else:\r
                        log.debugWarning("Unknown command {command!r}, arg {arg!r}".format(command=command, arg=arg))\r
 \r
-               if executeKeys:\r
-                       try:\r
-                               inputCore.manager.executeGesture(InputGesture(self._keysDown))\r
-                       except inputCore.NoInputGestureAction:\r
-                               pass\r
-                       # Any further releases are just the rest of the keys in the combination being released,\r
-                       # so they should be ignored.\r
-                       self._ignoreKeyReleases = True\r
-               if updateKeys:\r
-                       # We must update key state after execution instead of before because\r
-                       # execution needs to include the key that was just released.\r
-                       self._keysDown[command] = arg\r
-\r
        def display(self, cells):\r
                # cells will already be padded up to numCells.\r
                self._sendRequest(BAUM_DISPLAY_DATA, "".join(chr(cell) for cell in cells))\r