~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/brailleDisplayDrivers/brltty.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/brltty.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-2010 James Teh <jamie@jantrid.net>
6
6
 
7
7
import time
8
8
import wx
9
9
import braille
10
10
from logHandler import log
 
11
import inputCore
11
12
try:
12
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_"))
13
16
except ImportError:
14
17
        pass
15
18
 
16
19
KEY_CHECK_INTERVAL = 50
17
20
 
18
 
class BrailleDisplayDriver(braille.BrailleDisplayDriverWithCursor):
 
21
class BrailleDisplayDriver(braille.BrailleDisplayDriver):
19
22
        """brltty braille display driver.
20
23
        """
21
24
        name = "brltty"
58
61
        def _get_numCells(self):
59
62
                return self._con.displaySize[0]
60
63
 
61
 
        def _display(self, cells):
 
64
        def display(self, cells):
62
65
                cells = "".join(chr(cell) for cell in cells)
63
66
                # HACK: Temporarily work around a bug which causes brltty to freeze if data is written while there are key presses waiting.
64
67
                # Simply consume and act upon any waiting key presses.
81
84
                keyType = key["type"]
82
85
                command = key["command"]
83
86
                argument = key["argument"]
84
 
                try:
85
 
                        if keyType == brlapi.KEY_TYPE_CMD:
86
 
                                if command == brlapi.KEY_CMD_FWINLT:
87
 
                                        braille.handler.scrollBack()
88
 
                                elif command == brlapi.KEY_CMD_FWINRT:
89
 
                                        braille.handler.scrollForward()
90
 
                                elif command == brlapi.KEY_CMD_ROUTE:
91
 
                                        braille.handler.routeTo(argument)
92
 
                except:
93
 
                        log.error("Error executing key press action", exc_info=True)
 
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
 
 
103
class InputGesture(braille.BrailleDisplayGesture):
 
104
 
 
105
        source = BrailleDisplayDriver.name
 
106
 
 
107
        def __init__(self, command, argument):
 
108
                super(InputGesture, self).__init__()
 
109
                self.id = BRLAPI_CMD_KEYS[command]
 
110
                if command == brlapi.KEY_CMD_ROUTE:
 
111
                        self.routingIndex = argument