1
1
#brailleDisplayDrivers/freedomScientific.py
2
2
#A part of NonVisual Desktop Access (NVDA)
3
#Copyright (C) 2006-2009 NVDA Contributors <http://www.nvda-project.org/>
4
3
#This file is covered by the GNU General Public License.
5
4
#See the file COPYING for more details.
5
#Copyright (C) 2008-2011 Michael Curran <mick@kulgan.net>, James Teh <jamie@jantrid.net>
8
8
from ctypes.wintypes import *
13
from baseObject import ScriptableObject
14
from winUser import WNDCLASSEXW, WNDPROC, LRESULT, HCURSOR
12
16
#Try to load the fs braille dll
31
#Standard window class stuff
33
WNDPROC=WINFUNCTYPE(LRESULT,HWND,c_uint,WPARAM,LPARAM)
35
class WNDCLASSEXW(Structure):
39
('lpfnWndProc',WNDPROC),
42
('hInstance',HINSTANCE),
45
('hbrBackground',HBRUSH),
46
('lpszMenuName',LPWSTR),
47
('lpszClassName',LPWSTR),
51
35
appInstance=windll.kernel32.GetModuleHandleW(None)
53
37
nvdaFsBrlWm=windll.user32.RegisterWindowMessageW(u"nvdaFsBrlWm")
56
44
def nvdaFsBrlWndProc(hwnd,msg,wParam,lParam):
57
45
if msg==nvdaFsBrlWm and wParam==FB_INPUT:
63
if bool((b>>3)&1) is bool((b>>4)&1):
64
queueHandler.queueFunction(queueHandler.eventQueue,braille.handler.scrollBack)
66
queueHandler.queueFunction(queueHandler.eventQueue,braille.handler.scrollForward)
67
elif a==4 and c==1 and d==0: #press down bottom row routing key
68
queueHandler.queueFunction(queueHandler.eventQueue,braille.handler.routeTo,b)
47
if inputType==inputType_keys:
50
gesture=KeyGesture(keyBits)
52
inputCore.manager.executeGesture(gesture)
53
except inputCore.NoInputGestureAction:
55
elif inputType==inputType_routing:
56
routingIndex=(lParam>>8)&0xff
57
isRoutingPressed=bool((lParam>>16)&0xff)
58
isTopRoutingRow=bool((lParam>>24)&0xff)
60
gesture=RoutingGesture(routingIndex,isTopRoutingRow)
62
inputCore.manager.executeGesture(gesture)
63
except inputCore.NoInputGestureAction:
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)
74
inputCore.manager.executeGesture(gesture)
75
except inputCore.NoInputGestureAction:
70
return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
79
return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
72
81
nvdaFsBrlWndCls=WNDCLASSEXW()
73
82
nvdaFsBrlWndCls.cbSize=sizeof(nvdaFsBrlWndCls)
75
84
nvdaFsBrlWndCls.hInstance=appInstance
76
85
nvdaFsBrlWndCls.lpszClassName=u"nvdaFsBrlWndCls"
78
class BrailleDisplayDriver(braille.BrailleDisplayDriverWithCursor):
87
class BrailleDisplayDriver(braille.BrailleDisplayDriver,ScriptableObject):
80
89
name="freedomScientific"
81
description="Freedom Scientific Focus / Pacmate series"
90
description=_("Freedom Scientific Focus/PAC Mate series")
85
94
return bool(fsbLib)
97
(_("display scroll"),("globalCommands","GlobalCommands","braille_scrollBack"),("globalCommands","GlobalCommands","braille_scrollForward")),
98
(_("line scroll"),("globalCommands","GlobalCommands","braille_previousLine"),("globalCommands","GlobalCommands","braille_nextLine")),
87
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])
88
112
super(BrailleDisplayDriver,self).__init__()
89
113
self._messageWindowClassAtom=windll.user32.RegisterClassExW(byref(nvdaFsBrlWndCls))
90
114
self._messageWindow=windll.user32.CreateWindowExW(0,self._messageWindowClassAtom,u"nvdaFsBrlWndCls window",0,0,0,0,0,None,None,appInstance,None)
92
for port in ("usb","serial"):
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")
93
120
fbHandle=fbOpen(port,self._messageWindow,nvdaFsBrlWm)
106
133
def _get_numCells(self):
107
134
return fbGetCellCount(self.fbHandle)
109
def _display(self,cells):
136
def display(self,cells):
110
137
cells="".join([chr(x) for x in cells])
111
138
fbWrite(self.fbHandle,0,len(cells),cells)
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])
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])
153
"br(freedomScientific):leftWizWheelPress":"toggleLeftWizWheelAction",
154
"br(freedomScientific):rightWizWheelPress":"toggleRightWizWheelAction",
157
class InputGesture(braille.BrailleDisplayGesture):
158
source = BrailleDisplayDriver.name
160
class KeyGesture(InputGesture):
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',
172
'leftGDFButton','rightGDFButton',
174
'leftBumperBarUp','leftBumperBarDown','rightBumperBarUp','rightBumperBarDown',
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__()
181
class RoutingGesture(InputGesture):
183
def __init__(self,routingIndex,topRow=False):
185
self.id="topRouting%d"%(routingIndex+1)
188
self.routingIndex=routingIndex
189
super(RoutingGesture,self).__init__()
191
class WizWheelGesture(InputGesture):
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__()