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 _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._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