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 _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=0.03): """ Waits for the caret to move, for a timeout to elapse, or for a new focus event or script to be queued. @param bookmark: a bookmark representing the position of the caret before it was instructed to move @type bookmark: bookmark @param retryInterval: the interval of time in seconds this method should wait before checking the caret each time. @type retryInterval: float @param timeout: the over all amount of time in seconds the method should wait before giving up completely. @type timeout: float @return: a tuple containing a boolean denoting whether this method timed out, and a TextInfo representing the old or updated caret position or None if interupted by a script or focus event. @rtype: tuple """ elapsed = 0 newInfo = None while elapsed < timeout: if isScriptWaiting(): return (False, None) api.processPendingEvents(processEventQueue=False) if eventHandler.isPendingEvents("gainFocus"): return (True, None) #The caret may stop working as the focus jumps, we want to stay in the while loop though try: newInfo = self.makeTextInfo(textInfos.POSITION_CARET) newBookmark = newInfo.bookmark except (RuntimeError, NotImplementedError): newInfo = None else: if newBookmark != bookmark: return (True, newInfo) time.sleep(retryInterval) elapsed += retryInterval return (False, newInfo)
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 _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 _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 _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 _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=0.03): """ Waits for the caret to move, for a timeout to elapse, or for a new focus event or script to be queued. @param bookmark: a bookmark representing the position of the caret before it was instructed to move @type bookmark: bookmark @param retryInterval: the interval of time in seconds this method should wait before checking the caret each time. @type retryInterval: float @param timeout: the over all amount of time in seconds the method should wait before giving up completely. @type timeout: float @return: a tuple containing a boolean denoting whether this method timed out, and a TextInfo representing the old or updated caret position or None if interupted by a script or focus event. @rtype: tuple """ elapsed = 0 newInfo=None while elapsed < timeout: if isScriptWaiting(): return (False,None) api.processPendingEvents(processEventQueue=False) if eventHandler.isPendingEvents("gainFocus"): return (True,None) #The caret may stop working as the focus jumps, we want to stay in the while loop though try: newInfo = self.makeTextInfo(textInfos.POSITION_CARET) newBookmark = newInfo.bookmark except (RuntimeError,NotImplementedError): newInfo=None else: if newBookmark!=bookmark: return (True,newInfo) time.sleep(retryInterval) elapsed += retryInterval return (False,newInfo)
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 _tableMovementFirstOrLastScriptHelper(self, movement="first", 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(NVDAString("Not in a table cell")) return direction = "previous" if movement == "first" else "next" try: info = self._getNearestTableCell(tableID, self.selection, origRow, origCol, origRowSpan, origColSpan, direction, 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(NVDAString("Edge of table")) # Retrieve the cell on which we started. info = self._getTableCellAt(tableID, self.selection, origRow, origCol) speech.speakTextInfo(info, formatConfig=formatConfig, reason=REASON_CARET) info.collapse() self.selection = info return try: tableID1, origRow1, origCol1 = tableID, origRow, origCol origRowSpan1, origColSpan1 = origRowSpan, origColSpan i = 500 while i > 0: i = i - 1 info = self._getNearestTableCell(tableID1, self.selection, origRow1, origCol1, origRowSpan1, origColSpan1, direction, axis) tableID1, origRow1, origCol1, origRowSpan1, origColSpan1 = self._getTableCellCoords( self.selection) info.collapse() self.selection = info except LookupError: # Retrieve the previous cell info = self._getTableCellAt(tableID1, self.selection, origRow1, origCol1) speech.speakTextInfo(info, formatConfig=formatConfig, reason=REASON_CARET) info.collapse() self.selection = info
def findTableCell(selfself, gesture, movement="next", axis=None, index=0): 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 edgeFound = False for attempt in range(MAX_TABLE_DIMENSION): tableID, origRow, origCol, origRowSpan, origColSpan = selfself._getTableCellCoords( info) try: info = selfself._getNearestTableCell(tableID, info, origRow, origCol, origRowSpan, origColSpan, movement, axis) except LookupError: edgeFound = True break if not edgeFound: ui.message(_("Cannot find edge of table in this direction")) info = self._getTableCellAt(tableID, self.selection, origRow, origCol) info.collapse() self.selection = info return if index > 1: inverseMovement = "next" if movement == "previous" else "previous" for i in range(1, index): tableID, origRow, origCol, origRowSpan, origColSpan = selfself._getTableCellCoords( info) try: info = selfself._getNearestTableCell(tableID, selfself.selection, origRow, origCol, origRowSpan, origColSpan, inverseMovement, axis) except LookupError: ui.message( _("Cannot find {axis} with index {index} in this table"). format(**locals())) return speech.speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.REASON_CARET) info.collapse() selfself.selection = info
def script_repeatToggle(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() if self.appModule.getRepeat(): onOff = _("on") else: onOff = _("off") ui.message(onOff)
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 script_shuffleToggle(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() if getShuffle(): # Translators: the user has pressed the shuffle tracks toggle in winamp, shuffle is now on. onOff = pgettext("shuffle", "on") else: # Translators: the user has pressed the shuffle tracks toggle in winamp, shuffle is now off. onOff = pgettext("shuffle", "off") ui.message(onOff)
def script_shuffleToggle(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() if getShuffle(): # Translators: the user has pressed the shuffle tracks toggle in winamp, shuffle is now on. onOff = pgettext("shuffle", "on") else: # Translators: the user has pressed the shuffle tracks toggle in winamp, shuffle is now off. onOff = pgettext("shuffle", "off") speech.speakMessage(onOff)
def script_repeatToggle(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() if getRepeat(): # Translators: the user has pressed the repeat track toggle in winamp, repeat is now on. onOff = pgettext("repeat", "on") else: # Translators: the user has pressed the repeat track toggle in winamp, repeat is now off. onOff = pgettext("repeat", "off") ui.message(onOff)
def _caretMoveBySentenceHelper(self, gesture, direction): if isScriptWaiting(): return try: info=self.makeTextInfo(textInfos.POSITION_CARET) info.move(textInfos.UNIT_SENTENCE, direction) info.updateCaret() self._caretScriptPostMovedHelper(textInfos.UNIT_SENTENCE,gesture,info) except: gesture.send() return
def script_repeatToggle(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() if getRepeat(): # Translators: the user has pressed the repeat track toggle in winamp, repeat is now on. onOff = pgettext("repeat", "on") else: # Translators: the user has pressed the repeat track toggle in winamp, repeat is now off. onOff = pgettext("repeat", "off") speech.speakMessage(onOff)
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_caret_changeSelection(self,gesture): try: oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION) except: gesture.send() return gesture.send() if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"): return try: self.reportSelectionChange(oldInfo) except: return
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 _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 script_moveVertical(self,gesture): gesture.send() if scriptHandler.isScriptWaiting(): return self._clearLocationCache() textList=[] text=self._getOverlapText() if text: textList.append(text) text=self._getShapeLocationText(top=True,bottom=True) if text: textList.append(text) ui.message(", ".join(textList))
def script_caret_changeSelection(self, gesture): try: oldInfo = self.makeTextInfo(textInfos.POSITION_SELECTION) except: gesture.send() return gesture.send() if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"): return try: self.reportSelectionChange(oldInfo) except: return
def _reportRowOrColumn(self, axis="row"): if isScriptWaiting(): return try: tableID, origRow, origCol, origRowSpan, origColSpan = self._getTableCellCoords( self.selection) (row, col) = (origRow, 1) if axis == "row" else (1, origCol) info = self._getTableCellAt(tableID, self.selection, row, col) except LookupError: # Translators: The message reported when a user attempts # to use a table report command. # when the cursor is not within a table. ui.message(NVDAString("Not in a table cell")) return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = True formatConfig["includeLayoutTables"] = True formatConfig["reportTableCellCoords"] = True while info: _ignore, row, col, rowSpan, colSpan = self._getTableCellCoords( info) if axis == "row" and row != origRow: break elif axis == "column" and col != origCol: pass else: speech.speakTextInfo(info, formatConfig=formatConfig, reason=REASON_MESSAGE) try: if axis == "row": info = self._getNearestTableCell(tableID, info, origRow=row, origCol=col, origRowSpan=rowSpan, origColSpan=colSpan, movement="next", axis="column") else: info = self._getNearestTableCell(tableID, info, origRow=row, origCol=col, origRowSpan=rowSpan, origColSpan=colSpan, movement="next", axis="row") except LookupError: break
def script_caret_changeSelection(self,gesture): try: oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION) except: gesture.send() return gesture.send() if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"): return api.processPendingEvents(processEventQueue=False) try: newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION) except: return speech.speakSelectionChange(oldInfo,newInfo)
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_caret_changeSelection(self,gesture): try: oldInfo=self.makeTextInfo(textInfos.POSITION_SELECTION) except: gesture.send() return gesture.send() if isScriptWaiting() or eventHandler.isPendingEvents("gainFocus"): return api.processPendingEvents(processEventQueue=False) try: newInfo=self.makeTextInfo(textInfos.POSITION_SELECTION) except: return speech.speakSelectionChange(oldInfo,newInfo) braille.handler.handleCaretMove(self)
def script_changeSelection(self,gesture): oldSelection=self._getSelection() gesture.send() newSelection=None curTime=startTime=time.time() while (curTime-startTime)<=0.15: if scriptHandler.isScriptWaiting(): # Prevent lag if keys are pressed rapidly return if eventHandler.isPendingEvents('gainFocus'): return newSelection=self._getSelection() if newSelection and newSelection!=oldSelection: break api.processPendingEvents(processEventQueue=False) time.sleep(0.015) curTime=time.time() if newSelection: eventHandler.executeEvent('gainFocus',newSelection)
def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=0.03): elapsed = 0 while elapsed < timeout: if isScriptWaiting(): return False api.processPendingEvents(processEventQueue=False) if eventHandler.isPendingEvents("gainFocus"): return True #The caret may stop working as the focus jumps, we want to stay in the while loop though try: newBookmark = self.makeTextInfo(textInfos.POSITION_CARET).bookmark except (RuntimeError,NotImplementedError): pass else: if newBookmark!=bookmark: return True time.sleep(retryInterval) elapsed += retryInterval return False
def script_openDropdown(self,gesture): gesture.send() d=None curTime=startTime=time.time() while (curTime-startTime)<=0.25: if scriptHandler.isScriptWaiting(): # Prevent lag if keys are pressed rapidly return if eventHandler.isPendingEvents('gainFocus'): return d=self._getDropdown() if d: break api.processPendingEvents(processEventQueue=False) time.sleep(0.025) curTime=time.time() if not d: log.debugWarning("Failed to get dropDown, giving up") return d.parent=self eventHandler.queueEvent("gainFocus",d)
def _caretMoveBySentenceHelper(self, gesture, direction): if isScriptWaiting(): return if not self.WinwordSelectionObject: # Legacy object model not available. # Translators: a message when navigating by sentence is unavailable in MS Word ui.message( _("Navigating by sentence not supported in this document")) gesture.send() return # Using the legacy object model, # Move the caret to the next sentence in the requested direction. legacyInfo = LegacyWordDocumentTextInfo(self, textInfos.POSITION_CARET) legacyInfo.move(textInfos.UNIT_SENTENCE, direction) # Save the start of the sentence for future use legacyStart = legacyInfo.copy() # With the legacy object model, # Move the caret to the end of the new sentence. legacyInfo.move(textInfos.UNIT_SENTENCE, 1) legacyInfo.updateCaret() # Fetch the caret position (end of the next sentence) with UI automation. endInfo = self.makeTextInfo(textInfos.POSITION_CARET) # Move the caret back to the start of the next sentence, # where it should be left for the user. legacyStart.updateCaret() # Fetch the new caret position (start of the next sentence) with UI Automation. startInfo = self.makeTextInfo(textInfos.POSITION_CARET) # Make a UI automation text range spanning the entire next sentence. info = startInfo.copy() info.end = endInfo.end # Speak the sentence moved to speech.speakTextInfo(info, unit=textInfos.UNIT_SENTENCE, reason=controlTypes.OutputReason.CARET) # Forget the word currently being typed as the user has moved the caret somewhere else. speech.clearTypedWordBuffer() # Alert review and braille the caret has moved to its new position review.handleCaretMove(info) braille.handler.handleCaretMove(self)
def script_reportCurrentCellPosition(self, gesture): if isScriptWaiting(): return try: tableID, row, col, rowSpan, colSpan = self._getTableCellCoords(self.selection) # noqa:E501 info = self._getTableCellAt(tableID, self.selection, row, col) except LookupError: # Translators: The message reported when a user attempts # to use a table report command. # when the cursor is not within a table. ui.message(NVDAString("Not in a table cell")) return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = False formatConfig["reportTableHeaders"] = True formatConfig["includeLayoutTables"] = True formatConfig["reportTableCellCoords"] = True speech.speakTextInfo( info, useCache=False, formatConfig=formatConfig, reason=REASON_QUERY, onlyInitialFields=False)
def _tableMovementScriptHelper(self, movement="next", 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 import ui if isScriptWaiting(): return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = 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 = self._getTableCellAt(tableID, self.selection, origRow, origCol) speakTextInfo(info, formatConfig=formatConfig, reason=controlTypes.OutputReason.CARET) info.collapse() self.selection = info
def _tableMovementScriptHelper(self, movement="next", axis=None): # modified to indicate mmovement by a return True if isScriptWaiting(): return formatConfig = config.conf["documentFormatting"].copy() formatConfig["reportTables"] = True try: tableID, origRow, origCol, origRowSpan, origColSpan = self._getTableCellCoords(self.selection) # noqa:E501 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(NVDAString("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(NVDAString("Edge of table")) # Retrieve the cell on which we started. info = self._getTableCellAt(tableID, self.selection, origRow, origCol) speech.speakTextInfo( info, formatConfig=formatConfig, reason=REASON_CARET) info.collapse() self.selection = info return True
def script_refreshBuffer(self,gesture): if scriptHandler.isScriptWaiting(): # This script may cause subsequently queued scripts to fail, so don't execute. return self.unloadBuffer() self.loadBuffer()
def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=None): """ Waits for the caret to move, for a timeout to elapse, or for a new focus event or script to be queued. @param bookmark: a bookmark representing the position of the caret before it was instructed to move @type bookmark: bookmark @param retryInterval: the interval of time in seconds this method should wait before checking the caret each time. @type retryInterval: float @param timeout: the over all amount of time in seconds the method should wait before giving up completely, C{None} to use the value from the configuration. @type timeout: float @param origWord: The word at the caret before the movement command, C{None} if the word at the caret should not be used to detect movement. This is intended for use with the delete key. @return: a tuple containing a boolean denoting whether this method timed out, and a TextInfo representing the old or updated caret position or None if interupted by a script or focus event. @rtype: tuple """ if timeout is None: timeoutMs = config.conf["editableText"]["caretMoveTimeoutMs"] else: # This function's arguments are in seconds, but we want ms. timeoutMs = timeout * 1000 # time.sleep accepts seconds, so retryInterval is in seconds. # Convert to integer ms to avoid floating point precision errors when adding to elapsed. retryMs = int(retryInterval * 1000) elapsed = 0 newInfo=None while True: if isScriptWaiting(): return (False,None) api.processPendingEvents(processEventQueue=False) if eventHandler.isPendingEvents("gainFocus"): log.debug("Focus event. Elapsed: %d ms" % elapsed) return (True,None) # If the focus changes after this point, fetching the caret may fail, # but we still want to stay in this loop. try: newInfo = self.makeTextInfo(textInfos.POSITION_CARET) except (RuntimeError,NotImplementedError): newInfo = None # Caret events are unreliable in some controls. # Try to detect with bookmarks. newBookmark = None if newInfo: try: newBookmark = newInfo.bookmark except (RuntimeError,NotImplementedError): pass if newBookmark and newBookmark!=bookmark: log.debug("Caret move detected using bookmarks. Elapsed: %d ms" % elapsed) return (True, newInfo) if origWord is not None and newInfo and elapsed >= self._hasCaretMoved_minWordTimeoutMs: # When pressing delete, bookmarks might not be enough to detect caret movement. # Therefore try detecting if the word under the caret has changed, such as when pressing delete. # some editors such as Mozilla Gecko can have text and units that get out of sync with eachother while a character is being deleted. # Therefore, only check if the word has changed after a particular amount of time has elapsed, allowing the text and units to settle down. wordInfo = newInfo.copy() wordInfo.expand(textInfos.UNIT_WORD) word = wordInfo.text if word != origWord: log.debug("Word at caret changed. Elapsed: %d ms" % elapsed) return (True, newInfo) if elapsed >= timeoutMs: break time.sleep(retryInterval) elapsed += retryMs log.debug("Caret didn't move before timeout. Elapsed: %d ms" % elapsed) return (False,newInfo)
def script_changeItem(self, gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() speech.speakObject(self, reason=controlTypes.REASON_FOCUS) braille.handler.handleGainFocus(self)
def script_changeSelection(self,gesture): gesture.send() if scriptHandler.isScriptWaiting(): # Prevent lag if keys are pressed rapidly. return self.fireFocusOnSelection()
def script_nextColumn(self,gesture): gesture.send() if not isScriptWaiting(): next=self.next if next and controlTypes.STATE_FOCUSED in next.states: eventHandler.executeEvent("gainFocus", next)
def script_previousColumn(self,gesture): gesture.send() if not isScriptWaiting(): previous=self.previous if previous and controlTypes.STATE_FOCUSED in previous.states: eventHandler.executeEvent("gainFocus", previous)
def script_selectionChange(self,gesture): gesture.send() if scriptHandler.isScriptWaiting(): return self.handleSelectionChange()
def script_changeItem(self,gesture): gesture.send() if not isScriptWaiting(): api.processPendingEvents() speech.speakObject(self,reason=controlTypes.REASON_FOCUS) braille.handler.handleGainFocus(self)
def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=None): """ Waits for the caret to move, for a timeout to elapse, or for a new focus event or script to be queued. @param bookmark: a bookmark representing the position of the caret before it was instructed to move @type bookmark: bookmark @param retryInterval: the interval of time in seconds this method should wait before checking the caret each time. @type retryInterval: float @param timeout: the over all amount of time in seconds the method should wait before giving up completely, C{None} to use the value from the configuration. @type timeout: float @param origWord: The word at the caret before the movement command, C{None} if the word at the caret should not be used to detect movement. This is intended for use with the delete key. @return: a tuple containing a boolean denoting whether this method timed out, and a TextInfo representing the old or updated caret position or None if interupted by a script or focus event. @rtype: tuple """ if timeout is None: timeoutMs = config.conf["editableText"]["caretMoveTimeoutMs"] else: # This function's arguments are in seconds, but we want ms. timeoutMs = timeout * 1000 # time.sleep accepts seconds, so retryInterval is in seconds. # Convert to integer ms to avoid floating point precision errors when adding to elapsed. retryMs = int(retryInterval * 1000) elapsed = 0 newInfo = None while True: if isScriptWaiting(): return (False, None) api.processPendingEvents(processEventQueue=False) if eventHandler.isPendingEvents("gainFocus"): log.debug("Focus event. Elapsed: %d ms" % elapsed) return (True, None) # If the focus changes after this point, fetching the caret may fail, # but we still want to stay in this loop. try: newInfo = self.makeTextInfo(textInfos.POSITION_CARET) except (RuntimeError, NotImplementedError): newInfo = None # Caret events are unreliable in some controls. # Try to detect with bookmarks. newBookmark = None if newInfo: try: newBookmark = newInfo.bookmark except (RuntimeError, NotImplementedError): pass if newBookmark and newBookmark != bookmark: log.debug( "Caret move detected using bookmarks. Elapsed: %d ms" % elapsed) return (True, newInfo) if origWord is not None and newInfo: # When pressing delete, bookmarks might not be enough to detect caret movement. wordInfo = newInfo.copy() wordInfo.expand(textInfos.UNIT_WORD) word = wordInfo.text if word != origWord: log.debug("Word at caret changed. Elapsed: %d ms" % elapsed) return (True, newInfo) if elapsed >= timeoutMs: break time.sleep(retryInterval) elapsed += retryMs log.debug("Caret didn't move before timeout. Elapsed: %d ms" % elapsed) return (False, newInfo)
def script_previousColumn(self, gesture): gesture.send() if not isScriptWaiting(): previous = self.previous if previous and controlTypes.STATE_FOCUSED in previous.states: eventHandler.executeEvent("gainFocus", previous)