Ticket #209: handytech-gestures.diff

File handytech-gestures.diff, 4.2 KB (added by bramd, 17 months ago)

Improved patch, implemented code changes as suggested in ticket comments

  • contributors.txt

    === modified file 'contributors.txt'
     
    8282vrutti vyas <vruttivyas@yahoo.co.in> - hindi language files 
    8383Niko Carpenter <nik62591@gmail.com> - Small patches 
    8484<adikushnir@gmail.com> - hebrew language files 
     85Bram Duvigneau <bram@bramd.nl> - Updated Handy Tech braille driver======= 
     86 No newline at end of file 
  • source/brailleDisplayDrivers/handyTech.py

    === modified file 'source/brailleDisplayDrivers/handyTech.py'
     
    99import braille 
    1010from logHandler import log 
    1111import speech 
     12import inputCore 
     13import os 
     14from baseObject import ScriptableObject 
    1215 
    1316COM_CLASS = "HtBrailleDriverServer.HtBrailleDriver" 
     17HT_KEYS = {} 
     18 
    1419constants = None 
    1520 
    16 class Sink: 
     21class Sink(object): 
    1722 
    1823        def __init__(self, server): 
    1924                self.server = server 
     25                super(Sink, self).__init__() 
    2026 
    2127        def sayString(self, text): 
    2228                speech.speakMessage(text) 
     
    2531                # keys_arg is VARIANT. Indexing by 0 gives actual value. 
    2632                keys = keys_arg[0] 
    2733                if constants.KEY_ROUTING in keys: 
    28                         braille.handler.routeTo(routing_pos - 1) 
    29                 elif keys == (constants.KEY_UP,) or keys == (constants.KEY_LEFT,): 
    30                         braille.handler.scrollBack() 
    31                 elif keys == (constants.KEY_DOWN,) or keys == (constants.KEY_RIGHT,): 
    32                         braille.handler.scrollForward() 
    33                 elif keys == (constants.KEY_B4, constants.KEY_B8): 
    34                         self.server.startConfigDialog(False) 
     34                        gesture = InputGesture(keys, routing_pos -1) 
     35                else: 
     36                        gesture = InputGesture(keys) 
     37                try: 
     38                        inputCore.manager.executeGesture(gesture) 
     39                except inputCore.NoInputGestureAction: 
     40                        pass 
    3541 
    36 class BrailleDisplayDriver(braille.BrailleDisplayDriver): 
     42class BrailleDisplayDriver(braille.BrailleDisplayDriver, ScriptableObject): 
    3743        """Handy Tech braille display driver. 
    3844        """ 
    3945        name = "handyTech" 
     
    4854                        return False 
    4955 
    5056        def __init__(self): 
    51                 global constants 
     57                global constants, HT_KEYS 
    5258                super(BrailleDisplayDriver, self).__init__() 
    5359                self._server = comtypes.client.CreateObject(COM_CLASS) 
    5460                import comtypes.gen.HTBRAILLEDRIVERSERVERLib as constants 
     61                 
     62                HT_KEYS = {} 
     63                for key, constant in constants.__dict__.items(): 
     64                        if key.startswith('KEY_'): 
     65                                HT_KEYS[constant] = key[4:].lower().replace('_', '') 
     66 
    5567                # Keep the connection object so it won't become garbage 
    5668                self._advise = comtypes.client.GetEvents(self._server, Sink(self._server), constants.IHtBrailleDriverSink) 
    5769                self._server.initialize() 
     
    6577 
    6678        def display(self, cells): 
    6779                self._server.displayText(cells) 
     80         
     81        def script_showConfig(self, gesture): 
     82                self._server.startConfigDialog(False) 
     83        script_showConfig.__doc__ = _("Show the Handy Tech driver configuration window.") 
     84         
     85        gestureMap = inputCore.GlobalGestureMap({ 
     86                "globalCommands.GlobalCommands": { 
     87                        "braille_scrollBack": ("br(handytech):left", "br(handytech):up"), 
     88                        "braille_previousLine": ("br(handytech):b4",), 
     89                        "braille_nextLine": ("br(handytech):b5",), 
     90                        "braille_scrollForward": ("br(handytech):right", "br(handytech):down"), 
     91                        "braille_routeTo": ("br(handytech):routing",), 
     92                        "kb:shift+tab": ("br(handytech):esc",), 
     93                        "kb:alt": ("br(handytech):b2+b4+b5",), 
     94                        "kb:escape": ("br(handytech):b4+b6",), 
     95                        "kb:tab": ("br(handytech):enter",), 
     96                        "kb:enter": ("br(handytech):esc+enter",), 
     97                        "kb:upArrow": ("br(handytech):leftSpace",), 
     98                        "kb:downArrow": ("br(handytech):rightSpace",), 
     99                        "showGui": ("br(handytech):b2+b4+b5+b6",), 
     100                } 
     101        }) 
     102 
     103        __gestures = { 
     104                'br(handytech):b4+b8': 'showConfig', 
     105        } 
     106 
     107class InputGesture(braille.BrailleDisplayGesture): 
     108 
     109        source = BrailleDisplayDriver.name 
     110 
     111        def __init__(self, keys, routing_pos=None): 
     112                super(InputGesture, self).__init__() 
     113                self.keys = set(keys) 
     114 
     115                self.keyNames = names = set() 
     116                for key in self.keys: 
     117                        if key == constants.KEY_ROUTING: 
     118                                names.add("routing") 
     119                                self.routingIndex = routing_pos 
     120                        else: 
     121                                try: 
     122                                        names.add(HT_KEYS[key]) 
     123                                except KeyError: 
     124                                        log.debugWarning("Unknown key %d" % key) 
     125 
     126                self.id = "+".join(names)