Beispiel #1
0
    def _ldtpize_accessible(self, acc):
        """
        Get LDTP format accessibile name

        @param acc: Accessible handle
        @type acc: object

        @return: object type, stripped object name (associated / direct),
                        associated label
        @rtype: tuple
        """
        actual_role = self._get_role(acc)
        label = self._get_title(acc)
        if re.match("AXWindow", actual_role, re.M | re.U | re.L):
            # Strip space and new line from window title
            strip = r"( |\n)"
        else:
            # Strip space, colon, dot, underscore and new line from
            # all other object types
            strip = r"( |:|\.|_|\n)"
        if label:
            # Return the role type (if, not in the know list of roles,
            # return ukn - unknown), strip the above characters from name
            # also return labely_by string
            if not isinstance(label, unicode):
                label = u"%s" % label
            label = re.sub(strip, u"", label)
        role = abbreviated_roles.get(actual_role, "ukn")
        if self._ldtp_debug and role == "ukn":
            print(actual_role, acc)
        return role, label
Beispiel #2
0
    def _ldtpize_accessible(self, acc):
        """
        Get LDTP format accessibile name

        @param acc: Accessible handle
        @type acc: object

        @return: object type, stripped object name (associated / direct),
                        associated label
        @rtype: tuple
        """
        actual_role = self._get_role(acc)
        label = self._get_title(acc)
        if re.match("AXWindow", actual_role, re.M | re.U | re.L):
            # Strip space and new line from window title
            strip = r"( |\n)"
        else:
            # Strip space, colon, dot, underscore and new line from
            # all other object types
            strip = r"( |:|\.|_|\n)"
        if label:
            # Return the role type (if, not in the know list of roles,
            # return ukn - unknown), strip the above characters from name
            # also return labely_by string
            if not isinstance(label, unicode):
                label = u"%s" % label
            label = re.sub(strip, u"", label)
        role = abbreviated_roles.get(actual_role, "ukn")
        if self._ldtp_debug and role == "ukn":
            print actual_role
        return role, label
Beispiel #3
0
 def _ldtpize_accessible(self, acc):
     label_acc = None
     rel_set = acc.getRelationSet()
     if rel_set:
         for i, rel in enumerate(rel_set):
             if rel.getRelationType() == pyatspi.RELATION_LABELLED_BY:
                 label_acc = rel.getTarget(i)
                 break
     return abbreviated_roles.get(acc.getRole(), 'ukn'), \
         (label_acc or acc).name.replace(' ', '').rstrip(':.')
Beispiel #4
0
    def _ldtpize_accessible(self, acc):
        """
        Get LDTP format accessibile name

        @param acc: Accessible handle
        @type acc: object

        @return: object type, stripped object name (associated / direct),
                        associated label
        @rtype: tuple
        """
        label_by = label_acc = None
        try:
            # Get accessible relation set
            rel_set = acc.getRelationSet()
        except:
            rel_set = None
        if rel_set:
            for i, rel in enumerate(rel_set):
                relationType = rel.getRelationType()
                # If object relation is labelled by or controlled by,
                # then give that importance, rather than the direct object label
                if relationType == pyatspi.RELATION_LABELLED_BY or \
                        relationType == pyatspi.RELATION_CONTROLLED_BY:
                    # Get associated label
                    try:
                        label_acc = rel.getTarget(i)
                        break
                    except AttributeError:
                        # With "alacarte" window, doing getbojectlist('Main Menu')
                        # raise exception
                        #   File "/usr/lib/pymodules/python2.6/pyatspi/accessible.py", line 657, in getTarget
                        #    target = target._narrow(Accessibility.Accessible)
                        # exceptions.AttributeError: 'NoneType' object has no attribute '_narrow'
                        # Let us not throw exception, instead continue
                        if self._ldtp_debug:
                            print(traceback.format_exc())
                        continue
        try:
            role = acc.getRole()
        except:
            # with at-spi2 noticed gi._glib.GError exception
            role = None
        if role == pyatspi.ROLE_FRAME or role == pyatspi.ROLE_DIALOG or \
                role == pyatspi.ROLE_WINDOW or \
                role == pyatspi.ROLE_FONT_CHOOSER or \
                role == pyatspi.ROLE_FILE_CHOOSER or \
                role == pyatspi.ROLE_ALERT or \
                role == pyatspi.ROLE_COLOR_CHOOSER:
            # Strip space and new line from window title
            strip = '( |\n)'
        else:
            # Strip space, colon, dot, underscore and new line from
            # all other object types
            strip = '( |:|\.|_|\n)'
        if label_acc:
            try:
                # Priority to associated label
                label_by = label_acc.name
            except:
                label_by = ''
        # Return the role type (if, not in the know list of roles,
        # return ukn - unknown), strip the above characters from name
        # also return labely_by string
        try:
            label = re.sub(strip, '', (label_acc or acc).name)
        except:
            label = ''
        return abbreviated_roles.get(role, 'ukn'), \
            label, \
            label_by
