def event_selection(self, obj, nextHandler): if obj.role == controlTypes.ROLE_LISTITEM and isInWSRAlternatesPanel( obj): speech.speakText(str(obj.positionInfo["indexInGroup"])) speakAndSpellWSRAlternatesPanelItem(obj) return nextHandler()
def previousWord(self, selection=False): if self.value: if self.fakeCaret < 1: return if self.fakeCaret >= len(self.value): self.fakeCaret = self.fakeCaret-1 oldCaret = self.fakeCaret # Current character is a punctuation mark if self.fakeCaret > 0\ and self.value[self.fakeCaret] in punctuation\ and self.value[self.fakeCaret - 1] not in punctuation: self.fakeCaret = self.fakeCaret-1 if self.value[self.fakeCaret] in punctuation and self.fakeCaret >= 0: while self.value[self.fakeCaret] in punctuation and self.fakeCaret >= 0: self.fakeCaret = self.fakeCaret-1 self.fakeCaret = self.fakeCaret+1 if selection: speech.speakText(self.value[self.fakeCaret:oldCaret]) else: speech.speakText(self.value[self.fakeCaret]) return # Current character is an space if self.value[self.fakeCaret] == " " and self.fakeCaret > 0: while self.value[self.fakeCaret] == " " and self.fakeCaret > 0: self.fakeCaret = self.fakeCaret-1 group = self.alphanumeric\ if self.value[self.fakeCaret] in self.alphanumeric\ else punctuation self.fakeCaret = self.fakeCaret-1 if self.fakeCaret > 0 else 0 while self.value[self.fakeCaret] in group and self.fakeCaret > 0: self.fakeCaret = self.fakeCaret-1 if self.fakeCaret > 0: self.fakeCaret = self.fakeCaret+1 speech.speakText(self.value[self.fakeCaret:oldCaret]) return # Current character is alphanumeric if self.fakeCaret > 0 and\ self.value[self.fakeCaret-1] in self.alphanumeric+" ": self.fakeCaret = self.fakeCaret-1 if self.value[self.fakeCaret] in self.alphanumeric and self.fakeCaret > 0: while self.value[self.fakeCaret] in self.alphanumeric and self.fakeCaret > 0: # noqa:E501 self.fakeCaret = self.fakeCaret-1 if self.fakeCaret > 0: self.fakeCaret = self.fakeCaret+1 if oldCaret == len(self.value)-1: oldCaret = oldCaret+1 speech.speakText(self.value[self.fakeCaret:oldCaret]) return else: group = punctuation if self.value[self.fakeCaret] in punctuation else " " while self.value[self.fakeCaret] in group and self.fakeCaret > 0: self.fakeCaret = self.fakeCaret-1 if self.value[self.fakeCaret+1] == " ": group = punctuation if self.value[self.fakeCaret] in punctuation\ else self.alphanumeric while self.value[self.fakeCaret] in group and self.fakeCaret > 0: self.fakeCaret = self.fakeCaret-1 if self.fakeCaret > 0: self.fakeCaret = self.fakeCaret+1 speech.speakText(self.value[self.fakeCaret:oldCaret])
def previousCh(self, selection=0): if self.value: if self.fakeCaret > 0: self.fakeCaret = self.fakeCaret - 1 if selection and self.fakeCaret == 0: speech.speakText(self.value[self.fakeCaret]) else: speech.speakText(self.value[self.fakeCaret])
def script_home(self, gesture): self.typeBuffer = "" self.startSelection = -1 gesture.send() if self.fakeCaret > 0: self.fakeCaret = 0 if self.value: speech.speakText(self.value[self.fakeCaret]) self.displayBraille()
def event_valueChange(self): global lastMSNHistoryValue if winUser.isDescendantWindow(winUser.getForegroundWindow(),self.windowHandle): value=self.value if value!=lastMSNHistoryValue and config.conf["presentation"]["reportDynamicContentChanges"]: speech.speakText(value) lastMSNHistoryValue=value
def _handleInputHelp(self, gesture, onlyLog=False): textList = [gesture.displayName] script = gesture.script runScript = False logMsg = "Input help: gesture %s"%gesture.logIdentifier if script: scriptName = scriptHandler.getScriptName(script) logMsg+=", bound to script %s" % scriptName scriptLocation = scriptHandler.getScriptLocation(script) if scriptLocation: logMsg += " on %s" % scriptLocation if scriptName == "toggleInputHelp": runScript = True else: desc = script.__doc__ if desc: textList.append(desc) log.info(logMsg) if onlyLog: return import braille braille.handler.message("\t\t".join(textList)) # Punctuation must be spoken for the gesture name (the first chunk) so that punctuation keys are spoken. speech.speakText(textList[0], reason=controlTypes.REASON_MESSAGE, symbolLevel=characterProcessing.SYMLVL_ALL) for text in textList[1:]: speech.speakMessage(text) if runScript: script(gesture)
def reportFocus(self): if not config.conf["inputComposition"]["announceSelectedCandidate"]: return text=self.name desc=self.description if desc: text+=u", "+desc speech.speakText(text)
def _handleInputHelp(self, gesture, onlyLog=False): textList = [gesture.displayName] script = gesture.script runScript = False logMsg = "Input help: gesture %s" % gesture.identifiers[0] if script: scriptName = scriptHandler.getScriptName(script) logMsg += ", bound to script %s" % scriptName scriptLocation = scriptHandler.getScriptLocation(script) if scriptLocation: logMsg += " on %s" % scriptLocation if scriptName == "toggleInputHelp": runScript = True else: desc = script.__doc__ if desc: textList.append(desc) log.info(logMsg) if onlyLog: return import braille braille.handler.message("\t\t".join(textList)) # Punctuation must be spoken for the gesture name (the first chunk) so that punctuation keys are spoken. speech.speakText(textList[0], reason=controlTypes.REASON_MESSAGE, symbolLevel=characterProcessing.SYMLVL_ALL) for text in textList[1:]: speech.speakMessage(text) if runScript: script(gesture)
def event_mouseMove(self,x,y): if not self._mouseEntered and config.conf['mouse']['reportObjectRoleOnMouseEnter']: speech.cancelSpeech() speech.speakObjectProperties(self,role=True) speechWasCanceled=True else: speechWasCanceled=False self._mouseEntered=True try: info=self.makeTextInfo(textInfos.Point(x,y)) except NotImplementedError: info=NVDAObjectTextInfo(self,textInfos.POSITION_FIRST) except LookupError: return if config.conf["reviewCursor"]["followMouse"]: api.setReviewPosition(info) info.expand(info.unit_mouseChunk) oldInfo=getattr(self,'_lastMouseTextInfoObject',None) self._lastMouseTextInfoObject=info if not oldInfo or info.__class__!=oldInfo.__class__ or info.compareEndPoints(oldInfo,"startToStart")!=0 or info.compareEndPoints(oldInfo,"endToEnd")!=0: text=info.text notBlank=False if text: for ch in text: if not ch.isspace() and ch!=u'\ufffc': notBlank=True if notBlank: if not speechWasCanceled: speech.cancelSpeech() speech.speakText(text)
def script_announceBufferChange(self, gesture): gesture.send() speech.speakText(self.parent.parent.name) try: s = self.getLambdaObj().getline(self.windowHandle, -1, -1) self.say(s) except COMError: pass
def nextCh(self, selection=0): if self.value: if self.fakeCaret < len(self.value): self.fakeCaret = self.fakeCaret+1 try: if self.fakeCaret < len(self.value) + 1: speech.speakText(self.value[self.fakeCaret-selection]) except IndexError: pass
def move(self, gesture, regex, increment, errorMsg): focus = api.getFocusObject() if not getConfig("enableInWord") and ( isinstance(focus, winword.WordDocument) or ("Dynamic_IAccessibleRichEdit" in str(type(focus)) and hasattr(focus, "script_caret_nextSentence") and hasattr(focus, "script_caret_previousSentence"))): if increment > 0: focus.script_caret_nextSentence(gesture) elif increment < 0: focus.script_caret_previousSentence(gesture) else: # increment == 0 pass return if focus.role in [ controlTypes.ROLE_COMBOBOX, controlTypes.ROLE_LISTITEM, controlTypes.ROLE_BUTTON ]: try: # The following line will only succeed in BrowserMode. focus.treeInterceptor.script_collapseOrExpandControl(gesture) except AttributeError: gesture.send() return if hasattr(focus, "treeInterceptor") and hasattr( focus.treeInterceptor, "makeTextInfo"): focus = focus.treeInterceptor try: caretInfo = focus.makeTextInfo(textInfos.POSITION_CARET) except NotImplementedError: gesture.send() return caretIndex, paragraphInfo = getCaretIndexWithinParagraph(caretInfo) context = Context(paragraphInfo, caretIndex, caretInfo) reconstructMode = getConfig("reconstructMode") sentenceStr, ti = self.moveExtended(context, increment, regex=regex, errorMsg=errorMsg, reconstructMode=reconstructMode) if ti is None: return if increment != 0: newCaret = ti.copy() newCaret.collapse() newCaret.updateCaret() review.handleCaretMove(newCaret) braille.handler.handleCaretMove(focus) vision.handler.handleCaretMove(focus) if willSayAllResume(gesture): return if getConfig("speakFormatted"): speech.speakTextInfo(ti, reason=REASON_CARET) else: speech.speakText(sentenceStr)
def reportLastInsertedText(self, obj, reason=None): obj.detectPossibleSelectionChange() obj.invalidateCache() obj.redraw() s = obj.getLambdaObj().getlastinsertedel(obj.windowHandle, 1) if s == None or len(s) == 0: return self.shouldValueChangeSpeak = False if config.conf['keyboard']['speakTypedCharacters']: speech.speakText(s)
def say(self, msg): if (msg == None) or (msg == self.empty): return for space in self.appModule.LAMBDA_SPACE: if u' ' + space + u' ' in msg: msg = msg.replace(space, shMsg.GLB_SPACE) if msg == " ": msg = shMsg.GLB_SPACE speech.speakText(msg)
def wsrPanelHidden(self, windowHandle): global wsrAlternatesPanel, wsrSpellingPanel if wsrAlternatesPanel is not None and windowHandle == wsrAlternatesPanel.windowHandle: if wsrSpellingPanel is None: speech.speakText("Closed alternates panel") wsrAlternatesPanel = None elif wsrSpellingPanel is not None and windowHandle == wsrSpellingPanel.windowHandle: wsrSpellingPanel.cancelPoll() speech.speakText("Closed spelling panel") wsrSpellingPanel = None
def reportFocus(self): speech.speakObjectProperties(self,name=True,role=True) info=self.makeTextInfo(textInfos.POSITION_CARET) info.move(textInfos.UNIT_WORD,-1,endPoint="start") try: error=info._rangeObj.spellingErrors[1].text except: info.expand(textInfos.UNIT_STORY) speech.speakText(info.text) return speech.speakText(error) speech.speakSpelling(error)
def script_supr(self, gesture): self.typeBuffer = "" value = self.value gesture.send() if self.startSelection >= 0: self.removeSelection(value) return try: if self.value: speech.speakText(self.value[self.fakeCaret + 1]) except IndexError: pass self.displayBraille()
def moveInEditable(self, increment, errorMessage, unbounded=False, op=operator.eq, speakOnly=False, moveCount=1): with self.getLineManager() as lm: # Get the current indentation level text = lm.getText() indentationLevel = self.getIndentLevel(text) onEmptyLine = speech.isBlank(text) # Scan each line until we hit the end of the indentation block, the end of the edit area, or find a line with the same indentation level found = False indentLevels = [] while True: result = lm.move(increment) if result == 0: break text = lm.getText() newIndentation = self.getIndentLevel(text) # Skip over empty lines if we didn't start on one. if not onEmptyLine and speech.isBlank(text): continue if op(newIndentation, indentationLevel): # Found it found = True indentationLevel = newIndentation resultLine = lm.getLine() resultText = lm.getText() moveCount -= 1 if moveCount == 0: break elif newIndentation < indentationLevel: # Not found in this indentation block if not unbounded: break indentLevels.append(newIndentation) if found: textInfo = None if not speakOnly: textInfo = lm.updateCaret(resultLine) self.crackle(indentLevels) if textInfo is not None: speech.speakTextInfo(textInfo, unit=textInfos.UNIT_LINE) else: speech.speakText(resultText) else: self.endOfDocument(errorMessage)
def script_back(self, gesture): self.typeBuffer = "" if self.startSelection >= 0: value = self.value gesture.send() self.removeSelection(value) return if self.value and self.fakeCaret > 0: speech.speakText(self.value[self.fakeCaret - 1]) gesture.send() if self.fakeCaret > 0: self.fakeCaret = self.fakeCaret - 1 self.displayBraille()
def script_selectPreviousWord(self, gesture): self.typeBuffer = "" if self.startSelection < 0: self.startSelection = self.fakeCaret sizeBefore = self.startSelection - self.fakeCaret if self.startSelection > self.fakeCaret else self.fakeCaret - self.startSelection gesture.send() self.previousWord(True) sizeAfter = self.startSelection - self.fakeCaret if self.startSelection > self.fakeCaret else self.fakeCaret - self.startSelection if sizeAfter > sizeBefore: speech.speakText(_("selected")) else: if self.fakeCaret > 0: speech.speakText(_("deselected")) self.displayBraille()
def script_selectNextCh(self, gesture): self.typeBuffer = "" if self.startSelection < 0: self.startSelection = self.fakeCaret sizeBefore = self.startSelection - self.fakeCaret if self.startSelection > self.fakeCaret else self.fakeCaret - self.startSelection gesture.send() self.nextCh(1) sizeAfter = self.startSelection - self.fakeCaret if self.startSelection > self.fakeCaret else self.fakeCaret - self.startSelection if sizeAfter > sizeBefore: speech.speakText(_("selected")) else: if self.fakeCaret < len(self.value): speech.speakText(_("deselected")) self.displayBraille()
def event_typedCharacter(self, ch): if ord(ch) < 128: if config.conf['keyboard']['speakTypedWords'] and hasattr( self.parent, '_caretMovementScriptHelper'): self.focusToParent() info = api.getReviewPosition() if not ch.isspace(): info.move(textInfos.UNIT_CHARACTER, -1) info.move(textInfos.UNIT_CHARACTER, -1) info.collapse() info.expand(textInfos.UNIT_WORD) speech.speakText(info.text) super(KoreanInputComposition, self).event_typedCharacter(ch)
def readTrainingText(self): window = api.getForegroundObject() for descendant in window.recursiveDescendants: if not isinstance(descendant, UIA): continue try: automationID = descendant.UIAElement.currentAutomationID except: continue if automationID == "txttrain": api.setNavigatorObject(descendant) speech.speakText(descendant.name) break
def poll(self, *args, **kwargs): self.pollTimer = None oldWord = self.previousWord or "" newWord = self.word or "" if newWord != oldWord: self.previousWord = newWord if len(newWord) > len(oldWord) and newWord[:len(oldWord)] == oldWord: speech.speakSpelling(newWord[len(oldWord):]) elif newWord: speech.speakText(newWord) speech.speakSpelling(newWord) elif oldWord: speech.speakText("cleared") self.schedulePoll()
def flushCurrentEntry(): global currentEntry, autoFlushTimer if autoFlushTimer is not None: autoFlushTimer.Stop() autoFlushTimer = None start, text = currentEntry text = text.replace("\r\n", "\n") text = text.replace("\r", "\n") while True: i = text.find("\n") if i == -1: break if i > 0: speech.speakText(text[:i]) if text[i:i + 2] == "\n\n": # Translators: The text which is spoken when a new paragraph is added. speech.speakText(_("new paragraph")) text = text[i + 2:] else: # Translators: The message spoken when a new line is entered. speech.speakText(_("new line")) text = text[i + 1:] if text != "": speech.speakText(text) braille.handler.handleCaretMove(api.getFocusObject()) currentEntry = None requestWSRShowHideEvents()
def flushCurrentEntry(): global currentEntry, autoFlushTimer if autoFlushTimer is not None: autoFlushTimer.Stop() autoFlushTimer = None start, text = currentEntry text = text.replace("\r\n", "\n") text = text.replace("\r", "\n") while True: i = text.find("\n") if i == -1: break if i > 0: speech.speakText(text[:i]) if text[i:i + 2] == "\n\n": speech.speakText("new paragraph") text = text[i + 2:] else: speech.speakText("new line") text = text[i + 1:] if text != "": speech.speakText(text) braille.handler.handleCaretMove(api.getFocusObject()) currentEntry = None requestWSRShowHideEvents()
def poll(self, *args, **kwargs): self.pollTimer = None oldWord = self.previousWord or "" newWord = self.word or "" if newWord != oldWord: self.previousWord = newWord if len(newWord) > len(oldWord) and newWord[:len(oldWord)] == oldWord: speech.speakSpelling(newWord[len(oldWord):]) elif newWord: speech.speakText(newWord) speech.speakSpelling(newWord) elif oldWord: # Translators: The text which is spoken when the spelling dialog is cleared. speech.speakText(_("cleared")) self.schedulePoll()
def reportFocus(self): # #4878: Excel specific code for speaking format changes on the focused object. info=self.makeTextInfo(textInfos.POSITION_FIRST) info.expand(textInfos.UNIT_CHARACTER) formatField=textInfos.FormatField() formatConfig=config.conf['documentFormatting'] for field in info.getTextWithFields(formatConfig): if isinstance(field,textInfos.FieldCommand) and isinstance(field.field,textInfos.FormatField): formatField.update(field.field) if not hasattr(self.parent,'_formatFieldSpeechCache'): self.parent._formatFieldSpeechCache={} text=speech.getFormatFieldSpeech(formatField,attrsCache=self.parent._formatFieldSpeechCache,formatConfig=formatConfig) if formatField else None if text: speech.speakText(text) super(ExcelCell,self).reportFocus()
def event_gainFocus(self): rowHeaderText = "" columnHeaderText = "" if config.conf['calibre']['reportTableHeaders'] == "st": if self.rowHeaderText != self.appModule.lastRowHeader: rowHeaderText = "%s; " % self.rowHeaderText if self.columnHeaderText != self.appModule.lastColumnHeader: columnHeaderText = "; %s" % self.columnHeaderText if config.conf['calibre']['reportTableHeaders'] == "cl" and\ self.columnHeaderText != self.appModule.lastColumnHeader: columnHeaderText = "; %s" % self.columnHeaderText speakText("%s%s%s" % (rowHeaderText, self.name, columnHeaderText)) braille.handler.handleGainFocus(self) self.appModule.lastRowHeader = self.rowHeaderText self.appModule.lastColumnHeader = self.columnHeaderText
def reportLastInsertedText(self, obj, reason=None): obj.detectPossibleSelectionChange() cfg = config.conf['lambda']['brailleFlatMode'] if not cfg: braille.handler.handleGainFocus(obj) try: s = obj.getLambdaObj().getlastinsertedel(obj.windowHandle, 1) except COMError: s = None if s == None or len(s) == 0: return if s in self.LAMBDA_SPACE: return if s == u" ": return self.shouldValueChangeSpeak = False if config.conf['keyboard']['speakTypedCharacters']: speech.speakText(s)
def event_typedCharacter(self, *args, **kwargs): self.startSelection = -1 ch = kwargs["ch"] if ch in self.alphanumeric + punctuation: self.typeBuffer = self.typeBuffer + ch self.fakeCaret = self.fakeCaret + 1 if config.conf["keyboard"]["speakTypedCharacters"]: speech.speakText(ch) else: if self.typeBuffer: if config.conf["keyboard"]["speakTypedWords"]: speech.speakText(self.typeBuffer) self.typeBuffer = "" if ch == " ": self.fakeCaret = self.fakeCaret + 1 self.displayBraille()
def handleInputCompositionEnd(result): import speech import characterProcessing from NVDAObjects.inputComposition import InputComposition from NVDAObjects.behaviors import CandidateItem focus=api.getFocusObject() result=result.lstrip(u'\u3000 ') curInputComposition=None if isinstance(focus,InputComposition): curInputComposition=focus oldSpeechMode=speech.speechMode speech.speechMode=speech.speechMode_off eventHandler.executeEvent("gainFocus",focus.parent) speech.speechMode=oldSpeechMode elif isinstance(focus.parent,InputComposition): #Candidate list is still up curInputComposition=focus.parent focus.parent=focus.parent.parent if curInputComposition and not result: result=curInputComposition.compositionString.lstrip(u'\u3000 ') if result: speech.speakText(result,symbolLevel=characterProcessing.SYMLVL_ALL)
def handleInputCompositionEnd(result): import speech import characterProcessing from NVDAObjects.inputComposition import InputComposition from NVDAObjects.IAccessible.mscandui import ModernCandidateUICandidateItem focus = api.getFocusObject() result = result.lstrip(u'\u3000 ') curInputComposition = None if isinstance(focus, InputComposition): curInputComposition = focus oldSpeechMode = speech.getState().speechMode speech.setSpeechMode(speech.SpeechMode.off) eventHandler.executeEvent("gainFocus", focus.parent) speech.setSpeechMode(oldSpeechMode) elif isinstance(focus.parent, InputComposition): #Candidate list is still up curInputComposition = focus.parent focus.parent = focus.parent.parent if isinstance(focus, ModernCandidateUICandidateItem): # Correct focus for ModernCandidateUICandidateItem # Find the InputComposition object and # correct focus to its parent if isinstance(focus.container, InputComposition): curInputComposition = focus.container newFocus = curInputComposition.parent else: # Sometimes InputCompositon object is gone # Correct to container of CandidateItem newFocus = focus.container oldSpeechMode = speech.getState().speechMode speech.setSpeechMode(speech.SpeechMode.off) eventHandler.executeEvent("gainFocus", newFocus) speech.setSpeechMode(oldSpeechMode) if curInputComposition and not result: result = curInputComposition.compositionString.lstrip(u'\u3000 ') if result: speech.speakText(result, symbolLevel=characterProcessing.SymbolLevel.ALL)
def _reportNewText(self, line): """Report a line of new text. """ speech.speakText(line)
def event_selection(self): speech.cancelSpeech() speech.speakText(self.name) if config.conf["notepadPp"]["brailleAutocompleteSuggestions"]: braille.handler.message(u'⣏ %s ⣹' % self.name)
def event_selection(self, obj, nextHandler): if obj.role == controlTypes.ROLE_LISTITEM and isInWSRAlternatesPanel(obj): speech.speakText(str(obj.positionInfo["indexInGroup"])) speakAndSpellWSRAlternatesPanelItem(obj) return nextHandler()
def event_show(self, obj, nextHandler): global wsrAlternatesPanel, wsrSpellingPanel #Phrases which need translated in this function: # Translators: The text for "or say," Which is telling the user that they can say the next phrase. orSay = _("Or say") if isinstance(obj, WSRAlternatesPanel): wsrAlternatesPanel = obj speech.cancelSpeech() speech.speakText(obj.name) for descendant in obj.recursiveDescendants: if controlTypes.STATE_INVISIBLE in descendant.states or controlTypes.STATE_INVISIBLE in descendant.parent.states: continue if descendant.role == controlTypes.ROLE_STATICTEXT: speech.speakText(descendant.name) elif descendant.role == controlTypes.ROLE_LINK: speech.speakText(orSay) speech.speakText(descendant.name) elif descendant.role == controlTypes.ROLE_LISTITEM: speech.speakText(str(descendant.positionInfo["indexInGroup"])) speakWSRAlternatesPanelItem(descendant) return elif isinstance(obj, WSRSpellingPanel): if wsrSpellingPanel is not None: wsrSpellingPanel.cancelPoll() wsrSpellingPanel = obj wsrSpellingPanel.schedulePoll() speech.cancelSpeech() speech.speakText(obj.name) for descendant in obj.recursiveDescendants: if controlTypes.STATE_INVISIBLE in descendant.states or controlTypes.STATE_INVISIBLE in descendant.parent.states: continue if descendant.role == controlTypes.ROLE_STATICTEXT: speech.speakText(descendant.name) elif descendant.role == controlTypes.ROLE_LINK: speech.speakText(orSay) speech.speakText(descendant.name) return nextHandler()
def speakAndSpellWSRAlternatesPanelItem(obj): text = getCleanedWSRAlternatesPanelItemName(obj) speech.speakText(text) speech.speakSpelling(text)
def speakWSRAlternatesPanelItem(obj): text = getCleanedWSRAlternatesPanelItemName(obj) speech.speakText(text)
def textDeleted(hwnd, start, text): # Translators: The message spoken when a piece of text is deleted. speech.speakText(_("deleted %s" % text))
def reportFocus(self): errorText=self.errorText speech.speakObjectProperties(self,name=True,role=True) if errorText: speech.speakText(errorText) speech.speakSpelling(errorText)