def setCurrentMode(mode, updateReviewPosition=True): """ Sets the current review mode to the given mode ID or index and updates the review position. @param mode: either a 0-based index into the modes list, or one of the mode IDs (first item of a tuple in the modes list). @type mode: int or string @return: a presentable label for the new current mode (suitable for speaking or brailleing) @rtype: string """ global _currentMode if isinstance(mode, int): ID, label, func = modes[mode] else: for index, (ID, label, func) in enumerate(modes): if mode == ID: mode = index break else: raise LookupError("mode %s not found" % mode) obj = api.getNavigatorObject() pos = func(obj) if pos: _currentMode = mode if updateReviewPosition: api.setReviewPosition(pos[0], clearNavigatorObject=False) return label
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 handleCaretMove(pos): """ Instructs the review position to be updated due to caret movement. @param pos: Either a TextInfo instance at the caret position, or an NVDAObject or TeeInterceptor who's caret position should be retreaved. @type pos: L{textInfos.TextInfo} or L{NVDAObject} or L{TreeInterceptor} """ if not config.conf["reviewCursor"]["followCaret"]: return if isinstance(pos, textInfos.TextInfo): info = pos obj = pos.obj else: info = None obj = pos mode = getCurrentMode() if isinstance(obj, NVDAObject): if not mode == 'object' or obj != api.getNavigatorObject(): return elif isinstance(obj, DocumentTreeInterceptor): if mode not in ('object', 'document'): return if mode != 'document': if obj.passThrough: #if trying to set with a position in a treeInterceptor but passThrough is turned on, ignore it completely return setCurrentMode('document', updateReviewPosition=False) if not info: try: info = obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): return api.setReviewPosition(info, isCaret=True)
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 scriptHandler.isScriptWaiting (): return if not info: try: info = self.makeTextInfo (textInfos.POSITION_CARET) except: return if config.conf["reviewCursor"]["followCaret"] and api.getNavigatorObject() is self: api.setReviewPosition (info) if speakUnit == textInfos.UNIT_LINE and EditableLatex.processMaths: spokenLine = GetLine () #We don't need to get braille. It's handled by the region. if not spokenLine:# Is it a blank line? spokenLine = _("blank") else: self.speakMathLine(spokenLine) else: if speakUnit: info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET)
def handleCaretMove(pos): """ Instructs the review position to be updated due to caret movement. @param pos: Either a TextInfo instance at the caret position, or an NVDAObject or TeeInterceptor who's caret position should be retreaved. @type pos: L{textInfos.TextInfo} or L{NVDAObject} or L{TreeInterceptor} """ if not config.conf["reviewCursor"]["followCaret"]: return if isinstance(pos,textInfos.TextInfo): info=pos obj=pos.obj else: info=None obj=pos mode=getCurrentMode() if isinstance(obj,NVDAObject): if not mode=='object' or obj!=api.getNavigatorObject(): return elif isinstance(obj,DocumentTreeInterceptor): if mode not in ('object','document'): return if mode!='document': if obj.passThrough: #if trying to set with a position in a treeInterceptor but passThrough is turned on, ignore it completely return setCurrentMode('document',updateReviewPosition=False) if not info: try: info=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError,RuntimeError): return api.setReviewPosition(info)
def onOk(self, evt): try: self.Access8MathConfig["settings"]["language"] = list( available_languages_dict.keys())[ self.languageList.GetSelection()] self.Access8MathConfig["settings"][ "item_interval_time"] = self.item_interval_timeChoices[ self.item_interval_timeList.GetSelection()] for k in self.CheckBox_settings.keys(): self.Access8MathConfig["settings"][k] = getattr( self, k + "CheckBox").IsChecked() except: self.Access8MathConfig["settings"]["language"] = "en" self.Access8MathConfig["settings"]["item_interval_time"] = 50 for k in self.CheckBox_settings.keys(): self.Access8MathConfig["settings"][k] = True tones.beep(100, 100) # _config.save() A8M_PM.initialize(self.Access8MathConfig) try: api.setReviewPosition( MathMlTextInfo(globalVars.math_obj, textInfos.POSITION_FIRST), False) except: pass return super(GeneralSettingsDialog, self).onOk(evt)
def script_reportStatusLine(self, gesture): #it seems that the status bar is the last child of the forground object #so, get it from there obj = api.getForegroundObject().lastChild found=False if obj and obj.role == controlTypes.ROLE_STATUSBAR: text = api.getStatusBarText(obj) api.setNavigatorObject(obj) found=True else: info=api.getForegroundObject().flatReviewPosition if info: info.expand(textInfos.UNIT_STORY) info.collapse(True) info.expand(textInfos.UNIT_LINE) text=info.text info.collapse() api.setReviewPosition(info) found=True if not found: # Translators: Reported when there is no status line for the current program or window. ui.message(_("No status line found")) return if scriptHandler.getLastScriptRepeatCount()==0: ui.message(text) else: speech.speakSpelling(text)
def script_navigate(self, gesture): r = False if gesture.mainKeyName in [ "downArrow", "upArrow", "leftArrow", "rightArrow", "home" ]: r = self.mathcontent.navigate(gesture.mainKeyName) if not r: if _config.Access8MathConfig["settings"]["no_move_beep"]: tones.beep(100, 100) else: speech.speak([_("no move")]) api.setReviewPosition(self.makeTextInfo(), False) if self.mathcontent.pointer.parent: if _config.Access8MathConfig["settings"][ "auto_generate"] and self.mathcontent.pointer.parent.role_level == A8M_PM.AUTO_GENERATE: speech.speak([self.mathcontent.pointer.des]) elif _config.Access8MathConfig["settings"][ "dictionary_generate"] and self.mathcontent.pointer.parent.role_level == A8M_PM.DIC_GENERATE: speech.speak([self.mathcontent.pointer.des]) else: speech.speak([self.mathcontent.pointer.des]) speech.speak( translate_SpeechCommand(self.mathcontent.pointer.serialized()))
def routeReviewToFocus (): obj=api.getFocusObject() try: pos=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError,RuntimeError): pos=obj.makeTextInfo(textInfos.POSITION_FIRST) api.setReviewPosition(pos)
def event_caret(self, obj, nextHandler): self.detectPossibleSelectionChange() braille.handler.handleCaretMove(self) caret = self.makeTextInfo(textInfos.POSITION_CARET) if config.conf["reviewCursor"][ "followCaret"] and api.getNavigatorObject( ) is self.rootNVDAObject: api.setReviewPosition(caret)
def script_review_startOfLine(self,gesture): info=api.getReviewPosition().copy() info.expand(textInfos.UNIT_LINE) info.collapse() api.setReviewPosition(info.copy()) info.expand(textInfos.UNIT_CHARACTER) speech.speakMessage(_("left")) speech.speakTextInfo(info,unit=textInfos.UNIT_CHARACTER,reason=speech.REASON_CARET)
def event_caret(self): if self is api.getFocusObject() and not eventHandler.isPendingEvents("gainFocus"): braille.handler.handleCaretMove(self) if config.conf["reviewCursor"]["followCaret"] and api.getNavigatorObject() is self: try: api.setReviewPosition(self.makeTextInfo(textInfos.POSITION_CARET)) except (NotImplementedError, RuntimeError): pass
def script_navigatorObject_toFocus(self,gesture): obj=api.getFocusObject() try: pos=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError,RuntimeError): pos=obj.makeTextInfo(textInfos.POSITION_FIRST) api.setReviewPosition(pos) speech.speakMessage(_("move to focus")) speech.speakObject(obj,reason=speech.REASON_QUERY)
def script_review_previousLine(self,gesture): info=api.getReviewPosition().copy() info.expand(textInfos.UNIT_LINE) info.collapse() res=info.move(textInfos.UNIT_LINE,-1) api.setReviewPosition(info.copy()) info.expand(textInfos.UNIT_LINE) if res==0: speech.speakMessage(_("top")) speech.speakTextInfo(info,unit=textInfos.UNIT_LINE,reason=speech.REASON_CARET)
def script_review_nextWord(self,gesture): info=api.getReviewPosition().copy() info.expand(textInfos.UNIT_WORD) info.collapse() res=info.move(textInfos.UNIT_WORD,1) api.setReviewPosition(info.copy()) info.expand(textInfos.UNIT_WORD) if res==0: speech.speakMessage(_("bottom")) speech.speakTextInfo(info,reason=speech.REASON_CARET,unit=textInfos.UNIT_WORD)
def event_caret(self): if self is api.getFocusObject() and not eventHandler.isPendingEvents( "gainFocus"): braille.handler.handleCaretMove(self) if config.conf["reviewCursor"][ "followCaret"] and api.getNavigatorObject() is self: try: api.setReviewPosition( self.makeTextInfo(textInfos.POSITION_CARET)) except (NotImplementedError, RuntimeError): pass
def searchTag_2014(nodeType, first=False, reverse=False, func=None, elementDescription=None, moveFocus=True): try: focus = api.getFocusObject() focus = focus.treeInterceptor if moveFocus: focus.passThrough = False virtualBuffers.reportPassThrough.last = False # pour que le changement de mode ne soit pas lu automatiquement if first: info = focus.makeTextInfo(textInfos.POSITION_FIRST) else: info = focus.makeTextInfo(textInfos.POSITION_CARET) startOffset = info._startOffset endOffset = info._endOffset ok = False while not ok: if reverse: node, startOffset, endOffset = previousTag( focus, nodeType, startOffset) else: node, startOffset, endOffset = nextTag(focus, nodeType, startOffset) info = focus.makeTextInfo( textInfos.offsets.Offsets(startOffset, endOffset)) if elementDescription is not None: obj = info.NVDAObjectAtStart ok = getElementDescription(obj).find(elementDescription) > 0 elif func is not None: ok = func(info) else: ok = True except: return False info = focus.makeTextInfo(textInfos.offsets.Offsets( startOffset, endOffset)) if func is not None: if not func(info): return False fieldInfo = info.copy() info.collapse() info.move(textInfos.UNIT_LINE, 1, endPoint="end") if info.compareEndPoints(fieldInfo, "endToEnd") > 0: # We've expanded past the end of the field, so limit to the end of the field. info.setEndPoint(fieldInfo, "endToEnd") info.collapse() if moveFocus: focus._set_selection(info) api.setReviewPosition(info) return True
def _caretScriptPostMovedHelper(self, speakUnit): if isScriptWaiting(): return try: info = self.makeTextInfo(textInfos.POSITION_CARET) except: return if config.conf["reviewCursor"]["followCaret"] and api.getNavigatorObject() is self: api.setReviewPosition(info.copy()) if speakUnit: info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=speech.REASON_CARET)
def script_navigatorObject_moveToFlatReviewAtObjectPosition(self,gesture): obj=api.getNavigatorObject() pos=obj.flatReviewPosition if pos: api.setReviewPosition(pos) pos=pos.copy() obj=api.getNavigatorObject() speech.speakObjectProperties(obj,name=True,role=True) pos.expand(textInfos.UNIT_LINE) speech.speakTextInfo(pos) else: speech.speakMessage(_("No flat review for this object"))
def searchTag_2015(nodeType, info=None, id=None, className=None, src=None, text=None, first=False, reverse=False, func=None, max=None, moveFocus=False): if True: focus = getTreeInterceptor() dir = "next" if not reverse else "previous" if info is None: if first: info=focus.makeTextInfo(textInfos.POSITION_FIRST) else: info=focus.makeTextInfo(textInfos.POSITION_CARET) startOffset=info._startOffset endOffset=info._endOffset ok = False while not ok: item = oneStepTagSearch(dir, focus, nodeType, info) if item is None: return None info = focus.makeTextInfo(textInfos.offsets.Offsets(item.textInfo._startOffset, item.textInfo._endOffset)) if text is not None: if isinstance(text, tuple) or isinstance(text, list): texts = text else: texts = [text] for text in texts: if text in info.text: ok = True elif id is not None or className is not None or src is not None: obj = info.NVDAObjectAtStart ok = parentsContainsAttributes (obj, id=id, className=className, src=src, max=max) elif func is not None: ok = func(info) else: ok = True else: #except Exception as e: #log.exception("searchTag exception: %s" % e) return None return info info = focus.makeTextInfo(textInfos.offsets.Offsets(item.textInfo._startOffset, item.textInfo._endOffset)) if func is not None: if not func(info): return None fieldInfo = info.copy() info.collapse() info.move(textInfos.UNIT_LINE, 1, endPoint="end") if info.compareEndPoints(fieldInfo, "endToEnd") > 0: # We've expanded past the end of the field, so limit to the end of the field. info.setEndPoint(fieldInfo, "endToEnd") info.collapse() if moveFocus: item.moveTo() api.setReviewPosition(info) return info
def _caretScriptPostMovedHelper(self, speakUnit, info=None): if isScriptWaiting(): return if not info: try: info = self.makeTextInfo(textInfos.POSITION_CARET) except: return if config.conf["reviewCursor"]["followCaret"] and api.getNavigatorObject() is self: api.setReviewPosition(info) if speakUnit: info.expand(speakUnit) speech.speakTextInfo(info, unit=speakUnit, reason=controlTypes.REASON_CARET)
def lineReached(self, obj, bookmark, state): # We've just started speaking this line, so move the cursor there. state.updateObj() updater = obj.makeTextInfo(bookmark) if self.cursor == CURSOR_CARET: updater.updateCaret() if self.cursor != CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]: api.setReviewPosition(updater, isCaret=self.cursor==CURSOR_CARET) if self.numBufferedLines == 0: # This was the last line spoken, so move on. self.nextLine() else: self.numBufferedLines -= 1
def moveTo(self, x, y, new=False, unit=textInfos.UNIT_LINE): obj = api.getDesktopObject().objectFromPoint(x, y) prevObj = None while obj and obj.beTransparentToMouse: prevObj = obj obj = obj.parent if not obj or (obj.presentationType != obj.presType_content and obj.role != controlTypes.ROLE_PARAGRAPH): obj = prevObj if not obj: return hasNewObj = False if obj != self._obj: self._obj = obj hasNewObj = True if self.updateReview: api.setNavigatorObject(obj) else: obj = self._obj pos = None if obj.treeInterceptor: try: pos = obj.treeInterceptor.makeTextInfo(obj) except LookupError: pos = None if pos: obj = obj.treeInterceptor.rootNVDAObject if hasNewObj and self._obj and obj.treeInterceptor is self._obj.treeInterceptor: hasNewObj = False if not pos: try: pos = obj.makeTextInfo(locationHelper.Point(x, y)) except (NotImplementedError, LookupError): pass if pos: pos.expand(unit) if pos and self.updateReview: api.setReviewPosition(pos) speechCanceled = False if hasNewObj: speech.cancelSpeech() speechCanceled = True speech.speakObject(obj) if pos and (new or not self._pos or pos.__class__ != self._pos.__class__ or pos.compareEndPoints(self._pos, "startToStart") != 0 or pos.compareEndPoints(self._pos, "endToEnd") != 0): self._pos = pos if not speechCanceled: speech.cancelSpeech() speech.speakTextInfo(pos, reason=controlTypes.OutputReason.CARET)
def script_review_nextCharacter(self,gesture): lineInfo=api.getReviewPosition().copy() lineInfo.expand(textInfos.UNIT_LINE) charInfo=api.getReviewPosition().copy() charInfo.expand(textInfos.UNIT_CHARACTER) charInfo.collapse() res=charInfo.move(textInfos.UNIT_CHARACTER,1) if res==0 or charInfo.compareEndPoints(lineInfo,"endToEnd")>=0: speech.speakMessage(_("right")) reviewInfo=api.getReviewPosition().copy() reviewInfo.expand(textInfos.UNIT_CHARACTER) speech.speakTextInfo(reviewInfo,unit=textInfos.UNIT_CHARACTER,reason=speech.REASON_CARET) else: api.setReviewPosition(charInfo.copy()) charInfo.expand(textInfos.UNIT_CHARACTER) speech.speakTextInfo(charInfo,unit=textInfos.UNIT_CHARACTER,reason=speech.REASON_CARET)
def __init__(self, mathMl, interaction_frame=False): super(MathMlReaderInteraction, self).__init__(mathMl=mathMl) tree = mathml2etree(mathMl) globalVars.math_obj = self self.mathcontent = MathContent(A8M_PM.mathrule, tree) globalVars.mathcontent = self.mathcontent self.raw_data = mathMl api.setReviewPosition(self.makeTextInfo(), False) self.interactionFrame = None if convert_bool(os.environ['IFS']) or interaction_frame: self.interactionFrame = InteractionFrame(self) self.interactionFrame.Show() self.interactionFrame.Raise() self.setFocus()
def onOk(self,evt): try: for k in self.CheckBox_settings.keys(): config.conf["Access8Math"][k] = os.environ[k] = unicode(getattr(self, k +"CheckBox").IsChecked()) except: configure.initialize_config() for k in self.CheckBox_settings.keys(): config.conf["Access8Math"][k] = os.environ[k] = unicode(getattr(self, k +"CheckBox").IsChecked()) A8M_PM.config_from_environ() try: api.setReviewPosition(MathMlTextInfo(globalVars.math_obj, textInfos.POSITION_FIRST), False) except: pass return super(RuleSettingsDialog, self).onOk(evt)
def moveTo(self,x,y,new=False,unit=textInfos.UNIT_LINE): obj=api.getDesktopObject().objectFromPoint(x,y) prevObj=None while obj and obj.beTransparentToMouse: prevObj=obj obj=obj.parent if not obj or (obj.presentationType!=obj.presType_content and obj.role!=controlTypes.ROLE_PARAGRAPH): obj=prevObj if not obj: return hasNewObj=False if obj!=self._obj: self._obj=obj hasNewObj=True if self.updateReview: api.setNavigatorObject(obj) else: obj=self._obj pos=None if obj.treeInterceptor: try: pos=obj.treeInterceptor.makeTextInfo(obj) except LookupError: pos=None if pos: obj=obj.treeInterceptor.rootNVDAObject if hasNewObj and self._obj and obj.treeInterceptor is self._obj.treeInterceptor: hasNewObj=False if not pos: try: pos=obj.makeTextInfo(textInfos.Point(x,y)) except (NotImplementedError,LookupError): pass if pos: pos.expand(unit) if pos and self.updateReview: api.setReviewPosition(pos) speechCanceled=False if hasNewObj: speech.cancelSpeech() speechCanceled=True speech.speakObject(obj) if pos and (new or not self._pos or pos.__class__!=self._pos.__class__ or pos.compareEndPoints(self._pos,"startToStart")!=0 or pos.compareEndPoints(self._pos,"endToEnd")!=0): self._pos=pos if not speechCanceled: speech.cancelSpeech() speech.speakTextInfo(pos,reason=controlTypes.REASON_CARET)
def onOk(self,evt): try: for k in self.CheckBox_settings.keys(): self.Access8MathConfig["rules"][k] = getattr(self, k +"CheckBox").IsChecked() except: for k in self.CheckBox_settings.keys(): self.Access8MathConfig["rules"][k] = True tones.beep(100, 100) A8M_PM.initialize(self.Access8MathConfig) try: api.setReviewPosition(MathMlTextInfo(globalVars.math_obj, textInfos.POSITION_FIRST), False) except: pass return super(RuleSettingsDialog, self).onOk(evt)
def onOk(self, evt): try: self.Access8MathConfig["settings"]["language"] = list( available_languages_dict.keys())[ self.languageList.GetSelection()] self.Access8MathConfig["settings"][ "item_interval_time"] = self.item_interval_timeChoices[ self.item_interval_timeList.GetSelection()] for k in self.CheckBox_settings.keys(): self.Access8MathConfig["settings"][k] = getattr( self, k + "CheckBox").IsChecked() except: self.Access8MathConfig["settings"]["language"] = "en" self.Access8MathConfig["settings"]["item_interval_time"] = 50 for k in self.CheckBox_settings.keys(): self.Access8MathConfig["settings"][k] = True tones.beep(100, 100) # _config.save() A8M_PM.initialize(self.Access8MathConfig) try: api.setReviewPosition( MathMlTextInfo(globalVars.math_obj, textInfos.POSITION_FIRST), False) except: pass if self.edit_NVDA_gesture != self.Access8MathConfig["settings"][ "edit_NVDA_gesture"]: if gui.messageBox( # Translators: The message displayed _("For the NVDA+gesture configuration to apply, NVDA must be restarted. Do you want to restart NVDA now?" ), # Translators: The title of the dialog _("NVDA+gesture Configuration Change"), wx.OK | wx.CANCEL | wx.ICON_WARNING, self) == wx.OK: queueHandler.queueFunction(queueHandler.eventQueue, core.restart) return super(GeneralSettingsDialog, self).onOk(evt)
def script_ocrNavigatorObject(self, gesture): nav = api.getNavigatorObject() left, top, width, height = nav.location img = ImageGrab.grab(bbox=(left, top, left + width, top + height)) # Tesseract copes better if we convert to black and white... img = img.convert(mode='L') # and increase the size. img = img.resize( (width * IMAGE_RESIZE_FACTOR, height * IMAGE_RESIZE_FACTOR), Image.BICUBIC) baseFile = os.path.join(tempfile.gettempdir(), "nvda_ocr") try: imgFile = baseFile + ".bmp" img.save(imgFile) ui.message(_("Running OCR")) lang = getConfig()['language'] # Hide the Tesseract window. si = subprocess.STARTUPINFO() si.dwFlags = subprocess.STARTF_USESHOWWINDOW si.wShowWindow = subprocess.SW_HIDE subprocess.check_call( (TESSERACT_EXE, imgFile, baseFile, "-l", lang, "hocr"), startupinfo=si) finally: try: os.remove(imgFile) except OSError: pass try: hocrFile = baseFile + ".html" parser = HocrParser( open(hocrFile, encoding='utf8').read(), left, top) finally: try: os.remove(hocrFile) except OSError: pass # Let the user review the OCR output. nav.makeTextInfo = lambda position: OcrTextInfo(nav, position, parser) api.setReviewPosition(nav.makeTextInfo(textInfos.POSITION_FIRST)) ui.message(_("Done"))
def review(self, unit, direction, verbose=True): reviewOldMode = api.review.getCurrentMode() api.review.setCurrentMode("object") if self.reviewPosition: api.setReviewPosition(self.reviewPosition) info = api.getReviewPosition().copy() info.expand(unit) info.collapse() info.move(unit, direction) api.setReviewPosition(info) info.expand(unit) if verbose: speakTextInfo(info, unit=unit, reason=controlTypes.REASON_CARET if hasattr( controlTypes, "REASON_CARET") else controlTypes.OutputReason.CARET) self.reviewPosition = api.getReviewPosition() api.review.setCurrentMode(reviewOldMode) return info.move(unit, 1)
def script_downArrow(self, gesture): if self.objArrowMode == MODE_OBJNAV: commands.script_navigatorObject_firstChild(gesture) elif self.objArrowMode == MODE_WEB: self.webBrowseMode = (self.webBrowseMode + 1) % len( self.webBrowseElements) ui.message(self.webBrowseElements[self.webBrowseMode]) elif self.objArrowMode == MODE_SCANMODE: # Navigate to next line if possible. info = api.getReviewPosition().copy() info.expand(textInfos.UNIT_LINE) info.collapse() res = info.move(textInfos.UNIT_LINE, 1) if res != 0: api.setReviewPosition(info) info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=controlTypes.REASON_CARET) else: curObject = api.getNavigatorObject() newObject = None if curObject.simpleFirstChild: newObject = curObject.simpleFirstChild elif curObject.simpleNext: newObject = curObject.simpleNext elif curObject.simpleParent: parent = curObject.simpleParent while parent and not parent.simpleNext: parent = parent.simpleParent # As long as one is on current foreground object... #Stay within the current top-level window. if parent and parent.simpleParent != api.getDesktopObject( ): newObject = parent.simpleNext if newObject: api.setNavigatorObject(newObject) speech.speakObject(newObject, reason=controlTypes.REASON_FOCUS) else: # Translators: a message when there is no next object when navigating ui.reviewMessage(_("No next"))
def readTextHelper_generator(info,cursor): sendCount=0 receiveCount=0 cursorIndexMap={} reader=info.copy() if not reader.isCollapsed: reader.collapse() keepReading=True keepUpdating=True oldSpokenIndex=None while keepUpdating: if not reader.obj: # The object died, so we should too. return # receiveCount might be None if other speech was interspersed with this say all. # In this case, we want to send more text in case this was the last chunk spoken. if receiveCount is None or (sendCount-receiveCount)<=10: if keepReading: bookmark=reader.bookmark index=sendCount delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end") if delta<=0: keepReading=False continue speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=speech.REASON_SAYALL,index=index) sendCount+=1 cursorIndexMap[index]=bookmark reader.collapse(end=True) spokenIndex=speech.getLastSpeechIndex() if spokenIndex!=oldSpokenIndex: oldSpokenIndex=spokenIndex receiveCount=spokenIndex bookmark=cursorIndexMap.get(spokenIndex,None) if bookmark is not None: updater=reader.obj.makeTextInfo(bookmark) if cursor==CURSOR_CARET: updater.updateCaret() if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]: api.setReviewPosition(updater) while speech.isPaused: yield yield
def onOk(self,evt): try: config.conf["Access8Math"]["language"] = os.environ['LANGUAGE'] = list(available_languages_dict.keys())[self.languageList.GetSelection()] config.conf["Access8Math"]["item_interval_time"] = os.environ['item_interval_time'] = self.item_interval_timeChoices[self.item_interval_timeList.GetSelection()] for k in self.CheckBox_settings.keys(): config.conf["Access8Math"][k] = os.environ[k] = unicode(getattr(self, k +"CheckBox").IsChecked()) except: configure.initialize_config() config.conf["Access8Math"]["language"] = os.environ['LANGUAGE'] = list(available_languages_dict.keys())[self.languageList.GetSelection()] config.conf["Access8Math"]["item_interval_time"] = os.environ['item_interval_time'] = self.item_interval_timeChoices[self.item_interval_timeList.GetSelection()] for k in self.CheckBox_settings.keys(): config.conf["Access8Math"][k] = os.environ[k] = unicode(getattr(self, k +"CheckBox").IsChecked()) A8M_PM.config_from_environ() try: api.setReviewPosition(MathMlTextInfo(globalVars.math_obj, textInfos.POSITION_FIRST), False) except: pass return super(GeneralSettingsDialog, self).onOk(evt)
def script_modified_review_nextCharacter(self, gesture): #Add character description Braille output to the review character when Braille review mode is turned on. lineInfo = api.getReviewPosition().copy() lineInfo.expand(textInfos.UNIT_LINE) charInfo = api.getReviewPosition().copy() charInfo.expand(textInfos.UNIT_CHARACTER) charInfo.collapse() res = charInfo.move(textInfos.UNIT_CHARACTER, 1) if res == 0 or charInfo.compareEndPoints(lineInfo, "endToEnd") >= 0: ui.reviewMessage(_("Right")) reviewInfo = api.getReviewPosition().copy() reviewInfo.expand(textInfos.UNIT_CHARACTER) speech.speakTextInfo(reviewInfo, unit=textInfos.UNIT_CHARACTER, reason=controlTypes.OutputReason.CARET) char = reviewInfo.text.lower() if not isAlphanumeric(char) and CJK["brailleReview"] == "Auto": try: charDesc = characterProcessing.getCharacterDescription( CJK["locale"], char) BrailleHandler.message(handler, char + " " + " ".join(charDesc)) except TypeError: pass else: api.setReviewPosition(charInfo) charInfo.expand(textInfos.UNIT_CHARACTER) speech.speakTextInfo(charInfo, unit=textInfos.UNIT_CHARACTER, reason=controlTypes.OutputReason.CARET) char = charInfo.text.lower() if not isAlphanumeric(char) and CJK["brailleReview"] == "Auto": try: charDesc = characterProcessing.getCharacterDescription( CJK["locale"], char) BrailleHandler.message(handler, char + " " + " ".join(charDesc)) except TypeError: pass
def script_upArrow(self, gesture): if self.objArrowMode == MODE_OBJNAV: commands.script_navigatorObject_parent(gesture) elif self.objArrowMode == MODE_WEB: self.webBrowseMode = (self.webBrowseMode - 1) % len( self.webBrowseElements) ui.message(self.webBrowseElements[self.webBrowseMode]) elif self.objArrowMode == MODE_SCANMODE: # Move to previous line first so text can be reviewed before resorting to a new object. info = api.getReviewPosition().copy() info.expand(textInfos.UNIT_LINE) info.collapse() res = info.move(textInfos.UNIT_LINE, -1) if res != 0: api.setReviewPosition(info) info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=controlTypes.REASON_CARET) else: # Do not move outside of the current window. curObject = api.getNavigatorObject() newObject = None if curObject.parent != api.getDesktopObject(): newObject = curObject.simplePrevious if newObject: while newObject.simpleLastChild: newObject = newObject.simpleLastChild else: newObject = curObject.simpleParent if newObject: api.setNavigatorObject(newObject) speech.speakObject(newObject, reason=controlTypes.REASON_FOCUS) else: # Translators: a message when there is no previous object when navigating ui.reviewMessage(_("No previous"))
def callback(column): speech.cancelSpeech() comboBox = self._getSearchEditComboBoxObject() api.setNavigatorObject(comboBox) review.setCurrentMode("screen", updateReviewPosition=True) info = api.getReviewPosition().copy() info.collapse() info.expand(textInfos.UNIT_LINE) baseInfo = info.copy() info.collapse(True) api.setReviewPosition(info) curObject = api.getNavigatorObject() if curObject.role == ROLE_LISTITEM: info = baseInfo.copy() info.collapse() api.setReviewPosition(info) curObject = api.getNavigatorObject() columnHeaders = curObject.parent.children columnObj = columnHeaders[column - 1] if columnObj is None: log.error("Cannot found stations list column object:%s" % column) return name = columnObj.name[1:] if columnObj.name[ 0] == "*" else columnObj.name ui.message(name) time.sleep(0.5) location = columnObj.location (l, t, w, h) = location i = int(l + w - 10) j = int(t + h / 2) import winUser winUser.setCursorPos(i, j) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTDOWN, 0, 0, None, None) winUser.mouse_event(winUser.MOUSEEVENTF_RIGHTUP, 0, 0, None, None)
def script_navigate(self, gesture): r = False if gesture.mainKeyName in [ "downArrow", "upArrow", "leftArrow", "rightArrow", "home" ]: r = self.mathcontent.navigate(gesture.mainKeyName) if r: api.setReviewPosition(self.makeTextInfo(), False) if self.mathcontent.pointer.parent: if convert_bool( os.environ['AG'] ) and self.mathcontent.pointer.parent.role_level == A8M_PM.AUTO_GENERATE: speech.speak([self.mathcontent.pointer.des]) elif convert_bool( os.environ['DG'] ) and self.mathcontent.pointer.parent.role_level == A8M_PM.DIC_GENERATE: speech.speak([self.mathcontent.pointer.des]) else: speech.speak([self.mathcontent.pointer.des]) speech.speak( translate_SpeechCommand(self.mathcontent.pointer.serialized())) else: speech.speak([_("not move")])
def setCurrentMode(mode,updateReviewPosition=True): """ Sets the current review mode to the given mode ID or index and updates the review position. @param mode: either a 0-based index into the modes list, or one of the mode IDs (first item of a tuple in the modes list). @type mode: int or string @return: a presentable label for the new current mode (suitable for speaking or brailleing) @rtype: string """ global _currentMode if isinstance(mode,int): ID,label,func=modes[mode] else: for index,(ID,label,func) in enumerate(modes): if mode==ID: mode=index break else: raise LookupError("mode %s not found"%mode) obj=api.getNavigatorObject() pos=func(obj) if pos: _currentMode=mode if updateReviewPosition: api.setReviewPosition(pos[0],clearNavigatorObject=False) return label
def script_review_bottom(self,gesture): info=api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_LAST) api.setReviewPosition(info.copy()) info.expand(textInfos.UNIT_LINE) speech.speakMessage(_("bottom")) speech.speakTextInfo(info,unit=textInfos.UNIT_LINE,reason=speech.REASON_CARET)
def readTextHelper_generator(cursor): if cursor==CURSOR_CARET: try: reader=api.getCaretObject().makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): return else: reader=api.getReviewPosition() lastSentIndex=0 lastReceivedIndex=0 cursorIndexMap={} keepReading=True while True: if not reader.obj: # The object died, so we should too. return # lastReceivedIndex might be None if other speech was interspersed with this say all. # In this case, we want to send more text in case this was the last chunk spoken. if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=10: if keepReading: bookmark=reader.bookmark index=lastSentIndex+1 delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end") if delta<=0: speech.speakWithoutPauses(None) keepReading=False continue speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=controlTypes.REASON_SAYALL,index=index) lastSentIndex=index cursorIndexMap[index]=bookmark try: reader.collapse(end=True) except RuntimeError: #MS Word when range covers end of document speech.speakWithoutPauses(None) keepReading=False else: # We'll wait for speech to catch up a bit before sending more text. if speech.speakWithoutPauses.lastSentIndex is None or (lastSentIndex-speech.speakWithoutPauses.lastSentIndex)>=10: # There is a large chunk of pending speech # Force speakWithoutPauses to send text to the synth so we can move on. speech.speakWithoutPauses(None) receivedIndex=speech.getLastSpeechIndex() if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): lastReceivedIndex=receivedIndex bookmark=cursorIndexMap.get(receivedIndex,None) if bookmark is not None: updater=reader.obj.makeTextInfo(bookmark) if cursor==CURSOR_CARET: updater.updateCaret() if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]: api.setReviewPosition(updater) elif not keepReading and lastReceivedIndex==lastSentIndex: # All text has been spoken. # Turn the page and start again if the object supports it. if isinstance(reader.obj,textInfos.DocumentWithPageTurns): try: reader.obj.turnPage() except RuntimeError: break else: reader=reader.obj.makeTextInfo(textInfos.POSITION_FIRST) keepReading=True else: break while speech.isPaused: yield yield
def event_caret(self, obj, nextHandler): self.detectPossibleSelectionChange() braille.handler.handleCaretMove(self) caret = self.makeTextInfo(textInfos.POSITION_CARET) if config.conf["reviewCursor"]["followCaret"] and api.getNavigatorObject() is self.rootNVDAObject: api.setReviewPosition(caret)
def _setCursor(self, info): api.setReviewPosition(info)
def event_appModule_loseFocus(self): if not config.conf["reviewCursor"]["followFocus"]: api.setReviewPosition(self._oldReviewPos) del self._oldReviewPos, self._oldReviewObj inputCore.manager._captureFunc = None
def readTextHelper_generator(cursor): if cursor==CURSOR_CARET: try: reader=api.getCaretObject().makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): return else: reader=api.getReviewPosition() lastSentIndex=0 lastReceivedIndex=0 cursorIndexMap={} keepReading=True speakTextInfoState=speech.SpeakTextInfoState(reader.obj) with SayAllProfileTrigger(): while True: if not reader.obj: # The object died, so we should too. return # lastReceivedIndex might be None if other speech was interspersed with this say all. # In this case, we want to send more text in case this was the last chunk spoken. if lastReceivedIndex is None or (lastSentIndex-lastReceivedIndex)<=10: if keepReading: bookmark=reader.bookmark index=lastSentIndex+1 delta=reader.move(textInfos.UNIT_READINGCHUNK,1,endPoint="end") if delta<=0: speech.speakWithoutPauses(None) keepReading=False continue speech.speakTextInfo(reader,unit=textInfos.UNIT_READINGCHUNK,reason=controlTypes.REASON_SAYALL,index=index,useCache=speakTextInfoState) lastSentIndex=index cursorIndexMap[index]=(bookmark,speakTextInfoState.copy()) try: reader.collapse(end=True) except RuntimeError: #MS Word when range covers end of document # Word specific: without this exception to indicate that further collapsing is not posible, say-all could enter an infinite loop. speech.speakWithoutPauses(None) keepReading=False else: # We'll wait for speech to catch up a bit before sending more text. if speech.speakWithoutPauses.lastSentIndex is None or (lastSentIndex-speech.speakWithoutPauses.lastSentIndex)>=10: # There is a large chunk of pending speech # Force speakWithoutPauses to send text to the synth so we can move on. speech.speakWithoutPauses(None) receivedIndex=speech.getLastSpeechIndex() if receivedIndex!=lastReceivedIndex and (lastReceivedIndex!=0 or receivedIndex!=None): lastReceivedIndex=receivedIndex bookmark,state=cursorIndexMap.get(receivedIndex,(None,None)) if state: state.updateObj() if bookmark is not None: updater=reader.obj.makeTextInfo(bookmark) if cursor==CURSOR_CARET: updater.updateCaret() if cursor!=CURSOR_CARET or config.conf["reviewCursor"]["followCaret"]: api.setReviewPosition(updater) elif not keepReading and lastReceivedIndex==lastSentIndex: # All text has been sent to the synth. # Turn the page and start again if the object supports it. if isinstance(reader.obj,textInfos.DocumentWithPageTurns): try: reader.obj.turnPage() except RuntimeError: break else: reader=reader.obj.makeTextInfo(textInfos.POSITION_FIRST) keepReading=True else: break while speech.isPaused: yield yield # Wait until the synth has actually finished speaking. # Otherwise, if there is a triggered profile with a different synth, # we will switch too early and truncate speech (even up to several lines). # Send another index and wait for it. index=lastSentIndex+1 speech.speak([speech.IndexCommand(index)]) while speech.getLastSpeechIndex()<index: yield yield # Some synths say they've handled the index slightly sooner than they actually have, # so wait a bit longer. for i in xrange(30): yield
def updateCaret(self, updater: textInfos.TextInfo) -> None: updater.updateCaret() if config.conf["reviewCursor"]["followCaret"]: api.setReviewPosition(updater, isCaret=True)
def updateCaret(self, updater: textInfos.TextInfo) -> None: api.setReviewPosition(updater, isCaret=False)