Example #1
0
    def get_resource(self, resource_name):
        """Get a resource in a project.

        `resource_name` is the path of a resource in a project.  It is
        the path of a resource relative to project root.  Project root
        folder address is an empty string.  If the resource does not
        exist a `exceptions.ResourceNotFound` exception would be
        raised.  Use `get_file()` and `get_folder()` when you need to
        get nonexistent `Resource`\s.

        """
        path = self._get_resource_path(resource_name)
        if not os.path.exists(path):
            raise exceptions.ResourceNotFoundError(
                'Resource <%s> does not exist' % resource_name)
        elif os.path.isfile(path):
            return File(self, resource_name)
        elif os.path.isdir(path):
            return Folder(self, resource_name)
        else:
            raise exceptions.ResourceNotFoundError('Unknown resource ' +
                                                   resource_name)
Example #2
0
 def get_file(self, path):
     """Get the file with `path` (it may not exist)"""
     return File(self, path)
Example #3
0

ICONS = {
    #types
    'variable': Icon.variable,
    'parameter': Icon.variable,
    'function': Icon.method,
    'class': Icon.klass,
    'imported': Icon.namespace,
    'builtin': Icon.struct,
    #kids
    'attribute': Icon.member,
}


def sort_function(element):
    #scintilla requires the list sorted
    #return KINDS.get(element.kind), TYPES.get(element.type), element.name
    return element.name


project = Project(project_path)
resource = File(project, name=file_name)
elements = codeassist.code_assist(project, source, position, resource=resource)
elements.sort(key=sort_function)

for element in elements:
    icon = ICONS.get(element.type) or ICONS.get(element.kind) or '?7'
    #print element
    print element.name + icon