def textLines(self, obj, offset=None): """Creates a generator that can be used to iterate over each line of a text object, starting at the caret offset. Arguments: - obj: an Accessible that has a text specialization Returns an iterator that produces elements of the form: [SayAllContext, acss], where SayAllContext has the text to be spoken and acss is an ACSS instance for speaking the text. """ self._sayAllIsInterrupted = False self._inSayAll = False if not obj: return if obj.getRole() == pyatspi.ROLE_LINK: obj = obj.parent if self.utilities.isDocument(obj): document = obj else: document = self.utilities.getContainingDocument(obj) if not document or document.getState().contains(pyatspi.STATE_BUSY): return allTextObjs = utils.findAllDescendants( document, lambda x: x and 'Text' in utils.listInterfaces(x)) allTextObjs = allTextObjs[allTextObjs.index(obj):len(allTextObjs)] textObjs = [x for x in allTextObjs if x.parent not in allTextObjs] if not textObjs: return boundary = pyatspi.TEXT_BOUNDARY_LINE_START sayAllStyle = _settingsManager.getSetting('sayAllStyle') if sayAllStyle == settings.SAYALL_STYLE_SENTENCE: boundary = pyatspi.TEXT_BOUNDARY_SENTENCE_START voices = _settingsManager.getSetting('voices') systemVoice = voices.get(settings.SYSTEM_VOICE) self._inSayAll = True offset = textObjs[0].queryText().caretOffset for textObj in textObjs: textSegments = self.getTextSegments(textObj, boundary, offset) roleName = self.speechGenerator.getRoleName(textObj) if roleName: textSegments.append([roleName, 0, -1, systemVoice]) for (string, start, end, voice) in textSegments: context = speechserver.SayAllContext(textObj, string, start, end) self._sayAllContexts.append(context) eventsynthesizer.scrollIntoView(obj, start, end) yield [context, voice] offset = 0 self._inSayAll = False self._sayAllContexts = []
def textLines(self, obj, offset=None): """Creates a generator that can be used to iterate over each line of a text object, starting at the caret offset. Arguments: - obj: an Accessible that has a text specialization Returns an iterator that produces elements of the form: [SayAllContext, acss], where SayAllContext has the text to be spoken and acss is an ACSS instance for speaking the text. """ self._sayAllIsInterrupted = False self._inSayAll = False if not obj: return if obj.getRole() == pyatspi.ROLE_LINK: obj = obj.parent docRoles = [pyatspi.ROLE_DOCUMENT_FRAME, pyatspi.ROLE_DOCUMENT_WEB] document = utils.findAncestor(obj, lambda x: x.getRole() in docRoles) if not document or document.getState().contains(pyatspi.STATE_BUSY): return allTextObjs = utils.findAllDescendants( document, lambda x: x and 'Text' in utils.listInterfaces(x)) allTextObjs = allTextObjs[allTextObjs.index(obj):len(allTextObjs)] textObjs = [x for x in allTextObjs if x.parent not in allTextObjs] if not textObjs: return boundary = pyatspi.TEXT_BOUNDARY_LINE_START sayAllStyle = _settingsManager.getSetting('sayAllStyle') if sayAllStyle == settings.SAYALL_STYLE_SENTENCE: boundary = pyatspi.TEXT_BOUNDARY_SENTENCE_START self._inSayAll = True offset = textObjs[0].queryText().caretOffset for textObj in textObjs: textSegments = self.getTextSegments(textObj, boundary, offset) roleInfo = self.speechGenerator.getRoleName(textObj) if roleInfo: roleName, voice = roleInfo textSegments.append([roleName, 0, -1, voice]) for (string, start, end, voice) in textSegments: context = speechserver.SayAllContext(textObj, string, start, end) self._sayAllContexts.append(context) yield [context, voice] offset = 0 self._inSayAll = False self._sayAllContexts = []
def getAppStrings(app): # predicate = lambda x: ((x.getRole() == role.ROLE_MENU) or (x.getRole() == role.ROLE_MENU_ITEM)) buttons = utils.findAllDescendants( app, lambda x: ((x.getRole() == role.ROLE_MENU) or (x.getRole() == role.ROLE_MENU_ITEM))) for button in buttons: button.do_action(0) strings = [] traverse(app, strings) strings = [s for s in strings if s] return strings
def textLines(self, obj): """Creates a generator that can be used to iterate over each line of a text object, starting at the caret offset. Arguments: - obj: an Accessible that has a text specialization Returns an iterator that produces elements of the form: [SayAllContext, acss], where SayAllContext has the text to be spoken and acss is an ACSS instance for speaking the text. """ document = utils.findAncestor( obj, lambda x: x.getRole() == pyatspi.ROLE_DOCUMENT_FRAME) allTextObjs = utils.findAllDescendants( document, lambda x: 'Text' in utils.listInterfaces(x)) allTextObjs = allTextObjs[allTextObjs.index(obj):len(allTextObjs)] textObjs = filter(lambda x: x.parent not in allTextObjs, allTextObjs) if not textObjs: return boundary = pyatspi.TEXT_BOUNDARY_LINE_START sayAllStyle = _settingsManager.getSetting('sayAllStyle') if sayAllStyle == settings.SAYALL_STYLE_SENTENCE: boundary = pyatspi.TEXT_BOUNDARY_SENTENCE_START offset = textObjs[0].queryText().caretOffset for textObj in textObjs: textSegments = self.getTextSegments(textObj, boundary, offset) roleInfo = self.speechGenerator.getRoleName(textObj) if roleInfo: roleName, voice = roleInfo textSegments.append([roleName, 0, -1, voice]) for (string, start, end, voice) in textSegments: yield [speechserver.SayAllContext(textObj, string, start, end), voice] offset = 0