Package brailleDisplayDrivers :: Module alvaBC6
[hide private]
[frames] | no frames]

Source Code for Module brailleDisplayDrivers.alvaBC6

  1  #brailleDisplayDrivers/alvaBC6.py 
  2  #A part of NonVisual Desktop Access (NVDA) 
  3  #This file is covered by the GNU General Public License. 
  4  #See the file COPYING for more details. 
  5  #Copyright (C) 2009-2011 Optelec B.V. <http://www.optelec.com/>, James Teh <jamie@jantrid.net> 
  6   
  7  import braille 
  8  import queueHandler 
  9  from logHandler import log 
 10  from ctypes import * 
 11  from ctypes.wintypes import * 
 12  import time 
 13  import config 
 14  import inputCore 
 15   
 16  ALVA_RELEASE_MASK = 0x8000 
 17   
 18  ALVA_KEYS = { 
 19          # Thumb keys (FRONT_GROUP) 
 20          0x71: ("t1", "t2", "t3", "t4", "t5", 
 21                  # Only for BC680 
 22                  "t1", "t2", "t3", "t4", "t5"), 
 23          # eTouch keys (ETOUCH_GROUP) 
 24          0x72: ("etouch1", "etouch2", "etouch3", "etouch4"), 
 25          # Smartpad keys (PDA_GROUP) 
 26          0x73: ("sp1", "sp2", "spLeft", "spEnter", "spUp", "spDown", "spRight", "sp3", "sp4", 
 27                  # Only for BC680 
 28                  "sp1", "sp2", "spLeft", "spEnter", "spUp", "spDown", "spRight", "sp3", "sp4") 
 29  } 
 30  ALVA_CR_GROUP = 0x74 
 31  ALVA_MODIFIER_GROUP = 0x75 
 32  ALVA_ASCII_GROUP = 0x76 
 33   
 34  ALVA_PKEYCALLBACK = CFUNCTYPE(BOOL, c_int, USHORT, c_void_p) 
 35   
 36  #Try to load alvaw32.dll 
 37  try: 
 38          AlvaLib=windll[r"brailleDisplayDrivers\alvaw32.dll"] 
 39  except: 
 40          AlvaLib=None 
41 42 -class BrailleDisplayDriver(braille.BrailleDisplayDriver):
43 name = "alvaBC6" 44 description = _("ALVA BC640/680 series") 45 46 @classmethod
47 - def check(cls):
48 return bool(AlvaLib)
49
50 - def __init__(self):
51 super(BrailleDisplayDriver,self).__init__() 52 log.debug("ALVA BC6xx Braille init") 53 _AlvaNumDevices=c_int(0) 54 AlvaLib.AlvaScanDevices(byref(_AlvaNumDevices)) 55 if _AlvaNumDevices.value==0: 56 raise RuntimeError("No ALVA display found") 57 log.debug("%d devices found" %_AlvaNumDevices.value) 58 AlvaLib.AlvaOpen(0) 59 self._alva_NumCells = 0 60 self._keysDown = set() 61 self._ignoreKeyReleases = False 62 self._keyCallbackInst = ALVA_PKEYCALLBACK(self._keyCallback) 63 AlvaLib.AlvaSetKeyCallback(0, self._keyCallbackInst, None)
64
65 - def terminate(self):
66 super(BrailleDisplayDriver, self).terminate() 67 AlvaLib.AlvaClose(1) 68 # Drop the ctypes function instance for the key callback, 69 # as it is holding a reference to an instance method, which causes a reference cycle. 70 self._keyCallbackInst = None
71
72 - def _get_numCells(self):
73 if self._alva_NumCells==0: 74 NumCells = c_int(0) 75 AlvaLib.AlvaGetCells(0, byref(NumCells)) 76 if NumCells.value==0: 77 raise RuntimeError("Cannot obtain number of cells") 78 self._alva_NumCells = NumCells.value 79 log.info("ALVA BC6xx has %d cells" %self._alva_NumCells) 80 return self._alva_NumCells
81
82 - def display(self, cells):
83 cells="".join([chr(x) for x in cells]) 84 AlvaLib.AlvaSendBraille(0, cells, 0, len(cells))
85
86 - def _keyCallback(self, dev, key, userData):
87 group = (key >> 8) & 0x7F 88 number = key & 0xFF 89 if key & ALVA_RELEASE_MASK: 90 # Release. 91 if not self._ignoreKeyReleases and self._keysDown: 92 try: 93 inputCore.manager.executeGesture(InputGesture(self._keysDown)) 94 except inputCore.NoInputGestureAction: 95 pass 96 # Any further releases are just the rest of the keys in the combination being released, 97 # so they should be ignored. 98 self._ignoreKeyReleases = True 99 self._keysDown.discard((group, number)) 100 else: 101 # Press. 102 if group == ALVA_CR_GROUP: 103 # Execute routing keys when pressed instead of released. 104 try: 105 inputCore.manager.executeGesture(InputGesture(((group, number),))) 106 except inputCore.NoInputGestureAction: 107 pass 108 else: 109 self._keysDown.add((group, number)) 110 # This begins a new key combination. 111 self._ignoreKeyReleases = False 112 return False
113 114 gestureMap = inputCore.GlobalGestureMap({ 115 "globalCommands.GlobalCommands": { 116 "braille_scrollBack": ("br(alvaBC6):t1",), 117 "braille_previousLine": ("br(alvaBC6):t2",), 118 "braille_nextLine": ("br(alvaBC6):t4",), 119 "braille_scrollForward": ("br(alvaBC6):t5",), 120 "braille_routeTo": ("br(alvaBC6):routing",), 121 "kb:shift+tab": ("br(alvaBC6):sp1",), 122 "kb:alt": ("br(alvaBC6):sp2",), 123 "kb:escape": ("br(alvaBC6):sp3",), 124 "kb:tab": ("br(alvaBC6):sp4",), 125 "kb:upArrow": ("br(alvaBC6):spUp",), 126 "kb:downArrow": ("br(alvaBC6):spDown",), 127 "kb:leftArrow": ("br(alvaBC6):spLeft",), 128 "kb:rightArrow": ("br(alvaBC6):spRight",), 129 "kb:enter": ("br(alvaBC6):spEnter",), 130 "showGui": ("br(alvaBC6):sp1+sp3",), 131 "kb:windows+d": ("br(alvaBC6):sp1+sp4",), 132 "kb:windows": ("br(alvaBC6):sp2+sp3",), 133 "kb:alt+tab": ("br(alvaBC6):sp2+sp4",), 134 } 135 })
136
137 -class InputGesture(braille.BrailleDisplayGesture):
138 139 source = BrailleDisplayDriver.name 140
141 - def __init__(self, keys):
142 super(InputGesture, self).__init__() 143 self.keyCodes = set(keys) 144 145 self.keyNames = names = set() 146 for group, number in self.keyCodes: 147 if group == ALVA_CR_GROUP: 148 names.add("routing") 149 self.routingIndex = number 150 else: 151 try: 152 names.add(ALVA_KEYS[group][number]) 153 except (KeyError, IndexError): 154 log.debugWarning("Unknown key with group %d and number %d" % (group, number)) 155 156 self.id = "+".join(names)
157