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

Source Code for Module brailleDisplayDrivers.freedomScientific

  1  #brailleDisplayDrivers/freedomScientific.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) 2008-2011 Michael Curran <mick@kulgan.net>, James Teh <jamie@jantrid.net> 
  6   
  7  from ctypes import * 
  8  from ctypes.wintypes import * 
  9  import itertools 
 10  import hwPortUtils 
 11  import braille 
 12  import inputCore 
 13  from baseObject import ScriptableObject 
 14  from winUser import WNDCLASSEXW, WNDPROC, LRESULT, HCURSOR 
 15   
 16  #Try to load the fs braille dll 
 17  try: 
 18          fsbLib=windll.fsbrldspapi 
 19  except: 
 20          fsbLib=None 
 21   
 22  #Map the needed functions in the fs braille dll 
 23  if fsbLib: 
 24          fbOpen=getattr(fsbLib,'_fbOpen@12') 
 25          fbGetCellCount=getattr(fsbLib,'_fbGetCellCount@4') 
 26          fbWrite=getattr(fsbLib,'_fbWrite@16') 
 27          fbClose=getattr(fsbLib,'_fbClose@4') 
 28   
 29  FB_INPUT=1 
 30  FB_DISCONNECT=2 
 31   
 32  LRESULT=c_long 
 33  HCURSOR=c_long 
 34   
 35  appInstance=windll.kernel32.GetModuleHandleW(None) 
 36   
 37  nvdaFsBrlWm=windll.user32.RegisterWindowMessageW(u"nvdaFsBrlWm") 
 38   
 39  inputType_keys=3 
 40  inputType_routing=4 
 41  inputType_wizWheel=5 
