Ticket #209: handytech-gestures.diff
| File handytech-gestures.diff, 4.2 KB (added by bramd, 17 months ago) |
|---|
-
contributors.txt
=== modified file 'contributors.txt'
82 82 vrutti vyas <vruttivyas@yahoo.co.in> - hindi language files 83 83 Niko Carpenter <nik62591@gmail.com> - Small patches 84 84 <adikushnir@gmail.com> - hebrew language files 85 Bram 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'
9 9 import braille 10 10 from logHandler import log 11 11 import speech 12 import inputCore 13 import os 14 from baseObject import ScriptableObject 12 15 13 16 COM_CLASS = "HtBrailleDriverServer.HtBrailleDriver" 17 HT_KEYS = {} 18 14 19 constants = None 15 20 16 class Sink :21 class Sink(object): 17 22 18 23 def __init__(self, server): 19 24 self.server = server 25 super(Sink, self).__init__() 20 26 21 27 def sayString(self, text): 22 28 speech.speakMessage(text) … … 25 31 # keys_arg is VARIANT. Indexing by 0 gives actual value. 26 32 keys = keys_arg[0] 27 33 if constants.KEY_ROUTING in keys: 28 braille.handler.routeTo(routing_pos -1)29 el if 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 e lif 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 35 41 36 class BrailleDisplayDriver(braille.BrailleDisplayDriver ):42 class BrailleDisplayDriver(braille.BrailleDisplayDriver, ScriptableObject): 37 43 """Handy Tech braille display driver. 38 44 """ 39 45 name = "handyTech" … … 48 54 return False 49 55 50 56 def __init__(self): 51 global constants 57 global constants, HT_KEYS 52 58 super(BrailleDisplayDriver, self).__init__() 53 59 self._server = comtypes.client.CreateObject(COM_CLASS) 54 60 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 55 67 # Keep the connection object so it won't become garbage 56 68 self._advise = comtypes.client.GetEvents(self._server, Sink(self._server), constants.IHtBrailleDriverSink) 57 69 self._server.initialize() … … 65 77 66 78 def display(self, cells): 67 79 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 107 class 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)

