def _caretScriptPostMovedHelper(self, speakUnit, gesture, info = None): """ This method ensures that LaTeX translation occurs when the system caret moves, and also makes sure that normal behaviour occurs when l{processMaths} is off. """ if isScriptWaiting (): return if not info: try: info = self.makeTextInfo (textInfos.POSITION_CARET) except: return review.handleCaretMove(info) if speakUnit == textInfos.UNIT_LINE and EditableText.processMaths and not willSayAllResume(gesture): spokenLine = GetLine () brailledLine = GetLine () if not spokenLine and not brailledLine:# Is it a blank line? spokenLine = _("blank") brailledLine = _("") else: spokenLine = EditableText.latex_access.speech (spokenLine) brailledLine = EditableText.latex_access.nemeth (brailledLine) speech.speakMessage (spokenLine) braille.handler.message (brailledLine) else: if speakUnit and not willSayAllResume(gesture): info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET) braille.handler.handleCaretMove(self)
def _caretMovementScriptHelper(self, gesture, unit, direction=None, posConstant=textInfos.POSITION_SELECTION, posUnit=None, posUnitEnd=False, extraDetail=False, handleSymbols=False): oldInfo = self.makeTextInfo(posConstant) info = oldInfo.copy() info.collapse(end=not self._lastSelectionMovedStart) if not self._lastSelectionMovedStart and not oldInfo.isCollapsed: info.move(textInfos.UNIT_CHARACTER, -1) if posUnit is not None: info.expand(posUnit) info.collapse(end=posUnitEnd) if posUnitEnd: info.move(textInfos.UNIT_CHARACTER, -1) if direction is not None: info.expand(unit) info.collapse(end=posUnitEnd) info.move(unit, direction) self.selection = info info.expand(unit) if not willSayAllResume(gesture): speech.speakTextInfo(info, unit=unit, reason=controlTypes.REASON_CARET) if not oldInfo.isCollapsed: speech.speakSelectionChange(oldInfo, self.selection)
def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False): oldInfo=self.makeTextInfo(posConstant) info=oldInfo.copy() info.collapse(end=self.isTextSelectionAnchoredAtStart) if self.isTextSelectionAnchoredAtStart and not oldInfo.isCollapsed: info.move(textInfos.UNIT_CHARACTER,-1) if posUnit is not None: # expand and collapse to ensure that we are aligned with the end of the intended unit info.expand(posUnit) try: info.collapse(end=posUnitEnd) except RuntimeError: # MS Word has a "virtual linefeed" at the end of the document which can cause RuntimeError to be raised. # In this case it can be ignored. # See #7009 pass if posUnitEnd: info.move(textInfos.UNIT_CHARACTER,-1) if direction is not None: info.expand(unit) info.collapse(end=posUnitEnd) if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns): try: self.turnPage(previous=direction<0) except RuntimeError: pass else: info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST) self.selection=info info.expand(unit) if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET) if not oldInfo.isCollapsed: speech.speakSelectionChange(oldInfo,self.selection)
def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False): oldInfo=self.makeTextInfo(posConstant) info=oldInfo.copy() info.collapse(end=not self._lastSelectionMovedStart) if not self._lastSelectionMovedStart and not oldInfo.isCollapsed: info.move(textInfos.UNIT_CHARACTER,-1) if posUnit is not None: info.expand(posUnit) info.collapse(end=posUnitEnd) if posUnitEnd: info.move(textInfos.UNIT_CHARACTER,-1) if direction is not None: info.expand(unit) info.collapse(end=posUnitEnd) if info.move(unit,direction)==0 and isinstance(self,DocumentWithPageTurns): try: self.turnPage(previous=direction<0) except RuntimeError: pass else: info=self.makeTextInfo(textInfos.POSITION_FIRST if direction>0 else textInfos.POSITION_LAST) self.selection=info info.expand(unit) if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET) if not oldInfo.isCollapsed: speech.speakSelectionChange(oldInfo,self.selection)
def quickNavRapping(self, gesture, itemType, direction, errorMessage, readUnit): iterFactory = initNavItemsGenerator(self, itemType) try: item = next(iterFactory(direction, self.selection)) except NotImplementedError: # Translators: a message when a particular quick nav command is not supported in the current document. message(_('Not supported in this document')) return except StopIteration: if direction == 'next': lastPos = getCurrentPos(self) if not screenRapping(self, itemType, readUnit, msgrpTop, rpTo=textInfos.POSITION_FIRST): resetPosition(self, lastPos, itemType) else: lastPos = getCurrentPos(self) if not screenRapping(self, itemType, readUnit, msgrpBottom, rpTo=textInfos.POSITION_LAST, tone=(100, 80), reverse='next', direction='previous'): resetPosition(self, lastPos, itemType) return item.moveTo() if not gesture or not willSayAllResume(gesture): item.report(readUnit=readUnit)
def script_findNext(self, gesture): if not self._lastFindText: self.script_find(gesture) return self.doFindText( self._lastFindText, caseSensitive=self._lastCaseSensitivity, willSayAllResume=willSayAllResume(gesture), )
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 script_findPrevious(self, gesture): if not self._lastFindText: self.script_find(gesture, reverse=True) return self.doFindText( self._lastFindText, reverse=True, caseSensitive=self._lastCaseSensitivity, willSayAllResume=willSayAllResume(gesture), )
def _changePageScriptHelper(self,gesture,previous=False): if isScriptWaiting(): return try: self.turnPage(previous=previous) except RuntimeError: return info=self.makeTextInfo(textInfos.POSITION_FIRST) self.selection=info info.expand(textInfos.UNIT_LINE) if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=textInfos.UNIT_LINE,reason=controlTypes.REASON_CARET)
def _caretScriptPostMovedHelper(self, speakUnit, gesture, info=None): if isScriptWaiting(): return if not info: try: info = self.makeTextInfo(textInfos.POSITION_CARET) except: return review.handleCaretMove(info) if speakUnit and not willSayAllResume(gesture): info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET) braille.handler.handleCaretMove(self)
def _quickNavScript(self,gesture, itemType, direction, errorMessage, readUnit): info=self.selection try: item = next(self._iterNodesByType(itemType, direction, info)) except NotImplementedError: # Translators: a message when a particular quick nav command is not supported in the current document. ui.message(_("Not supported in this document")) return except StopIteration: ui.message(errorMessage) return item.moveTo() if not gesture or not willSayAllResume(gesture): item.report(readUnit=readUnit)
def _caretScriptPostMovedHelper(self, speakUnit, gesture, info=None): if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"): return if not info: try: info = self.makeTextInfo(textInfos.POSITION_CARET) except: return # Forget the word currently being typed as the user has moved the caret somewhere else. speech.clearTypedWordBuffer() review.handleCaretMove(info) if speakUnit and not willSayAllResume(gesture): info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET) braille.handler.handleCaretMove(self)
def script_specificFindPrevious(self, gesture): obj = api.getFocusObject() if not controlTypes.STATE_MULTILINE in obj.states: treeInterceptor = obj.treeInterceptor if not (isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough): gesture.send() return if not lastFindText: self.script_specificFind(gesture, reverse=True) else: doFindTextUp( lastFindText, lastCaseSensitivity, willSayAllResume=willSayAllResume(gesture), )
def _quickNavScript(self, gesture, itemType, direction, errorMessage, readUnit): if itemType == "notLinkBlock": iterFactory = self._iterNotLinkBlock else: iterFactory = lambda direction, info: self._iterNodesByType( itemType, direction, info) info = self.selection try: item = next(iterFactory(direction, info)) except NotImplementedError: # Translators: a message when a particular quick nav command # is not supported in the current document. ui.message(NVDAString("Not supported in this document")) return except StopIteration: if not toggleLoopInNavigationModeOption(False): ui.message(errorMessage) return # return to the top or bottom of page and continue search if direction == "previous": info = api.getReviewPosition().obj.makeTextInfo( textInfos.POSITION_LAST) self._set_selection(info, reason="quickNav") # Translators: message to the user which indicates the return # to the bottom of the page. msg = _("Return to bottom of page") else: info = None # Translators: message to user which indicates the return # to the top of the page. msg = _("Return to top of page") try: item = next(iterFactory(direction, info)) except Exception: ui.message(errorMessage) return ui.message(msg) winsound.PlaySound("default", 1) # #8831: Report before moving because moving might change the focus, which # might mutate the document, potentially invalidating info if it is # offset-based. if not gesture or not willSayAllResume(gesture): item.report(readUnit=readUnit) item.moveTo()
def myExecuteScript(script, gesture): """Executes a given script (function) passing it the given gesture. It also keeps track of the execution of duplicate scripts with in a certain amount of time, and counts how many times this happens. Use L{getLastScriptRepeatCount} to find out this count value. @param script: the function or method that should be executed. The function or method must take an argument of 'gesture'. This must be the same value as gesture.script, # but its passed in here purely for performance. @type script: callable. @param gesture: the input gesture that activated this script @type gesture: L{inputCore.InputGesture} """ global _lastScriptTime, _lastScriptCount, _lastScriptRef, _isScriptRunning lastScriptRef = _lastScriptRef() if _lastScriptRef else None # We don't allow the same script to be executed from with in itself, # but we still should pass the key through scriptFunc = getattr(script, "__func__", script) if _isScriptRunning and lastScriptRef == scriptFunc: return gesture.send() _isScriptRunning = True resumeSayAllMode = None if scriptHandler.willSayAllResume(gesture): resumeSayAllMode = sayAllHandler.lastSayAllMode try: scriptTime = time.time() scriptRef = weakref.ref(scriptFunc) if (scriptTime - _lastScriptTime) <= _getMaxTimeBetweenSameScript()\ and scriptFunc == lastScriptRef: _lastScriptCount += 1 else: _lastScriptCount = 0 _lastScriptRef = scriptRef _lastScriptTime = scriptTime script(gesture) except: # noqa:E722 log.exception("error executing script: %s with gesture %r" % (script, gesture.displayName)) finally: _isScriptRunning = False if resumeSayAllMode is not None: sayAllHandler.readText(resumeSayAllMode)
def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=textInfos.POSITION_SELECTION,posUnit=None,posUnitEnd=False,extraDetail=False,handleSymbols=False): oldInfo=self.makeTextInfo(posConstant) info=oldInfo.copy() info.collapse(end=not self._lastSelectionMovedStart) if not self._lastSelectionMovedStart and not oldInfo.isCollapsed: info.move(textInfos.UNIT_CHARACTER,-1) if posUnit is not None: info.expand(posUnit) info.collapse(end=posUnitEnd) if posUnitEnd: info.move(textInfos.UNIT_CHARACTER,-1) if direction is not None: info.expand(unit) info.collapse(end=posUnitEnd) info.move(unit,direction) self.selection=info info.expand(unit) if not willSayAllResume(gesture): speech.speakTextInfo(info,unit=unit,reason=controlTypes.REASON_CARET) if not oldInfo.isCollapsed: speech.speakSelectionChange(oldInfo,self.selection)
def script_selectNextBookmark(self, gesture): obj = api.getFocusObject() treeInterceptor = obj.treeInterceptor if hasattr(treeInterceptor, 'TextInfo') and not treeInterceptor.passThrough: obj = treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() positions = list(bookmarks.keys()) if len(positions) == 0: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return start = obj.makeTextInfo(textInfos.POSITION_ALL) try: end = obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): ui.message( # Translators: message presented when cannot find any bookmarks. _("Cannot find any bookmarks")) return start.setEndPoint(end, "endToStart") count = len(start.text) positions.sort() for pos in positions: if pos > count: end.move(textInfos.UNIT_CHARACTER, pos - count) obj.selection = end if not willSayAllResume(gesture): end.move(textInfos.UNIT_LINE, 1, endPoint="end") speech.speakTextInfo(end, reason=controlTypes.REASON_CARET) ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % pos) return ui.message( # Translators: message presented when the next bookmark is not found. _("Next bookmark not found"))
def script_selectPreviousBookmark(self, gesture): obj = api.getFocusObject() appName=appModuleHandler.getAppNameFromProcessID(obj.processID,True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() if bookmarks == {}: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return curPos = obj.makeTextInfo(textInfos.POSITION_CARET).bookmark.startOffset prevPos = None for pos in sorted(bookmarks, reverse=True): if pos < curPos: prevPos = pos break if prevPos is not None: info = obj.makeTextInfo(Offsets(prevPos, prevPos)) info.updateSelection() review.handleCaretMove(info) if willSayAllResume(gesture): info.move(textInfos.UNIT_LINE,1,endPoint="end") #speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % prevPos) return ui.message( # Translators: message presented when the previous bookmark is not found. _("Previous bookmark not found"))
def quickNavWrapping(treeInterceptor, gesture, itemType, direction, errorMessage, readUnit): iterFactory = initNavItemsGenerator(treeInterceptor, itemType) try: item = next(iterFactory(direction, treeInterceptor.selection)) except NotImplementedError: # Translators: a message when a particular quick nav command is not supported in the current document. message(_("Not supported in this document")) return except StopIteration: if direction == "next": lastPos = getCurrentPos(treeInterceptor) if not screenWrapping(treeInterceptor, itemType, readUnit, wrp2=textInfos.POSITION_FIRST): resetPosition(treeInterceptor, lastPos, errorMessage) else: lastPos = getCurrentPos(treeInterceptor) if not screenWrapping(treeInterceptor, itemType, readUnit, wrp2=textInfos.POSITION_LAST, reverse="next", direction="previous"): resetPosition(treeInterceptor, lastPos, errorMessage) return item.moveTo() if not gesture or not willSayAllResume(gesture): item.report(readUnit=readUnit)
def script_selectNextBookmark(self, gesture): obj = api.getFocusObject() appName = appModuleHandler.getAppNameFromProcessID(obj.processID, True) if appName == "MicrosoftEdgeCP.exe": gesture.send() return treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor else: gesture.send() return bookmarks = getSavedBookmarks() if bookmarks == {}: ui.message( # Translators: message presented when trying to select a bookmark, but none is found. _("No bookmarks found")) return curPos = obj.makeTextInfo( textInfos.POSITION_CARET).bookmark.startOffset nextPos = None for pos in sorted(bookmarks): if pos > curPos: nextPos = pos break if nextPos is not None: moveToBookmark(nextPos) if not willSayAllResume(gesture): ui.message( # Translators: message presented when a bookmark is selected. _("Position: character %d") % nextPos) return ui.message( # Translators: message presented when the next bookmark is not found. _("Next bookmark not found"))