Beispiel #5
0
    def getobjectproperty(self, window_name, object_name, prop):
        '''
        Get object property value.
        
        @param window_name: Window name to look for, either full name,
        LDTP's name convention, or a Unix glob.
        @type window_name: string
        @param object_name: Object name to look for, either full name,
        LDTP's name convention, or a Unix glob. 
        @type object_name: string
        @param prop: property name.
        @type prop: string

        @return: list of properties
        @rtype: list
        '''
        if prop == 'child_index':
            obj = self._get_object(window_name, object_name)
            return obj.getIndexInParent()
        elif prop == 'key':
            obj = self._get_object(window_name, object_name) # A sanity check.
            return object_name # For now, we only match exact names anyway.
        elif prop == 'obj_index':
            role_count = {}
            for gui in self._list_guis():
                if self._match_name_to_acc(window_name, gui):
                    for name, obj in self._appmap_pairs(gui):
                        role = obj.getRole()
                        role_count[role] = role_count.get(role, 0) + 1
                        if name == object_name:
                            return '%s#%d' % (
                                abbreviated_roles.get(role, 'ukn'),
                                role_count.get(role, 1) - 1)

            raise LdtpServerException(
                'Unable to find object name in application map')
        elif prop == 'parent':
            cached_list = []
            for gui in self._list_guis():
                if self._match_name_to_acc(window_name, gui):
                    for name, obj in self._appmap_pairs(gui):
                        if name == object_name:
                            for pname, pobj in cached_list:
                                if obj in pobj: # avoid double link issues
                                    return pname
                            _parent = self._ldtpize_accessible(obj.parent)
                            return '%s%s' % (_parent[0], _parent[1])
                        cached_list.insert(0, (name, obj))

            raise LdtpServerException(
                'Unable to find object name in application map')
        elif prop == 'class':
            obj = self._get_object(window_name, object_name)
            return obj.getRoleName().replace(' ', '_')
        elif prop == 'children':
            children = []
            obj = self._get_object(window_name, object_name)
            for gui in self._list_guis():
                if self._match_name_to_acc(window_name, gui):
                    for name, child in self._appmap_pairs(gui):
                        if child in obj:
                            children.append(name)
                    break
            return ' '.join(children)

        raise LdtpServerException('Unknown property "%s" in %s' % \
                                      (prop, object_name))
Beispiel #6
0
    def _ldtpize_accessible(self, acc):
        """
        Get LDTP format accessibile name

        @param acc: Accessible handle
        @type acc: object

        @return: object type, stripped object name (associated / direct),
                        associated label
        @rtype: tuple
        """
        label_by = label_acc = None
        try:
            # Get accessible relation set
            rel_set = acc.getRelationSet()
        except:
            rel_set = None
        if rel_set:
            for i, rel in enumerate(rel_set):
                relationType = rel.getRelationType()
                # If object relation is labelled by or controlled by,
                # then give that importance, rather than the direct object label
                if relationType == pyatspi.RELATION_LABELLED_BY or \
                        relationType == pyatspi.RELATION_CONTROLLED_BY:
                    # Get associated label
                    try:
                        label_acc = rel.getTarget(i)
                        break
                    except AttributeError:
                        # With "alacarte" window, doing getbojectlist('Main Menu')
                        # raise exception
                        #   File "/usr/lib/pymodules/python2.6/pyatspi/accessible.py", line 657, in getTarget
                        #    target = target._narrow(Accessibility.Accessible)
                        # exceptions.AttributeError: 'NoneType' object has no attribute '_narrow'
                        # Let us not throw exception, instead continue
                        if self._ldtp_debug:
                            print(traceback.format_exc())
                        if self._ldtp_debug_file:
                            with open(self._ldtp_debug_file, "a") as fp:
                                fp.write(traceback.format_exc())
                        continue
        try:
            role = acc.getRole()
        except:
            # with at-spi2 noticed gi._glib.GError exception
            role = None
        if role == pyatspi.ROLE_FRAME or role == pyatspi.ROLE_DIALOG or \
                role == pyatspi.ROLE_WINDOW or \
                role == pyatspi.ROLE_FONT_CHOOSER or \
                role == pyatspi.ROLE_FILE_CHOOSER or \
                role == pyatspi.ROLE_ALERT or \
                role == pyatspi.ROLE_COLOR_CHOOSER:
            # Strip space and new line from window title
            strip = '( |\n)'
        else:
            # Strip space, colon, dot, underscore and new line from
            # all other object types
            strip = '( |:|\.|_|\n)'
        if label_acc:
            try:
                # Priority to associated label
                label_by = label_acc.name
            except:
                label_by = ''
        # Return the role type (if, not in the know list of roles,
        # return ukn - unknown), strip the above characters from name
        # also return labely_by string
        try:
            label = re.sub(strip, '', (label_acc or acc).name)
        except:
            label = ''
        return abbreviated_roles.get(role, 'ukn'), \
            label, \
            label_by