def sayCurrentLine(): global instanceGP if not braille.handler._auto_scroll: if getTether() == braille.handler.TETHER_REVIEW: if config.conf["brailleExtender"]["speakScroll"] in [ addoncfg.CHOICE_focusAndReview, addoncfg.CHOICE_review ]: scriptHandler.executeScript( globalCommands.commands.script_review_currentLine, None) return if config.conf["brailleExtender"]["speakScroll"] in [ addoncfg.CHOICE_focusAndReview, addoncfg.CHOICE_focus ]: obj = api.getFocusObject() treeInterceptor = obj.treeInterceptor if isinstance(treeInterceptor, treeInterceptorHandler.DocumentTreeInterceptor ) and not treeInterceptor.passThrough: obj = treeInterceptor try: info = obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): info = obj.makeTextInfo(textInfos.POSITION_FIRST) info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=REASON_CARET)
def script_caret_newLine(self,gesture): try: info=self.makeTextInfo(textInfos.POSITION_CARET) except: gesture.send() return bookmark=info.bookmark gesture.send() caretMoved,newInfo=self._hasCaretMoved(bookmark) if not caretMoved or not newInfo: return # newInfo.copy should be good enough here, but in MS Word we get strange results. try: lineInfo=self.makeTextInfo(textInfos.POSITION_CARET) except (RuntimeError,NotImplementedError): return lineInfo.expand(textInfos.UNIT_LINE) if not self.announceEntireNewLine: lineInfo.setEndPoint(newInfo,"endToStart") if lineInfo.isCollapsed: lineInfo.expand(textInfos.UNIT_CHARACTER) onlyInitial=True else: onlyInitial=False speech.speakTextInfo(lineInfo,unit=textInfos.UNIT_LINE,reason=controlTypes.REASON_CARET,onlyInitialFields=onlyInitial,suppressBlanks=True)
def script_moveToParent(self, gesture): # Make sure we're in a editable control focus = api.getFocusObject() if focus.role != controlTypes.ROLE_EDITABLETEXT: ui.message("Not in an edit control.") return # Get the current indentation level textInfo = focus.makeTextInfo(textInfos.POSITION_CARET) textInfo.expand(textInfos.UNIT_LINE) indentationLevel = len(textInfo.text) - len(textInfo.text.strip()) onEmptyLine = len(textInfo.text) == 1 #1 because an empty line will have the \n character # Scan each line until we hit the start of the indentation block, the start of the edit area, or find a line with less indentation level found = False while textInfo.move(textInfos.UNIT_LINE, -2) == -2: textInfo.expand(textInfos.UNIT_LINE) newIndentation = len(textInfo.text) - len(textInfo.text.strip()) # Skip over empty lines if we didn't start on one. if not onEmptyLine and len(textInfo.text) == 1: continue if newIndentation < indentationLevel: # Found it found = True textInfo.updateCaret() speech.speakTextInfo(textInfo, unit=textInfos.UNIT_LINE) break # If we didn't find it, tell the user if not found: ui.message("No parent of indentation block")
def _tableMovementScriptHelper(self, movement: _Movement = _Movement.NEXT, axis: Optional[_Axis] = None): # documentBase is a core module and should not depend on these UI modules and so they are imported # at run-time. (#12404) from scriptHandler import isScriptWaiting from speech import speakTextInfo if isScriptWaiting(): return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = True try: _cell, info, tableSelection = self._tableFindNewCell( movement, axis, ) except LookupError: # _tableFindNewCell already spoke proper error message return speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.OutputReason.CARET) info.collapse() self.selection = info self._lastTableSelection = tableSelection
def script_caret_newLine(self, gesture): try: info = self.makeTextInfo(textInfos.POSITION_CARET) except: gesture.send() return bookmark = info.bookmark gesture.send() caretMoved, newInfo = self._hasCaretMoved(bookmark) if not caretMoved or not newInfo: return # newInfo.copy should be good enough here, but in MS Word we get strange results. try: lineInfo = self.makeTextInfo(textInfos.POSITION_CARET) except (RuntimeError, NotImplementedError): return lineInfo.expand(textInfos.UNIT_LINE) lineInfo.setEndPoint(newInfo, "endToStart") if lineInfo.isCollapsed: lineInfo.expand(textInfos.UNIT_CHARACTER) onlyInitial = True else: onlyInitial = False speech.speakTextInfo(lineInfo, unit=textInfos.UNIT_LINE, reason=controlTypes.REASON_CARET, onlyInitialFields=onlyInitial, suppressBlanks=True)
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 _tableMovementScriptHelper(self, movement="next", axis=None): if isScriptWaiting(): return formatConfig=config.conf["documentFormatting"].copy() formatConfig["reportTables"]=True formatConfig["includeLayoutTables"]=True try: tableID, origRow, origCol, origRowSpan, origColSpan = self._getTableCellCoords(self.selection) except LookupError: # Translators: The message reported when a user attempts to use a table movement command # when the cursor is not within a table. ui.message(_("Not in a table cell")) return try: info = self._getNearestTableCell(tableID, self.selection, origRow, origCol, origRowSpan, origColSpan, movement, axis) except LookupError: # Translators: The message reported when a user attempts to use a table movement command # but the cursor can't be moved in that direction because it is at the edge of the table. ui.message(_("Edge of table")) # Retrieve the cell on which we started. info = next(self._iterTableCells(tableID, row=origRow, column=origCol)) speech.speakTextInfo(info,formatConfig=formatConfig,reason=controlTypes.REASON_CARET) info.collapse() self.selection = info
def speakColumn(selfself, gesture): movement = "next" axis = "row" from scriptHandler import isScriptWaiting if isScriptWaiting(): return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = True try: tableID, origRow, origCol, origRowSpan, origColSpan = selfself._getTableCellCoords( selfself.selection) info = selfself._getTableCellAt(tableID, selfself.selection, origRow, origCol) except LookupError: # Translators: The message reported when a user attempts to use a table movement command # when the cursor is not within a table. ui.message(_("Not in a table cell")) return MAX_TABLE_DIMENSION = 500 for attempt in range(MAX_TABLE_DIMENSION): speech.speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.REASON_CARET) tableID, origRow, origCol, origRowSpan, origColSpan = selfself._getTableCellCoords( info) try: info = selfself._getNearestTableCell(tableID, info, origRow, origCol, origRowSpan, origColSpan, movement, axis) except LookupError: break
def script_reportCurrentLine (self, gesture): """ This script reports the line that the current navigator object is focused on, and speaks/brailles it appropriately depending on the state of l{processMaths}. If pressed twice quickly, the current line is spelt out. @param gesture: the gesture to be passed through to NVDA (in this case, a keypress). @type gesture: l{inputCore.InputGesture}. """ obj=api.getFocusObject() treeInterceptor=obj.treeInterceptor if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough: obj=treeInterceptor try: info=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): info=obj.makeTextInfo(textInfos.POSITION_FIRST) info.expand(textInfos.UNIT_LINE) if getLastScriptRepeatCount()==0: if EditableText.processMaths: 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: speech.speakTextInfo(info,unit=textInfos.UNIT_LINE,reason=controlTypes.REASON_CARET) else: speech.speakSpelling(info.text)
def _tableMovementScriptHelper(self, movement="next", axis=None): if isScriptWaiting(): return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = True formatConfig["includeLayoutTables"] = True try: tableID, origRow, origCol, origRowSpan, origColSpan = self._getTableCellCoords( self.selection) except LookupError: # Translators: The message reported when a user attempts to use a table movement command # when the cursor is not within a table. ui.message(_("Not in a table cell")) return try: info = self._getNearestTableCell(tableID, self.selection, origRow, origCol, origRowSpan, origColSpan, movement, axis) except LookupError: # Translators: The message reported when a user attempts to use a table movement command # but the cursor can't be moved in that direction because it is at the edge of the table. ui.message(_("edge of table")) # Retrieve the cell on which we started. info = next( self._iterTableCells(tableID, row=origRow, column=origCol)) speech.speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.REASON_CARET) info.collapse() self.selection = info
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 _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 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 script_review_currentWord(self,gesture): info=api.getReviewPosition().copy() info.expand(textInfos.UNIT_WORD) scriptCount=scriptHandler.getLastScriptRepeatCount() if scriptCount==0: speech.speakTextInfo(info,reason=speech.REASON_CARET,unit=textInfos.UNIT_WORD) else: speech.speakSpelling(info.text,useCharacterDescriptions=bool(scriptCount>1))
def script_caret_moveByCell(self,gesture): gesture.send() info=self.makeTextInfo(textInfos.POSITION_SELECTION) inTable=info._rangeObj.tables.count>0 isCollapsed=info.isCollapsed if inTable: info.expand(textInfos.UNIT_CELL) speech.speakTextInfo(info,reason=controlTypes.REASON_FOCUS) braille.handler.handleCaretMove(self)
def script_tab(self,gesture): oldBookmark=self.rootNVDAObject.makeTextInfo(textInfos.POSITION_SELECTION).bookmark gesture.send() noTimeout,newInfo=self.rootNVDAObject._hasCaretMoved(oldBookmark,timeout=1) if not newInfo: return info=self.makeTextInfo(textInfos.POSITION_SELECTION) if not info.isCollapsed: speech.speakTextInfo(info,reason=controlTypes.REASON_FOCUS)
def report(self,readUnit=None): info=self.textInfo if readUnit: fieldInfo = info.copy() info.collapse() info.move(readUnit, 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") speech.speakTextInfo(info, reason=controlTypes.REASON_FOCUS)
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 script_previousColumn(self,gesture): info=self.makeTextInfo("caret") if not info._rangeObj.Information(wdWithInTable): speech.speakMessage(_("not in table")) return if info._moveInTable(-1,0): info.updateCaret() info.expand(textInfos.UNIT_CELL) speech.speakTextInfo(info,reason=speech.REASON_CARET) else: speech.speakMessage(_("edge of table"))
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): 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 event_pageChange(self, obj, nextHandler): if self.pageChangeAlreadyHandled: # This page change has already been handled. self.pageChangeAlreadyHandled = False return info = self.makeTextInfo(textInfos.POSITION_FIRST) self.selection = info if not self.rootNVDAObject.hasFocus: # Don't report anything if the book area isn't focused. return info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=controlTypes.REASON_CARET)
def moveToBookmark(position): obj = api.getFocusObject() treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj = treeInterceptor bookmark = Offsets(position, position) info = obj.makeTextInfo(bookmark) info.updateSelection() review.handleCaretMove(info) speech.cancelSpeech() info.move(textInfos.UNIT_LINE,1,endPoint="end") speech.speakTextInfo(info,reason=controlTypes.REASON_CARET)
def doFindText(self,text,reverse=False): if not text: return info=self.makeTextInfo(textInfos.POSITION_CARET) res=info.find(text,reverse=reverse) if res: self.selection=info speech.cancelSpeech() info.move(textInfos.UNIT_LINE,1,endPoint="end") speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: wx.CallAfter(gui.messageBox,_('text "%s" not found')%text,_("Find Error"),wx.OK|wx.ICON_ERROR) CursorManager._lastFindText=text
def event_treeInterceptor_gainFocus(self): braille.handler.handleGainFocus(self) self.rootNVDAObject.reportFocus() if not self.hadFocusOnce: self.hadFocusOnce=True self.reportNewSlide() else: info = self.selection if not info.isCollapsed: speech.speakSelectionMessage(_("selected %s"), info.text) else: info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, reason=controlTypes.REASON_CARET, unit=textInfos.UNIT_LINE)
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 event_treeInterceptor_gainFocus(self): speech.speakObject(self.rootNVDAObject, reason=controlTypes.REASON_FOCUS) try: info = self.makeTextInfo(textInfos.POSITION_SELECTION) except RuntimeError: pass else: if info.isCollapsed: info.expand(textInfos.UNIT_LINE) speech.speakTextInfo(info, unit=textInfos.UNIT_LINE, reason=controlTypes.REASON_CARET) else: speech.speakSelectionMessage(_("selected %s"), info.text) braille.handler.handleGainFocus(self) self.initAutoSelectDetection()
def doFindText(self,text,reverse=False): if not text: return info=self.makeTextInfo(textInfos.POSITION_CARET) res=info.find(text,reverse=reverse) if res: self.selection=info speech.cancelSpeech() info.move(textInfos.UNIT_LINE,1,endPoint="end") speech.speakTextInfo(info,reason=speech.REASON_CARET) else: errorDialog=gui.scriptUI.MessageDialog(_("text \"%s\" not found")%text,title=_("Find Error"),style=gui.scriptUI.wx.OK|gui.scriptUI.wx.ICON_ERROR) errorDialog.run() CursorManager._lastFindText=text
def script_reportCurrentLine(self,gesture): obj=api.getFocusObject() treeInterceptor=obj.treeInterceptor if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough: obj=treeInterceptor try: info=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): info=obj.makeTextInfo(textInfos.POSITION_FIRST) info.expand(textInfos.UNIT_LINE) if scriptHandler.getLastScriptRepeatCount()==0: speech.speakTextInfo(info,unit=textInfos.UNIT_LINE,reason=speech.REASON_CARET) else: speech.speakSpelling(info.text)
def _moveInTable(self,row=True,forward=True): info=self.makeTextInfo(textInfos.POSITION_CARET) info.expand(textInfos.UNIT_CHARACTER) formatConfig=config.conf['documentFormatting'].copy() formatConfig['reportTables']=True commandList=info.getTextWithFields(formatConfig) if len(commandList)<3 or commandList[1].field.get('role',None)!=controlTypes.ROLE_TABLE or commandList[2].field.get('role',None)!=controlTypes.ROLE_TABLECELL: # Translators: The message reported when a user attempts to use a table movement command # when the cursor is not withnin a table. ui.message(_("Not in table")) return False rowCount=commandList[1].field.get('table-rowcount',1) columnCount=commandList[1].field.get('table-columncount',1) rowNumber=commandList[2].field.get('table-rownumber',1) columnNumber=commandList[2].field.get('table-columnnumber',1) try: table=info._rangeObj.tables[1] except COMError: log.debugWarning("Could not get MS Word table object indicated in XML") ui.message(_("Not in table")) return False _cell=table.cell getCell=lambda thisIndex,otherIndex: _cell(thisIndex,otherIndex) if row else _cell(otherIndex,thisIndex) thisIndex=rowNumber if row else columnNumber otherIndex=columnNumber if row else rowNumber thisLimit=(rowCount if row else columnCount) if forward else 1 limitOp=operator.le if forward else operator.ge incdecFunc=operator.add if forward else operator.sub foundCell=None curOtherIndex=otherIndex while curOtherIndex>0: curThisIndex=incdecFunc(thisIndex,1) while limitOp(curThisIndex,thisLimit): try: foundCell=getCell(curThisIndex,curOtherIndex).range except COMError: pass if foundCell: break curThisIndex=incdecFunc(curThisIndex,1) if foundCell: break curOtherIndex-=1 if not foundCell: ui.message(_("Edge of table")) return False newInfo=WordDocumentTextInfo(self,textInfos.POSITION_CARET,_rangeObj=foundCell) speech.speakTextInfo(newInfo,reason=controlTypes.REASON_CARET, unit=textInfos.UNIT_PARAGRAPH) newInfo.collapse() newInfo.updateCaret() return True
def script_tab(self,gesture): bookmark=self.rootNVDAObject.makeTextInfo(textInfos.POSITION_SELECTION).bookmark gesture.send() info,caretMoved=self.rootNVDAObject._hasCaretMoved(bookmark) if not caretMoved: return info=self.makeTextInfo(textInfos.POSITION_SELECTION) inTable=info._rangeObj.tables.count>0 isCollapsed=info.isCollapsed if inTable and isCollapsed: info.expand(textInfos.UNIT_CELL) isCollapsed=False if not isCollapsed: speech.speakTextInfo(info,reason=controlTypes.REASON_FOCUS) braille.handler.handleCaretMove(self)
def script_review_currentCharacter(self,gesture): info=api.getReviewPosition().copy() info.expand(textInfos.UNIT_CHARACTER) scriptCount=scriptHandler.getLastScriptRepeatCount() if scriptCount==0: speech.speakTextInfo(info,unit=textInfos.UNIT_CHARACTER,reason=speech.REASON_CARET) elif scriptCount==1: speech.speakSpelling(info.text,useCharacterDescriptions=True) else: try: c = ord(info.text) speech.speakMessage("%d," % c) speech.speakSpelling(hex(c)) except: speech.speakTextInfo(info,unit=textInfos.UNIT_CHARACTER,reason=speech.REASON_CARET)
def _moveInTable(self,row=True,forward=True): info=self.makeTextInfo(textInfos.POSITION_CARET) info.expand(textInfos.UNIT_CHARACTER) formatConfig=config.conf['documentFormatting'].copy() formatConfig['reportTables']=True commandList=info.getTextWithFields(formatConfig) if len(commandList)<3 or commandList[1].field.get('role',None)!=controlTypes.ROLE_TABLE or commandList[2].field.get('role',None)!=controlTypes.ROLE_TABLECELL: # Translators: The message reported when a user attempts to use a table movement command # when the cursor is not withnin a table. ui.message(_("Not in table")) return False rowCount=commandList[1].field.get('table-rowcount',1) columnCount=commandList[1].field.get('table-columncount',1) rowNumber=commandList[2].field.get('table-rownumber',1) columnNumber=commandList[2].field.get('table-columnnumber',1) if row: rowNumber+=1 if forward else -1 else: columnNumber+=1 if forward else -1 if rowNumber<1 or rowNumber>rowCount or columnNumber<1 or columnNumber>columnCount: # Translators: The message reported when a user attempts to use a table movement command # but the cursor can't be moved in that direction because it is at the edge of the table. ui.message(_("Edge of table")) return False try: table=info._rangeObj.tables[1] except COMError: log.debugWarning("Could not get MS Word table object indicated in XML") ui.message(_("Not in table")) return False while (columnNumber if row else rowNumber)>0: try: cell=table.cell(rowNumber,columnNumber) break except COMError: cell=None if row: columnNumber-=1 else: rowNumber-=1 if not cell: ui.message(_("Edge of table")) return False newInfo=WordDocumentTextInfo(self,textInfos.POSITION_CARET,_rangeObj=cell.range) speech.speakTextInfo(newInfo,reason=controlTypes.REASON_CARET) newInfo.collapse() newInfo.updateCaret() return True
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 doFindText(text, reverse=False, caseSensitive=False): if not text: return obj=api.getFocusObject() treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor obj.doFindText(text=text, reverse=reverse, caseSensitive=caseSensitive) elif obj.role != controlTypes.ROLE_EDITABLETEXT: return else: CursorManager._lastFindText = text CursorManager._lastCaseSensitivity = caseSensitive try: info=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): info=obj.makeTextInfo(textInfos.POSITION_FIRST) try: res=info.find(text,reverse=reverse, caseSensitive=caseSensitive) except WindowsError: wx.CallAfter(gui.messageBox, # Message translated in NVDA core. translate('text "%s" not found') % text, # Message translated in NVDA core. translate("Find Error"), wx.OK|wx.ICON_ERROR) except: if api.copyToClip(text): # Translators: message presented when a string of text has been copied to the clipboard. ui.message(_("%s copied to clipboard") % text) return if res: if hasattr(obj,'selection'): obj.selection=info else: info.updateCaret() speech.cancelSpeech() info.move(textInfos.UNIT_LINE,1,endPoint="end") speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: wx.CallAfter(gui.messageBox, # Message translated in NVDA core. translate('text "%s" not found') % text, # Message translated in NVDA core. translate("Find Error"), wx.OK|wx.ICON_ERROR)