| Trees | Indices | Help |
|---|
|
|
1 #brailleDisplayDrivers/brltty.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-2010 James Teh <jamie@jantrid.net>
6
7 import time
8 import wx
9 import braille
10 from logHandler import log
11 import inputCore
12 try:
13 import brlapi
14 BRLAPI_CMD_KEYS = dict((code, name[8:].lower())
15 for name, code in brlapi.__dict__.iteritems() if name.startswith("KEY_CMD_"))
16 except ImportError:
17 pass
18
19 KEY_CHECK_INTERVAL = 50
22 """brltty braille display driver.
23 """
24 name = "brltty"
25 description = "brltty"
26
27 @classmethod
35
37 super(BrailleDisplayDriver, self).__init__()
38 self._con = brlapi.Connection()
39 self._con.enterTtyModeWithPath()
40 self._keyCheckTimer = wx.PyTimer(self._handleKeyPresses)
41 self._keyCheckTimer.Start(KEY_CHECK_INTERVAL)
42 # BRLTTY simulates key presses for braille typing keys, so let BRLTTY handle them.
43 # NVDA may eventually implement this itself, but there's no reason to deny BRLTTY users this functionality in the meantime.
44 self._con.ignoreKeys(brlapi.rangeType_type, (long(brlapi.KEY_TYPE_SYM),))
45
47 super(BrailleDisplayDriver, self).terminate()
48 # Exceptions might be raised if initialisation failed. Just ignore them.
49 try:
50 self._keyCheckTimer.Stop()
51 self._keyCheckTimer = None
52 except:
53 pass
54 try:
55 # Give BRLTTY a chance to write the last piece of data to the display.
56 time.sleep(0.05)
57 self._con.leaveTtyMode()
58 except:
59 pass
60
63
65 cells = "".join(chr(cell) for cell in cells)
66 # HACK: Temporarily work around a bug which causes brltty to freeze if data is written while there are key presses waiting.
67 # Simply consume and act upon any waiting key presses.
68 self._handleKeyPresses()
69 self._con.writeDots(cells)
70
72 while True:
73 try:
74 key = self._con.readKey(False)
75 except:
76 log.error("Error reading key press from brlapi", exc_info=True)
77 return
78 if not key:
79 break
80 key = self._con.expandKeyCode(key)
81 self._onKeyPress(key)
82
84 keyType = key["type"]
85 command = key["command"]
86 argument = key["argument"]
87 if keyType == brlapi.KEY_TYPE_CMD:
88 try:
89 inputCore.manager.executeGesture(InputGesture(command, argument))
90 except inputCore.NoInputGestureAction:
91 pass
92
93 gestureMap = inputCore.GlobalGestureMap({
94 "globalCommands.GlobalCommands": {
95 "braille_scrollBack": ("br(brltty):fwinlt",),
96 "braille_scrollForward": ("br(brltty):fwinrt",),
97 "braille_previousLine": ("br(brltty):lnup",),
98 "braille_nextLine": ("br(brltty):lndn",),
99 "braille_routeTo": ("br(brltty):route",),
100 }
101 })
102
104
105 source = BrailleDisplayDriver.name
106
108 super(InputGesture, self).__init__()
109 self.id = BRLAPI_CMD_KEYS[command]
110 if command == brlapi.KEY_CMD_ROUTE:
111 self.routingIndex = argument
112
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Nov 18 17:46:03 2011 | http://epydoc.sourceforge.net |