~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/brailleDisplayDrivers/freedomScientific.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
6
6
 
7
7
from ctypes import *
8
8
from ctypes.wintypes import *
 
9
import itertools
 
10
import hwPortUtils
9
11
import braille
10
 
import queueHandler
 
12
import inputCore
 
13
from baseObject import ScriptableObject
 
14
from winUser import WNDCLASSEXW, WNDPROC, LRESULT, HCURSOR
11
15
 
12
16
#Try to load the fs braille dll
13
17
try:
28
32
LRESULT=c_long
29
33
HCURSOR=c_long
30
34
 
31
 
#Standard window class stuff
32
 
 
33
 
WNDPROC=WINFUNCTYPE(LRESULT,HWND,c_uint,WPARAM,LPARAM)
34
 
 
35
 
class WNDCLASSEXW(Structure):
36
 
        _fields_=[
37
 
                ('cbSize',c_uint),
38
 
                ('style',c_uint),
39
 
                ('lpfnWndProc',WNDPROC),
40
 
                ('cbClsExtra',c_int),
41
 
                ('cbWndExtra',c_int),
42
 
                ('hInstance',HINSTANCE),
43
 
                ('hIcon',HICON),
44
 
                ('HCURSOR',HCURSOR),
45
 
                ('hbrBackground',HBRUSH),
46
 
                ('lpszMenuName',LPWSTR),
47
 
                ('lpszClassName',LPWSTR),
48
 
                ('hIconSm',HICON),
49
 
        ]
50
 
 
51
35
appInstance=windll.kernel32.GetModuleHandleW(None)
52
36
 
53
37
nvdaFsBrlWm=windll.user32.RegisterWindowMessageW(u"nvdaFsBrlWm")
54
38
 
 
39
inputType_keys=3
 
40
inputType_routing=4
 
41
inputType_wizWheel=5
 
42
 
55
43
@WNDPROC
56
44
def nvdaFsBrlWndProc(hwnd,msg,wParam,lParam):
57
45
        if msg==nvdaFsBrlWm and wParam==FB_INPUT:
58
 
                a=lParam&0xFF
59
 
                b=(lParam>>8)&0xFF
60
 
                c=(lParam>>16)&0xff
61
 
                d=(lParam>>24)&0xFF
62
 
                if a==5: #wizzwheels
63
 
                        if bool((b>>3)&1) is bool((b>>4)&1):
64
 
                                queueHandler.queueFunction(queueHandler.eventQueue,braille.handler.scrollBack)
65
 
                        else:
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)
 
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
69
77
                return 0
70
 
        return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
 
78
        else:
 
79
                return windll.user32.DefWindowProcW(hwnd,msg,wParam,lParam)
71
80
 
72
81
nvdaFsBrlWndCls=WNDCLASSEXW()
73
82
nvdaFsBrlWndCls.cbSize=sizeof(nvdaFsBrlWndCls)
75
84
nvdaFsBrlWndCls.hInstance=appInstance
76
85
nvdaFsBrlWndCls.lpszClassName=u"nvdaFsBrlWndCls"
77
86
 
78
 
class BrailleDisplayDriver(braille.BrailleDisplayDriverWithCursor):
 
87
class BrailleDisplayDriver(braille.BrailleDisplayDriver,ScriptableObject):
79
88
 
80
89
        name="freedomScientific"
81
 
        description="Freedom Scientific Focus / Pacmate series"
 
90
        description=_("Freedom Scientific Focus/PAC Mate series")
82
91
 
83
92
        @classmethod
84
93
        def check(cls):
85
94
                return bool(fsbLib)
86
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
 
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)
91
115
                fbHandle=-1
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")
 
119
                ):
93
120
                        fbHandle=fbOpen(port,self._messageWindow,nvdaFsBrlWm)
94
121
                        if fbHandle!=-1:
95
122
                                break
106
133
        def _get_numCells(self):
107
134
                return fbGetCellCount(self.fbHandle)
108
135
 
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)
 
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__()