def accessibilityPutValue(processor, path, value): ''' Sets the given value in an accessible of the given path. :param processor: A processor object calling the function :type processor: Processor :param path: A path of the accessible :type path: tadek.core.accessible.Path :param value: New value of the accessible :type value: float :return: True if success, False otherwise :rtype: boolean ''' log.debug(str(locals())) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if obj is None: log.warning("Attempt of setting value for non-accessible") return False status = a11y.setValue(obj, value) except: log.exception("Set accessible value error: %s" % path) # Reset the processor cache before leaving processor.cache = None return False if not status: log.info("Set accessible value failure: %s" % path) return status
def accessibilityGet(processor, path, depth, name=False, description=False, role=False, count=False, position=False, size=False, text=False, value=False, actions=False, states=False, attributes=False, relations=False): ''' Gets an accessible of the given path and depth including specified accessible parameters. :param processor: A processor object calling the function :type processor: Processor :param path: A path of a demanded accessible :type path: tadek.core.accessible.Path :param depth: A depth of a demanded accessible tree :type depth: integer :param name: True if a demanded accessible should include name :type name: boolean :param description: True if a demanded accessible should include description :type description: boolean :param role: True if a demanded accessible should include role :type role: boolean :param count: True if a demanded accessible should include child count :type count: boolean :param position: True if a demanded accessible should include position :type position: boolean :param size: True if a demanded accessible should include size :type size: boolean :param text: True if a demanded accessible should include text :type text: boolean :param value: True if a demanded accessible should include value :type value: boolean :param actions: True if a demanded accessible should include actions :type actions: boolean :param states: True if a demanded accessible should include states :type states: boolean :param attributes: True if a demanded accessible should include attributes :type attributes: boolean :param relations: True if a demanded accessible should include relations :type relations: bool :return: A getting accessible status and an accessible of the given path :rtype: tuple ''' log.debug(str(locals())) # Reset the processor cache processor.cache = None try: a11y, obj = providers.accessible(path) if a11y is None and path.tuple: log.info("Get accessible of requested path failure: %s" % path) return False, Accessible(path) processor.cache = (a11y, obj, path) return True, dumpAccessible(a11y, obj, path, depth=depth, name=name, description=description, role=role, count=count, position=position, size=size, text=text, value=value, actions=actions, states=states, attributes=attributes, relations=relations) except: log.exception("Get accessible of requested path error: %s" % path) return False, Accessible(path)
def accessibilityExecMouse(processor, path, event, button, coordinates): ''' Generates the given mouse event on an accessible of the specified path at the given coordinates using the specified mouse button. :param processor: A processor object calling the function :type processor: Processor :param path: A path of the accessible :type path: tadek.core.accessible.Path :param event: A mouse event to generate :type event: string :param button: A mouse button to use :type button: string :param coordinates: A a mouse event coordinates :type coordinates: list :return: True if success, False otherwise :rtype: boolean ''' log.debug(str(locals())) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if a11y is None: log.warning("Attempt of generating mouse event on non-accessible") return False button = getattr(a11y.buttonset, button, button) if event == 'CLICK': a11y.mouseClick(button=button, *coordinates) elif event == 'DOUBLE_CLICK': a11y.mouseDoubleClick(button=button, *coordinates) elif event == 'PRESS': a11y.mousePress(button=button, *coordinates) elif event == 'RELEASE': a11y.mouseRelease(button=button, *coordinates) elif event == 'ABSOLUTE_MOTION': a11y.mouseAbsoluteMotion(*coordinates) elif event == 'RELATIVE_MOTION': a11y.mouseRelativeMotion(*coordinates) else: log.warning("Unknown mouse event: %s", event) return False except: log.exception("Generate mouse event failure: %s" % path) # Reset the processor cache before leaving processor.cache = None return False return True
def accessibilityExecAction(processor, path, action): ''' Executes the specified action of an accessible given by the path. :param processor: A processor object calling the function :type processor: Processor :param path: A path of the accessible :type path: tadek.core.accessible.Path :param action: An accessible action to execute :type action: string :return: True if success, False otherwise :rtype: boolean ''' log.debug(str(locals())) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if obj is None: log.warning("Attempt of executing action of non-accessible") return False if action == A11Y_ACTION_FOCUS: status = a11y.grabFocus(obj) else: status = a11y.doAction(obj, getattr(a11y.actionset, action, action)) except: log.exception("Execute accessible action error: %s" % path) # Reset the processor cache before leaving processor.cache = None return False if not status: log.info("Execute accessible action failure: %s" % path) return status
def accessibilityExecKeyboard(processor, path, keycode, modifiers): ''' Generates a keyboard event for the given key code using the specified modifiers for an accessible of the given path. :param processor: A processor object calling the function :type processor: Processor :param path: A path of the accessible :type path: tadek.core.accessible.Path :param keycode: A code of a key to generate event of :type keycode: integer :param modifiers: A list of key codes to use as modifiers :type modifiers: list :return: True if success, False otherwise :rtype: boolean ''' log.debug(str(locals())) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if a11y is None: log.warning("Attempt of generating keyboard" " event on non-accessible") return False a11y.keyboardEvent(keycode, modifiers) except: log.exception("Generate keyboard event error: %s" % path) # Reset the processor cache before leaving processor.cache = None return False return True
def accessibilitySearch(processor, path, method, name=None, description=None, role=None, index=None, count=None, action=None, relation=None, state=None, text=None, nth=0): ''' Searches an accessible using the given method according to specified accessible parameters. :param processor: A processor object calling the function :type processor: Processor :param path: A path of a demanded accessible :type path: tadek.core.accessible.Path :param method: A search method of accessible :type method: string :param name: A name of searched accessible or None :type name: string or NoneType :param description: A description of searched accessible or None :type description: string or NoneType :param role: A role of searched accessible or None :type role: string or NoneType :param index: An index of searched accessible or None :type index: integer or NoneType :param count: A child count of searched accessible or None :type count: string or NoneType :param action: An action of searched accessible or None :type action: string or NoneType :param relation: A relation of searched accessible or None :type relation: string or NoneType :param state: A state of searched accessible or None :type state: string or NoneType :param text: Text of searched accessible or None :type text: string or NoneType :param nth: A nth matched accessible :type nth: integer :return: A searching accessible status and an accessible of the given path :rtype: tuple ''' log.debug(str(locals())) def matchString(pattern, string): ''' Checks if the give string matches the regular expression pattern. ''' if string is None: return False match = pattern.match(string) return match is not None and match.span() == (0, len(string)) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if a11y is None and path.tuple: log.info("Accessible of requested path not found: %s" % path) return False, Accessible(path) if method == protocol.MHD_SEARCH_SIMPLE: provider = providers.Children elif method == protocol.MHD_SEARCH_BACKWARDS: provider = providers.ChildrenBackwards elif method == protocol.MHD_SEARCH_DEEP: provider = providers.Descendants else: log.error("Unknown search method: %s" % method) return False, Accessible(Path()) if name and name[0] == '&': name = re.compile(name[1:], re.DOTALL) cmpName = matchString else: cmpName = lambda pattern, string: pattern == string if description and description[0] == '&': description = re.compile(description[1:], re.DOTALL) cmpDesc = matchString else: cmpDesc = lambda pattern, string: pattern == string if text and text[0] == '&': text = re.compile(text[1:], re.DOTALL) cmpText = matchString else: cmpText = lambda pattern, string: pattern == string i = 0 for a11y, obj, path in provider(a11y, obj, path): if index is not None and index != path.index(): continue if obj is None: if name is not None and not cmpName(name, a11y.name): continue if count is not None and a11y.countChildren() != count: continue else: if name is not None and not cmpName(name, a11y.getName(obj)): continue if (description is not None and not cmpDesc(description, a11y.getDescription(obj))): continue if role is not None and a11y.getRoleName(obj) != role: continue if count is not None and a11y.countChildren(obj) != count: continue if action is not None: found = False for act in a11y.actionNames(obj): if action == act: found = True break if not found: continue if relation is not None: found = False for rel in a11y.relationNames(obj): if relation == rel: found = True break if not found: continue if (state is not None and not a11y.inState( obj, getattr(a11y.stateset, state, None))): continue if text is not None and not cmpText(text, a11y.getText(obj)): continue i += 1 if nth < i: processor.cache = (a11y, obj, path) return True, dumpAccessible(a11y, obj, path, depth=0, name=True, description=True, role=True, count=True, position=True, size=True, text=True, value=True, actions=True, states=True, attributes=True, relations=True) except: log.exception("Search an accessible of specified parmaters error") # Reset the processor cache before leaving processor.cache = None return False, Accessible(path) log.info("Search an accessible of specified parmaters failure") return False, Accessible(path)
def accessibilitySearch(processor, path, method, name=None, description=None, role=None, index=None, count=None, action=None, relation=None, state=None, text=None, nth=0): ''' Searches an accessible using the given method according to specified accessible parameters. :param processor: A processor object calling the function :type processor: Processor :param path: A path of a demanded accessible :type path: tadek.core.accessible.Path :param method: A search method of accessible :type method: string :param name: A name of searched accessible or None :type name: string or NoneType :param description: A description of searched accessible or None :type description: string or NoneType :param role: A role of searched accessible or None :type role: string or NoneType :param index: An index of searched accessible or None :type index: integer or NoneType :param count: A child count of searched accessible or None :type count: string or NoneType :param action: An action of searched accessible or None :type action: string or NoneType :param relation: A relation of searched accessible or None :type relation: string or NoneType :param state: A state of searched accessible or None :type state: string or NoneType :param text: Text of searched accessible or None :type text: string or NoneType :param nth: A nth matched accessible :type nth: integer :return: A searching accessible status and an accessible of the given path :rtype: tuple ''' log.debug(str(locals())) def matchString(pattern, string): ''' Checks if the give string matches the regular expression pattern. ''' if string is None: return False match = pattern.match(string) return match is not None and match.span() == (0, len(string)) try: # Get object from the processor cache or from the accessible provider if processor.cache and processor.cache[-1] == path: a11y, obj, path = processor.cache else: a11y, obj = providers.accessible(path) # Reset the processor cache processor.cache = None if a11y is None and path.tuple: log.info("Accessible of requested path not found: %s" % path) return False, Accessible(path) if method == protocol.MHD_SEARCH_SIMPLE: provider = providers.Children elif method == protocol.MHD_SEARCH_BACKWARDS: provider = providers.ChildrenBackwards elif method == protocol.MHD_SEARCH_DEEP: provider = providers.Descendants else: log.error("Unknown search method: %s" % method) return False, Accessible(Path()) if name and name[0] == '&': name = re.compile(name[1:], re.DOTALL) cmpName = matchString else: cmpName = lambda pattern, string: pattern == string if description and description[0] == '&': description = re.compile(description[1:], re.DOTALL) cmpDesc = matchString else: cmpDesc = lambda pattern, string: pattern == string if text and text[0] == '&': text = re.compile(text[1:], re.DOTALL) cmpText = matchString else: cmpText = lambda pattern, string: pattern == string i = 0 for a11y, obj, path in provider(a11y, obj, path): if index is not None and index != path.index(): continue if obj is None: if name is not None and not cmpName(name, a11y.name): continue if count is not None and a11y.countChildren() != count: continue else: if name is not None and not cmpName(name, a11y.getName(obj)): continue if (description is not None and not cmpDesc(description, a11y.getDescription(obj))): continue if role is not None and a11y.getRoleName(obj) != role: continue if count is not None and a11y.countChildren(obj) != count: continue if action is not None: found = False for act in a11y.actionNames(obj): if action == act: found = True break if not found: continue if relation is not None: found = False for rel in a11y.relationNames(obj): if relation == rel: found = True break if not found: continue if (state is not None and not a11y.inState(obj, getattr(a11y.stateset, state, None))): continue if text is not None and not cmpText(text, a11y.getText(obj)): continue i += 1 if nth < i: processor.cache = (a11y, obj, path) return True, dumpAccessible(a11y, obj, path, depth=0, name=True, description=True, role=True, count=True, position=True, size=True, text=True, value=True, actions=True, states=True, attributes=True, relations=True) except: log.exception("Search an accessible of specified parmaters error") # Reset the processor cache before leaving processor.cache = None return False, Accessible(path) log.info("Search an accessible of specified parmaters failure") return False, Accessible(path)