42 43 @WNDPROC 44 -def nvdaFsBrlWndProc(hwnd,msg,wParam,lParam):
45 if msg==nvdaFsBrlWm and wParam==FB_INPUT: 46 inputType=lParam&0xff 47 if inputType==inputType_keys: 48 keyBits=lParam>>8 49 if keyBits: 50 gesture=KeyGesture(keyBits) 51 try: 52 inputCore.manager.executeGesture(gesture) 53 except inputCore.NoInputGestureAction: 54 pass 55 elif inputType==inputType_routing: 56 routingIndex=(lParam>>8)&0xff 57 isRoutingPressed=bool((lParam>>16)&0xff) 58 isTopRoutingRow=bool((lParam>>24)&0xff) 59 if isRoutingPressed: 60 gesture=RoutingGesture(routingIndex,isTopRoutingRow) 61 try: 62 inputCore.manager.executeGesture(gesture) 63 except inputCore.NoInputGestureAction: 64 pass 65 elif inputType==inputType_wizWheel: 66 numUnits=(lParam>>8)&0x7 67 isRight=bool((lParam>>12)&1) 68 isDown=bool((lParam>>11)&1) 69 #Right's up and down are rversed, but NVDA does not want this 70 if isRight: isDown=not isDown 71 for unit in xrange(numUnits): 72 gesture=WizWheelGesture(isDown,isRight) 73 try: 74 inputCore.manager.executeGesture(gesture) 75 except inputCore.NoInputGestureAction: 76 pass 77 return 0 78 else: 79 return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
80 81 nvdaFsBrlWndCls=WNDCLASSEXW() 82 nvdaFsBrlWndCls.cbSize=sizeof(nvdaFsBrlWndCls) 83 nvdaFsBrlWndCls.lpfnWndProc=nvdaFsBrlWndProc 84 nvdaFsBrlWndCls.hInstance=appInstance 85 nvdaFsBrlWndCls.lpszClassName=u"nvdaFsBrlWndCls"
86 87 -class BrailleDisplayDriver(braille.BrailleDisplayDriver,ScriptableObject):
88 89 name="freedomScientific" 90 description=_("Freedom Scientific Focus/PAC Mate series") 91 92 @classmethod
93 - def check(cls):
94 return bool(fsbLib)
95 96 wizWheelActions=[ 97 (_("display scroll"),("globalCommands","GlobalCommands","braille_scrollBack"),("globalCommands","GlobalCommands","braille_scrollForward")), 98 (_("line scroll"),("globalCommands","GlobalCommands","braille_previousLine"),("globalCommands","GlobalCommands","braille_nextLine")), 99 ] 100
101 - def __init__(self):
102 self.gestureMap=inputCore.GlobalGestureMap() 103 self.gestureMap.add("br(freedomScientific):routing","globalCommands","GlobalCommands","braille_routeTo") 104 self.leftWizWheelActionCycle=itertools.cycle(self.wizWheelActions) 105 action=self.leftWizWheelActionCycle.next() 106 self.gestureMap.add("br(freedomScientific):leftWizWheelUp",*action[1]) 107 self.gestureMap.add("br(freedomScientific):leftWizWheelDown",*action[2]) 108 self.rightWizWheelActionCycle=itertools.cycle(self.wizWheelActions) 109 action=self.rightWizWheelActionCycle.next() 110 self.gestureMap.add("br(freedomScientific):rightWizWheelUp",*action[1]) 111 self.gestureMap.add("br(freedomScientific):rightWizWheelDown",*action[2]) 112 super(BrailleDisplayDriver,self).__init__() 113 self._messageWindowClassAtom=windll.user32.RegisterClassExW(byref(nvdaFsBrlWndCls)) 114 self._messageWindow=windll.user32.CreateWindowExW(0,self._messageWindowClassAtom,u"nvdaFsBrlWndCls window",0,0,0,0,0,None,None,appInstance,None) 115 fbHandle=-1 116 for port in itertools.chain(("USB",), 117 (portInfo["port"].encode("mbcs") for portInfo in hwPortUtils.listComPorts(onlyAvailable=True) 118 if portInfo.get("bluetoothName") == "Focus 40 BT") 119 ): 120 fbHandle=fbOpen(port,self._messageWindow,nvdaFsBrlWm) 121 if fbHandle!=-1: 122 break 123 if fbHandle==-1: 124 raise RuntimeError("No display found") 125 self.fbHandle=fbHandle
126
127 - def terminate(self):
128 super(BrailleDisplayDriver,self).terminate() 129 fbClose(self.fbHandle) 130 windll.user32.DestroyWindow(self._messageWindow) 131 windll.user32.UnregisterClassW(self._messageWindowClassAtom,appInstance)
132
133 - def _get_numCells(self):
134 return fbGetCellCount(self.fbHandle)
135
136 - def display(self,cells):
137 cells="".join([chr(x) for x in cells]) 138 fbWrite(self.fbHandle,0,len(cells),cells)
139
140 - def script_toggleLeftWizWheelAction(self,gesture):
141 action=self.leftWizWheelActionCycle.next() 142 self.gestureMap.add("br(freedomScientific):leftWizWheelUp",*action[1],replace=True) 143 self.gestureMap.add("br(freedomScientific):leftWizWheelDown",*action[2],replace=True) 144 braille.handler.message(action[0])
145
146 - def script_toggleRightWizWheelAction(self,gesture):
147 action=self.rightWizWheelActionCycle.next() 148 self.gestureMap.add("br(freedomScientific):rightWizWheelUp",*action[1],replace=True) 149 self.gestureMap.add("br(freedomScientific):rightWizWheelDown",*action[2],replace=True) 150 braille.handler.message(action[0])
151 152 __gestures={ 153 "br(freedomScientific):leftWizWheelPress":"toggleLeftWizWheelAction", 154 "br(freedomScientific):rightWizWheelPress":"toggleRightWizWheelAction", 155 }
156
157 -class InputGesture(braille.BrailleDisplayGesture):
158 source = BrailleDisplayDriver.name
159
160 -class KeyGesture(InputGesture):
161 162 keyLabels=[ 163 #Braille keys (byte 1) 164 'dot1','dot2','dot3','dot4','dot5','dot6','dot7','dot8', 165 #Assorted keys (byte 2) 166 'leftWizWheelPress','rightWizWheelPress', 167 'leftShiftKey','rightShiftKey', 168 'leftAdvanceBar','rightAdvanceBar', 169 None, 170 'brailleSpaceBar', 171 #GDF keys (byte 3) 172 'leftGDFButton','rightGDFButton', 173 None, 174 'leftBumperBarUp','leftBumperBarDown','rightBumperBarUp','rightBumperBarDown', 175 ] 176
177 - def __init__(self,keyBits):
178 self.id="+".join(set(self.keyLabels[num] for num in xrange(24) if (keyBits>>num)&1)) 179 super(KeyGesture,self).__init__()
180
181 -class RoutingGesture(InputGesture):
182
183 - def __init__(self,routingIndex,topRow=False):
184 if topRow: 185 self.id="topRouting%d"%(routingIndex+1) 186 else: 187 self.id="routing" 188 self.routingIndex=routingIndex 189 super(RoutingGesture,self).__init__()
190
191 -class WizWheelGesture(InputGesture):
192
193 - def __init__(self,isDown,isRight):
194 which="right" if isRight else "left" 195 direction="Down" if isDown else "Up" 196 self.id="%sWizWheel%s"%(which,direction) 197 super(WizWheelGesture,self).__init__()
198