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) 2012-2013 NV Access Limited, Rui Batista
11 from logHandler import log
15 """Framework for handling braille input from the user.
16 All braille input is represented by a {BrailleInputGesture}.
17 Normally, all that is required is to create and execute a L{BrailleInputGesture},
18 as there are built-in gesture bindings for braille input.
21 #: The singleton BrailleInputHandler instance.
22 #: @type: L{BrailleInputHandler}
27 handler = BrailleInputHandler()
28 log.info("Braille input initialized")
34 class BrailleInputHandler(object):
35 """Handles braille input.
38 def input(self, dots):
39 """Handle one cell of braille input.
41 # liblouis requires us to set the highest bit for proper use of dotsIO.
42 char = unichr(dots | 0x8000)
43 text = louis.backTranslate(
44 [os.path.join(braille.TABLES_DIR, config.conf["braille"]["inputTable"]),
45 "braille-patterns.cti"],
46 char, mode=louis.dotsIO)
51 def sendChars(self, chars):
54 input = winUser.Input()
55 input.type = winUser.INPUT_KEYBOARD
56 input.ii.ki = winUser.KeyBdInput()
57 input.ii.ki.wScan = ord(ch)
58 input.ii.ki.dwFlags = winUser.KEYEVENTF_UNICODE
60 winUser.SendInput(inputs)
62 class BrailleInputGesture(inputCore.InputGesture):
63 """Input (dots and/or space bar) from a braille keyboard.
64 This could either be as part of a braille display or a stand-alone unit.
65 L{dots} and L{space} should be set appropriately.
68 #: Bitmask of pressed dots.
72 #: Whether the space bar is pressed.
76 def _get_identifiers(self):
77 if self.space and self.dots:
78 dotsString = "+".join("dot%d" % (i+1) for i in xrange(8) if self.dots & (1 << i))
79 return ("bk:space+%s" % dotsString,
81 elif self.dots or self.space:
86 def _get_displayName(self):
87 if not self.dots and not self.space:
89 # Translators: Reported before braille input in input help mode.
91 if self.space and self.dots:
92 # Translators: Reported when braille space is pressed with dots in input help mode.
93 out.append(_("space with dot"))
95 # Translators: Reported when braille dots are pressed in input help mode.
98 # Translators: Reported when braille space is pressed in input help mode.
99 out.append(_("space"))
101 for dot in xrange(8):
102 if self.dots & (1 << dot):
103 out.append(str(dot + 1))