def getTableOverview(tbl = ''): """ Return an overview of a input braille table. :param tbl: the braille table to use (default: the current input braille table). :type tbl: str :return: an overview of braille table in the form of a textual table :rtype: str """ t = "" tmp = {} available = "" i = 0x2800 while i<0x2800+256: text = louis.backTranslate([osp.join(r"louis\tables", config.conf["braille"]["inputTable"]), "braille-patterns.cti"], unichr(i), mode=louis.ucBrl) if i != 0x2800: t = 'Input Output\n' if not re.match(r'^\\.+/$', text[0]): tmp['%s' % text[0] if text[0] != '' else '?'] = '%s %-7s' % ( '%s (%s)' % (unichr(i), combinationDesign(unicodeBrailleToDescription(unichr(i)))), '%s%-8s' % (text[0], '%s' % (' (%-10s)' % str(hex(ord(text[0]))) if len(text[0]) == 1 else '' if text[0] != '' else '#ERROR')) ) else: available += unichr(i) i += 1 t += '\n'.join(tmp[k] for k in sorted(tmp)) nbAvailable = len(available) if nbAvailable>1: t += '\n'+_("Available combinations")+" (%d): %s" % (nbAvailable, available) elif nbAvailable == 1: t += '\n'+_("One combination available")+": %s" % available return t
def _translate(self, endWord): """Translate buffered braille up to the cursor. Any text produced is sent to the system. @param endWord: C{True} if this is the end of a word, C{False} otherwise. @type endWord: bool @return: C{True} if translation produced text, C{False} if not. @rtype: bool """ assert not self.useContractedForCurrentFocus or endWord, "Must only translate contracted at end of word" if self.useContractedForCurrentFocus: # self.bufferText has been used by _reportContractedCell, so clear it. self.bufferText = u"" oldTextLen = len(self.bufferText) pos = self.untranslatedStart + self.untranslatedCursorPos data = u"".join([unichr(cell | LOUIS_DOTS_IO_START) for cell in self.bufferBraille[:pos]]) mode = louis.dotsIO | louis.noUndefinedDots if (not self.currentFocusIsTextObj or self.currentModifiers) and self._table.contracted: mode |= louis.partialTrans self.bufferText = louis.backTranslate( [os.path.join(brailleTables.TABLES_DIR, self._table.fileName), "braille-patterns.cti"], data, mode=mode)[0] newText = self.bufferText[oldTextLen:] if newText: # New text was generated by the cells just entered. if self.useContractedForCurrentFocus or self.currentModifiers: # For contracted braille, an entire word is sent at once. # Don't speak characters as this is sent. # Also, suppress typed characters when emulating a command gesture. speech._suppressSpeakTypedCharacters(len(newText)) else: self._uncontSentTime = time.time() self.untranslatedStart = pos self.untranslatedCursorPos = 0 if self.currentModifiers or not self.currentFocusIsTextObj: if len(newText)>1: # Emulation of multiple characters at once is unsupported # Clear newText, so this function returns C{False} if not at end of word newText = u"" else: self.emulateKey(newText) else: self.sendChars(newText) if endWord or (newText and (not self.currentFocusIsTextObj or self.currentModifiers)): # We only need to buffer one word. # Clear the previous word (anything before the cursor) from the buffer. del self.bufferBraille[:pos] self.bufferText = u"" self.cellsWithText.clear() self.currentModifiers.clear() self.untranslatedStart = 0 self.untranslatedCursorPos = 0 if newText or endWord: self._updateUntranslated() return True return False
def _translate(self, endWord): """Translate buffered braille up to the cursor. Any text produced is sent to the system. @param endWord: C{True} if this is the end of a word, C{False} otherwise. @type endWord: bool @return: C{True} if translation produced text, C{False} if not. @rtype: bool """ assert not self.useContractedForCurrentFocus or endWord, "Must only translate contracted at end of word" if self.useContractedForCurrentFocus: # self.bufferText has been used by _reportContractedCell, so clear it. self.bufferText = u"" oldTextLen = len(self.bufferText) pos = self.untranslatedStart + self.untranslatedCursorPos data = u"".join([chr_(cell | brailleInput.LOUIS_DOTS_IO_START) for cell in self.bufferBraille[:pos]]) mode = louis.dotsIO | louis.noUndefinedDots if (not self.currentFocusIsTextObj or self.currentModifiers) and self._table.contracted: mode |= louis.partialTrans self.bufferText = louis.backTranslate(getCurrentBrailleTables(True), data, mode=mode)[0] newText = self.bufferText[oldTextLen:] if newText: # New text was generated by the cells just entered. if self.useContractedForCurrentFocus or self.currentModifiers: # For contracted braille, an entire word is sent at once. # Don't speak characters as this is sent. # Also, suppress typed characters when emulating a command gesture. speech._suppressSpeakTypedCharacters(len(newText)) else: self._uncontSentTime = time.time() self.untranslatedStart = pos self.untranslatedCursorPos = 0 if self.currentModifiers or not self.currentFocusIsTextObj: if len(newText)>1: # Emulation of multiple characters at once is unsupported # Clear newText, so this function returns C{False} if not at end of word newText = u"" else: self.emulateKey(newText) else: self.sendChars(newText) if endWord or (newText and (not self.currentFocusIsTextObj or self.currentModifiers)): # We only need to buffer one word. # Clear the previous word (anything before the cursor) from the buffer. del self.bufferBraille[:pos] self.bufferText = u"" self.cellsWithText.clear() if not instanceGP.modifiersLocked: self.currentModifiers.clear() instanceGP.clearMessageFlash() self.untranslatedStart = 0 self.untranslatedCursorPos = 0 if newText or endWord: self._updateUntranslated() return True return False
def bkToChar(dots, inTable=-1): if inTable == -1: inTable = config.conf["braille"]["inputTable"] char = chr(dots | 0x8000) text = louis.backTranslate( [osp.join(r"louis\tables", inTable), "braille-patterns.cti"], char, mode=louis.dotsIO) chars = text[0] if len(chars) == 1 and chars.isupper(): chars = 'shift+' + chars.lower() return chars if chars != ' ' else 'space'
def input(self, dots): """Handle one cell of braille input. """ # liblouis requires us to set the highest bit for proper use of dotsIO. char = unichr(dots | 0x8000) text = louis.backTranslate( [os.path.join(braille.TABLES_DIR, config.conf["braille"]["inputTable"]), "braille-patterns.cti"], char, mode=louis.dotsIO) chars = text[0] if len(chars) > 0: self.sendChars(chars)
def _translate(self, endWord): """Translate buffered braille up to the cursor. Any text produced is sent to the system. @param endWord: C{True} if this is the end of a word, C{False} otherwise. @type endWord: bool @return: C{True} if translation produced text, C{False} if not. @rtype: bool """ assert not self._table.contracted or endWord, "Must only translate contracted at end of word" if self._table.contracted: # self.bufferText has been used by _reportContractedCell, so clear it. self.bufferText = u"" oldTextLen = len(self.bufferText) pos = self.untranslatedStart + self.untranslatedCursorPos data = u"".join([ unichr(cell | LOUIS_DOTS_IO_START) for cell in self.bufferBraille[:pos] ]) self.bufferText = louis.backTranslate([ os.path.join(brailleTables.TABLES_DIR, self._table.fileName), "braille-patterns.cti" ], data, mode=louis.dotsIO | louis.noUndefinedDots)[0] newText = self.bufferText[oldTextLen:] if newText: # New text was generated by the cells just entered. if self._table.contracted: # For contracted braille, an entire word is sent at once. # Don't speak characters as this is sent. speech._suppressSpeakTypedCharacters(len(newText)) else: self._uncontSentTime = time.time() self.untranslatedStart = pos self.untranslatedCursorPos = 0 self.sendChars(newText) if endWord: # We only need to buffer one word. # Clear the previous word (anything before the cursor) from the buffer. del self.bufferBraille[:pos] self.bufferText = u"" self.cellsWithText.clear() self.untranslatedStart = 0 self.untranslatedCursorPos = 0 if newText or endWord: self._updateUntranslated() return True return False
def _translateForReportContractedCell(self, pos): """Translate text for current input as required by L{_reportContractedCell}. @return: The previous translated text. @rtype: str """ cells = self.bufferBraille[:pos + 1] data = u"".join([chr(cell | LOUIS_DOTS_IO_START) for cell in cells]) oldText = self.bufferText text = louis.backTranslate( [os.path.join(brailleTables.TABLES_DIR, self._table.fileName), "braille-patterns.cti"], data, mode=louis.dotsIO | louis.noUndefinedDots | louis.partialTrans)[0] self.bufferText = text return oldText
def _translateForReportContractedCell(self, pos): """Translate text for current input as required by L{_reportContractedCell}. @return: The previous translated text. @rtype: unicode """ cells = self.bufferBraille[:pos + 1] data = u"".join([unichr(cell | LOUIS_DOTS_IO_START) for cell in cells]) oldText = self.bufferText text = louis.backTranslate( [os.path.join(brailleTables.TABLES_DIR, self._table.fileName), "braille-patterns.cti"], data, mode=louis.dotsIO | louis.noUndefinedDots | louis.partialTrans)[0] self.bufferText = text return oldText
def input(self, dots): """Handle one cell of braille input. """ # liblouis requires us to set the highest bit for proper use of dotsIO. char = unichr(dots | 0x8000) text = louis.backTranslate([ os.path.join(braille.TABLES_DIR, config.conf["braille"]["inputTable"]), "braille-patterns.cti" ], char, mode=louis.dotsIO) chars = text[0] if len(chars) > 0: self.sendChars(chars)
def input_(self, dots): """Handle one cell of braille input. """ # Insert the newly entered cell into the buffer at the cursor position. pos = self.untranslatedStart + self.untranslatedCursorPos # Space ends the word. endWord = dots == 0 continue_ = True if config.conf["brailleExtender"]["oneHandedMode"]["enabled"]: continue_, endWord = processOneHandMode(self, dots) if not continue_: return else: self.bufferBraille.insert(pos, dots) self.untranslatedCursorPos += 1 ok = False if instanceGP: focusObj = api.getFocusObject() ok = not self.currentModifiers and ( not focusObj.treeInterceptor or focusObj.treeInterceptor.passThrough) if instanceGP and instanceGP.advancedInput and ok: pos = self.untranslatedStart + self.untranslatedCursorPos advancedInputStr = ''.join( [chr(cell | 0x2800) for cell in self.bufferBraille[:pos]]) if advancedInputStr: res = '' abreviations = advancedinput.getReplacements([advancedInputStr]) startUnicodeValue = "⠃⠙⠓⠕⠭⡃⡙⡓⡕⡭" if not abreviations and advancedInputStr[0] in startUnicodeValue: advancedInputStr = config.conf["brailleExtender"][ "advancedInputMode"][ "escapeSignUnicodeValue"] + advancedInputStr lenEscapeSign = len( config.conf["brailleExtender"]["advancedInputMode"] ["escapeSignUnicodeValue"]) if advancedInputStr == config.conf["brailleExtender"][ "advancedInputMode"]["escapeSignUnicodeValue"] or ( advancedInputStr.startswith( config.conf["brailleExtender"]["advancedInputMode"] ["escapeSignUnicodeValue"]) and len(advancedInputStr) > lenEscapeSign and advancedInputStr[lenEscapeSign] in startUnicodeValue): equiv = { '⠃': 'b', '⠙': 'd', '⠓': 'h', '⠕': 'o', '⠭': 'x', '⡃': 'B', '⡙': 'D', '⡓': 'H', '⡕': 'O', '⡭': 'X' } if advancedInputStr[-1] == '⠀': text = equiv[advancedInputStr[1]] + louis.backTranslate( getCurrentBrailleTables(True, brf=instanceGP.BRFMode), advancedInputStr[2:-1])[0] try: res = getCharFromValue(text) sendChar(res) except BaseException as err: speech.speakMessage(repr(err)) return badInput(self) else: self._reportUntranslated(pos) elif abreviations: if len(abreviations) == 1: res = abreviations[0].replacement sendChar(res) else: return self._reportUntranslated(pos) else: res = huc.isValidHUCInput(advancedInputStr) if res == huc.HUC_INPUT_INCOMPLETE: return self._reportUntranslated(pos) if res == huc.HUC_INPUT_INVALID: return badInput(self) res = huc.backTranslate(advancedInputStr) sendChar(res) if res and config.conf["brailleExtender"]["advancedInputMode"][ "stopAfterOneChar"]: instanceGP.advancedInput = False return # For uncontracted braille, translate the buffer for each cell added. # Any new characters produced are then sent immediately. # For contracted braille, translate the buffer only when a word is ended (i.e. a space is typed). # This is because later cells can change characters produced by previous cells. # For example, in English grade 2, "tg" produces just "tg", # but "tgr" produces "together". if not self.useContractedForCurrentFocus or endWord: if self._translate(endWord): if not endWord: self.cellsWithText.add(pos) elif self.bufferText and not self.useContractedForCurrentFocus and self._table.contracted: # Translators: Reported when translation didn't succeed due to unsupported input. speech.speakMessage(_("Unsupported input")) self.flushBuffer() else: # This cell didn't produce any text; e.g. number sign. self._reportUntranslated(pos) else: self._reportUntranslated(pos)
def do_process_key_event(self, keyval, keycode, state): is_press = ((state & IBus.ModifierType.RELEASE_MASK) == 0) no_control = ((state & IBus.ModifierType.CONTROL_MASK) == 0) no_alt = ((state & IBus.ModifierType.META_MASK) == 0) no_shift = ((state & IBus.ModifierType.SHIFT_MASK) == 0) no_super = ((state & IBus.ModifierType.SUPER_MASK) == 0) no_extra_mask = (no_control & no_alt & no_shift & no_super) if (not no_extra_mask): return False #if (not is_control and not is_alt and not is_shift and not is_super): # return False; #Key Release if not is_press: ordered_pressed_keys = self.order_pressed_keys(self.pressed_keys) if (ordered_pressed_keys == "3" and self.conventional_braille): self.conventional_braille_dot_3 = True self.old_braille_letter_map_pos = self.braille_letter_map_pos #Move map position to contraction if any if (ordered_pressed_keys in self.contractions_dict.keys() and self.liblouis_mode == False and self.one_hand_mode == False): self.braille_letter_map_pos = self.contractions_dict[ ordered_pressed_keys] #Toggle Punctuation elif ordered_pressed_keys == "0": self.braille_letter_map_pos = 2 #Expand Abbreviation elif (ordered_pressed_keys == "a" and self.simple_mode == 0): #self.pressed_keys = ""; surrounding_text = self.get_surrounding_text() text = surrounding_text[0].get_text() cursor_pos = surrounding_text[1] string_up_to_cursor = text[:cursor_pos] last_word = string_up_to_cursor.split()[-1] #Substitute abbreviation if exist and letter bofore the cursor is not space if (last_word in self.abbreviations.keys() and string_up_to_cursor[-1] != " "): self.delete_surrounding_text(-(len(last_word)), len(last_word)) for key, value in self.abbreviations.items(): if key == last_word: self.__commit_string(value) #Fixme Why this heck is not working :( ?? #self.__commit_string(self.abbreviations[last_word.decode('UTF-8')].decode('UTF-8')) #Delete Last word elif (ordered_pressed_keys == "c9"): surrounding_text = self.get_surrounding_text() text = surrounding_text[0].get_text() cursor_pos = surrounding_text[1] string_up_to_cursor = text[:cursor_pos] #If end is space, then count backword till a space found if (string_up_to_cursor[-1] == " "): count = 0 char_found = 0 for item in string_up_to_cursor[::-1]: if (item != " "): char_found = 1 if (item == " " and char_found == 1): break count += 1 self.delete_surrounding_text(-(count), count) speak(string_up_to_cursor[-(count):] + "Deleted") #If end is not space, delete length of last word else: count = len(string_up_to_cursor.split()[-1]) self.delete_surrounding_text(-(count), count) speak(string_up_to_cursor.split()[-1] + "Deleted") #Delete Last letter elif (ordered_pressed_keys == "9"): surrounding_text = self.get_surrounding_text() text = surrounding_text[0].get_text() speak(text[-1:] + "Deleted") self.delete_surrounding_text(-1, 1) #Toggle capital switch elif (ordered_pressed_keys == "c" and self.language == "english"): if (self.capital_switch == 1): if (self.capital == False): self.capital = True speak("Caps Lock On!") else: self.capital = False speak("Caps Lock Off!") self.capital_switch = 0 self.capital_switch = 1 elif (self.conventional_braille == True and ordered_pressed_keys == "4" and self.liblouis_mode == False): self.conventional_braille_dot_4 = True else: if (len(ordered_pressed_keys) > 0): if (self.liblouis_mode): sum = 0 for i in ordered_pressed_keys: sum = sum + pow(2, int(i) - 1) pressed_dots = 0x2800 + sum #self.louis_current_typing_word = self.louis_current_typing_word + chr(pressed_dots) self.__commit_string(chr(pressed_dots)) else: if (self.one_hand_mode): if (self.three_dot_pos == 1 and self.pressed_keys != ""): if (self.pressed_keys == "o"): self.pressed_keys = "" self.three_dot_pos = 2 t = Timer(self.one_hand_conversion_delay, self.three_dot_do_commit) t.start() return False try: value = self.map[ordered_pressed_keys][ self.braille_letter_map_pos] except: value = "" if (self.capital_switch == 1 or self.capital == 1): value = value.upper() self.capital_switch = 0 self.__commit_string(value) self.conventional_braille_dot_4_pass = False self.conventional_braille_dot_3 = False if (self.conventional_braille == 1 and self.conventional_braille_dot_4): self.conventional_braille_dot_4 = False self.__commit_string( self.map["4"][self.braille_letter_map_pos]) self.conventional_braille_dot_4_pass = True self.braille_letter_map_pos = 1 self.pressed_keys = "" return False #Key press else: self.get_surrounding_text() if keycode in self.keycode_map.keys(): #Store the letters if (self.one_hand_mode): if (self.three_dot_pos == 1): self.pressed_keys += self.keycode_map[keycode] else: self.pressed_keys += str( int(self.keycode_map[keycode]) + 3) else: self.pressed_keys += self.keycode_map[keycode] return True else: if (keyval == keysyms.space): self.braille_letter_map_pos = 0 if (self.liblouis_mode): surrounding_text = self.get_surrounding_text() text = surrounding_text[0].get_text() cursor_pos = surrounding_text[1] string_up_to_cursor = text[:cursor_pos] count = len(string_up_to_cursor.split()[-1]) last_word = string_up_to_cursor.split()[-1] if (string_up_to_cursor[-1] != " "): word = louis.backTranslate( self.liblouis_table_list, last_word, None, 0) self.delete_surrounding_text(-(count), count) self.__commit_string(word[0]) else: if (self.conventional_braille == True): if (self.conventional_braille_dot_3): self.__commit_string(self.map["3"][ self.old_braille_letter_map_pos]) self.conventional_braille_dot_3 = False if (self.conventional_braille_dot_4): self.conventional_braille_dot_4 = False self.__commit_string( self.map["4"][self.braille_letter_map_pos]) elif (self.conventional_braille_dot_4_pass == True ): self.conventional_braille_dot_4_pass = False self.__commit_string( self.map["8"][self.braille_letter_map_pos]) return True else: if (keycode == self.key_to_switch_between_languages): if (len(self.checked_languages) - 1 == self.language_iter): self.language_iter = 0 self.load_map( self.checked_languages[self.language_iter]) else: self.language_iter = self.language_iter + 1 self.load_map( self.checked_languages[self.language_iter]) if (keycode == self.list_switch_key): if (self.braille_letter_map_pos == 0): self.braille_letter_map_pos = 1 else: self.braille_letter_map_pos = 0 return False