Ejemplo n.º 1
0
 def getApplicationMenuList(self, search_by_item='Quit'):
     """
     Returns list of all menu item nodes. Searches for the menu by a reference item.
     Provide a different item name, if the 'Quit' is not present - but beware picking one
     present elsewhere, like 'Lock' or 'Power Off' present under the user menu.
     """
     matches = self.shell.findChildren(
         predicate.GenericPredicate(name=search_by_item, roleName='label'))
     for match in matches:
         ancestor = match.parent.parent.parent
         if ancestor.roleName == 'panel':
             return ancestor.findChildren(
                 predicate.GenericPredicate(roleName='label'))
     from tree import SearchError
     raise SearchError(
         "Could not find the Application menu based on '%s' item. Please provide an existing reference item"
         % search_by_item)
Ejemplo n.º 2
0
    def child(self, name='', roleName='', description='', label='', recursive=True, retry=True, debugName=None):
        """
        Finds a child satisying the given criteria.

        This is implemented using findChild, and hence will automatically retry
        if no such child is found, and will eventually raise an exception. It
        also logs the search.
        """
        return self.findChild(predicate.GenericPredicate(name=name, roleName=roleName, description=description, label=label), recursive=recursive, retry=retry, debugName=debugName)
Ejemplo n.º 3
0
    def __call__(self, name='', roleName='', description=''):
        """
        If name, roleName or description are specified, search for a widget that matches and refocus on it.
        """
        if not name and not roleName and not description:
            raise TypeError(ENOARGS)

        # search for a widget.
        pred = predicate.GenericPredicate(name=name,
                                          roleName=roleName,
                                          description=description)
        return self.findByPredicate(pred)
Ejemplo n.º 4
0
    def getRelativeSearch(self):
        """
        Get a (ancestorNode, predicate, isRecursive) triple that identifies the
        best way to find this Node uniquely.
        FIXME: or None if no such search exists?
        FIXME: may need to make this more robust
        FIXME: should this be private?
        """
        if config.debugSearchPaths:
            logger.log("getRelativeSearchPath(%s)" % self)

        assert self
        assert self.parent

        isRecursive = False
        ancestor = self.parent

        # iterate up ancestors until you reach an identifiable one,
        # setting the search to be isRecursive if need be:
        while not self.__nodeIsIdentifiable(ancestor):
            ancestor = ancestor.parent
            isRecursive = True

        # Pick the most appropriate predicate for finding this node:
        if self.labellee:
            if self.labellee.name:
                return (ancestor, predicate.IsLabelledAs(self.labellee.name), isRecursive)

        if self.roleName == 'menu':
            return (ancestor, predicate.IsAMenuNamed(self.name), isRecursive)
        elif self.roleName == 'menu item' or self.roleName == 'check menu item':
            return (ancestor, predicate.IsAMenuItemNamed(self.name), isRecursive)
        elif self.roleName == 'text':
            return (ancestor, predicate.IsATextEntryNamed(self.name), isRecursive)
        elif self.roleName == 'push button':
            return (ancestor, predicate.IsAButtonNamed(self.name), isRecursive)
        elif self.roleName == 'frame':
            return (ancestor, predicate.IsAWindowNamed(self.name), isRecursive)
        elif self.roleName == 'dialog':
            return (ancestor, predicate.IsADialogNamed(self.name), isRecursive)
        else:
            pred = predicate.GenericPredicate(
                name=self.name, roleName=self.roleName)
            return (ancestor, pred, isRecursive)
Ejemplo n.º 5
0
    def isChild(self, name='', roleName='', description='', label='', recursive=True, retry=False, debugName=None):
        """
        Determines whether a child satisying the given criteria exists.

        This is implemented using findChild, but will not automatically retry
        if no such child is found. To make the function retry multiple times set retry to True.
        Returns a boolean value depending on whether the child was eventually found. Similar to
        'child', yet it catches SearchError exception to provide for False results, will raise
        any other exceptions. It also logs the search.
        """
        found = True
        try:
            self.findChild(
                predicate.GenericPredicate(
                    name=name, roleName=roleName, description=description, label=label),
                recursive=recursive, retry=retry, debugName=debugName)
        except SearchError:
            found = False
        return found
Ejemplo n.º 6
0
 def applications(self):
     """
     Get all applications.
     """
     return root.findChildren(predicate.GenericPredicate(
         roleName="application"), recursive=False)