def executeScript(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 willSayAllResume(gesture): resumeSayAllMode=sayAllHandler.lastSayAllMode try: scriptTime=time.time() scriptRef=weakref.ref(scriptFunc) if (scriptTime-_lastScriptTime)<=0.5 and scriptFunc==lastScriptRef: _lastScriptCount+=1 else: _lastScriptCount=0 _lastScriptRef=scriptRef _lastScriptTime=scriptTime script(gesture) except: log.exception("error executing script: %s with gesture %r"%(script,gesture.displayName)) finally: _isScriptRunning=False if resumeSayAllMode is not None: sayAllHandler.readText(resumeSayAllMode)
def script_sayAll(self,gesture): o=api.getFocusObject() ti=o.treeInterceptor if ti and not ti.passThrough: o=ti try: info=o.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): return sayAllHandler.readText(info,sayAllHandler.CURSOR_CARET)
def script_readDocumentation(self, gesture): rootDocumentationWindow = None # If there aren't any suggestion selected, there is no way to find quick documentation if not self.appModule.selectedItem: gesture.send() return # Try to locate the documentation document try: rootDocumentationWindow = self.appModule.selectedItem.parent.parent.parent.parent.previous.previous except AttributeError: pass # In XML documents this is different, maybe in other editors too # so we try to locate the root window again if not rootDocumentationWindow or not rootDocumentationWindow.appModule == self.appModule: try: rootDocumentationWindow = self.appModule.selectedItem.parent.parent.parent.parent.previous except AttributeError: pass # Check if this object is from the same appModule if rootDocumentationWindow and rootDocumentationWindow.appModule == self.appModule: api.setNavigatorObject(rootDocumentationWindow) documentObj = rootDocumentationWindow while documentObj: if documentObj.firstChild: documentObj = documentObj.firstChild # In some editors the help document is a HTML ones # On XML documents, for example, it is a simple read-only editable text if documentObj.role in (controlTypes.ROLE_DOCUMENT, controlTypes.ROLE_EDITABLETEXT): break else: break if documentObj.role == controlTypes.ROLE_DOCUMENT: api.setNavigatorObject(documentObj) braille.handler.handleReviewMove() sayAllHandler.readText(sayAllHandler.CURSOR_REVIEW) elif documentObj.role == controlTypes.ROLE_EDITABLETEXT: ui.message(documentObj.value) else: # Translators: When the help popup cannot be found for the selected autocompletion item ui.message(_("Cann't find the documentation window."))
def script_sayall(self, gesture, fromQuickNav=False): speech.cancelSpeech() if self.markerQuery.sayName: speech.speakMessage(self.markerQuery.name) treeInterceptor = html.getTreeInterceptor() if not treeInterceptor: return speechOff() treeInterceptor.passThrough = False browseMode.reportPassThrough.last = treeInterceptor.passThrough self.node.moveto() html.speakLine() speechOn() sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
def script_sayall(self, gesture, fromQuickNav=False): speech.cancelSpeech() if self.markerQuery.sayName: speech.speakMessage(self.markerQuery.label) treeInterceptor = html.getTreeInterceptor() if not treeInterceptor: return speechMode = speech.speechMode try: speech.speechMode = speech.speechMode_off treeInterceptor.passThrough = False browseMode.reportPassThrough.last = treeInterceptor.passThrough self.node.moveto() html.speakLine() api.processPendingEvents() except: log.exception("Error during script_sayall") return finally: speech.speechMode = speechMode sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
def reportNewSlide(self): self.makeTextInfo(textInfos.POSITION_FIRST).updateCaret() sayAllHandler.readText(sayAllHandler.CURSOR_CARET)
def script_review_sayAll(self,gesture): info=api.getReviewPosition().copy() sayAllHandler.readText(info,sayAllHandler.CURSOR_REVIEW)
def sayAll(self): if self.moveto(): sayAllHandler.readText(sayAllHandler.CURSOR_CARET) return True else: return False