Ejemplo n.º 1
0
def import_document(win, syncvar):
    root = win.syntax_info
    if not root:
        return

    lineno = win.GetCurrentLine() + 1
    result = root.get_imports(lineno)
    pout("import_document")
    for importline, line in result:
        if syncvar and not syncvar.empty:
            raise StopException

        pout("import", importline, line)
        if importline.startswith("from"):
            try:
                exec(importline) in namespace
            except:
                # error.traceback()
                pass
        elif importline.startswith("import"):
            try:
                exec(importline) in namespace
            except:
                #                error.traceback()
                pass
Ejemplo n.º 2
0
def import_document(win, syncvar):
    root = win.syntax_info
    if not root:
        return
    
    lineno = win.GetCurrentLine() + 1
    result = root.get_imports(lineno)
    pout('import_document')
    for importline, line in result:
        if syncvar and not syncvar.empty:
            raise StopException
        
        pout('import', importline, line)
        if importline.startswith('from'):
            try:
                exec(importline) in namespace
            except:
                #error.traceback()
                pass
        elif importline.startswith('import'):
            try:
                exec(importline) in namespace
            except:
#                error.traceback()
                pass
Ejemplo n.º 3
0
def try_get_obj_type(win, t, v, lineno):
    pout(INDENT, "try_get_obj_type", t, v, lineno)
    flag = "obj"
    node = None
    if t in ("class", "function"):
        node = v
        flag = "source"
    elif t not in ("reference", "import"):
        node = v
    else:
        node = getObject(win, v)
    return flag, node
Ejemplo n.º 4
0
def try_get_obj_type(win, t, v, lineno):
    pout(INDENT, "try_get_obj_type", t, v, lineno)
    flag = 'obj'
    node = None
    if t in ('class', 'function'):
        node = v
        flag = 'source'
    elif t not in ('reference', 'import'):
        node = v
    else:
        node = getObject(win, v)
    return flag, node
Ejemplo n.º 5
0
def try_get_obj_type(win, t, v, lineno):
    pout(INDENT, "try_get_obj_type", t, v, lineno)
    flag = 'obj'
    node = None
    if t in ('class', 'function'):
        node = v
        flag = 'source'
    elif t not in ('reference', 'import'):
        node = v
    else:
        node = getObject(win, v)
    return flag, node
Ejemplo n.º 6
0
def getAutoCompleteList(win, command="", syncvar=None):
    from modules.callinmainthread import CallFunctionOnMainThread

    _getattributes = CallFunctionOnMainThread(getattributes)
    #    if not hasattr(win, 'syntax_info') or not win.syntax_info:
    #        return []

    if hasattr(win, "syntax_info") and win.syntax_info:
        root = win.syntax_info
        r_idens = _get_filter_list(win, command, root.idens)
    else:
        r_idens = []

    pout("-" * 50)
    pout("getAutoCompleteList", command)

    v = guessWordObject(win, command, True, syncvar)
    flag, object = v
    pout(INDENT, "ready to output:", flag, object)
    if object:
        if flag == "obj":
            return _getattributes(object) + r_idens
        else:
            if object.type == "class":
                return getClassAttributes(win, object, syncvar) + r_idens
    pout(INDENT, "return:", "***")
    return r_idens
Ejemplo n.º 7
0
def getAutoCompleteList(win, command='', syncvar=None):
    from modules.callinmainthread import CallFunctionOnMainThread
    
    _getattributes = CallFunctionOnMainThread(getattributes)
#    if not hasattr(win, 'syntax_info') or not win.syntax_info:
#        return []

    if hasattr(win, 'syntax_info') and win.syntax_info:
        root = win.syntax_info
        r_idens = _get_filter_list(win, command, root.idens)
    else:
        r_idens = []
        
    pout('-'*50)
    pout('getAutoCompleteList', command)

    v = guessWordObject(win, command, True, syncvar)
    flag, object = v
    pout(INDENT, 'ready to output:', flag, object)
    if object:
        if flag == 'obj':
            return _getattributes(object) + r_idens
        else:
            if object.type == 'class':
                return getClassAttributes(win, object, syncvar) + r_idens
    pout(INDENT, 'return:', '***')
    return r_idens
Ejemplo n.º 8
0
def getObject(win, word, syncvar=None):
    pout(INDENT, "getObject:", word)
    object = None
    line = win.GetLine(win.GetCurrentLine())

    if syncvar and not syncvar.empty:
        raise StopException

    if re_match.match(line):
        if sys.modules.has_key(word):
            object = sys.modules[word]
        else:
            try:
                object = __import__(word, [], [], [""])
            except:
                pass
    else:
        object = evaluate(win, word, syncvar)
    #        try:
    #            object = eval(word, namespace)
    #            if syncvar and not syncvar.empty:
    #                raise StopException
    #        except:
    #            try:
    #                import_document(win, syncvar)
    #                if syncvar and not syncvar.empty:
    #                    raise StopException
    #
    #                object = eval(word, namespace)
    #            except:
    #                try:
    #                    pout(INDENT*2, 'import %s' % word)
    #                    exec('import %s' % word) in namespace
    #                    object = eval(word, namespace)
    #                except:
    #                    pass
    pout(INDENT, "getObject result [%s]:" % word, object)
    return object
Ejemplo n.º 9
0
def getObject(win, word, syncvar=None):
    pout(INDENT, 'getObject:', word)
    object = None
    line = win.GetLine(win.GetCurrentLine())

    if syncvar and not syncvar.empty:
        raise StopException
    
    if re_match.match(line):
        if sys.modules.has_key(word):
            object = sys.modules[word]
        else:
            try:
                object = __import__(word, [], [], [''])
            except:
                pass
    else:
        object = evaluate(win, word, syncvar)
#        try:
#            object = eval(word, namespace)
#            if syncvar and not syncvar.empty:
#                raise StopException
#        except:
#            try:
#                import_document(win, syncvar)
#                if syncvar and not syncvar.empty:
#                    raise StopException
#                
#                object = eval(word, namespace)
#            except:
#                try:
#                    pout(INDENT*2, 'import %s' % word)
#                    exec('import %s' % word) in namespace
#                    object = eval(word, namespace)
#                except:
#                    pass
    pout(INDENT, 'getObject result [%s]:' % word, object)
    return object
Ejemplo n.º 10
0
def get_calltip(win, word, syncvar):
    if not hasattr(win, "syntax_info") or not win.syntax_info:
        return []

    pout("-" * 50)
    pout("get_calltip", word)

    flag, object = guessWordObject(win, word, False, syncvar)

    pout(INDENT, "ready to output:", flag, object)
    if object:
        if flag == "obj":
            signature = getargspec(win, object)
            doc = object.__doc__
            return filter(None, [signature, doc])
        else:
            if object.type == "function":
                return unicode("\n".join([object.info, object.docstring]), "utf8")
            elif object.type == "class":
                s = []
                s.append(object.docstring)
                t = object.get_local_name("__init__")
                c = object.get_local_name("__call__")
                if t:
                    _obj = t[1]
                    s.append("\n")
                    s.append(_obj.info)
                    s.append(_obj.docstring)
                if c:
                    _obj1 = c[1]
                    s.append("\n")
                    s.append(_obj1.info)
                    s.append(_obj1.docstring)
                return unicode("\n".join(s), "utf8")

    pout(INDENT, "return:", None)
    return None
Ejemplo n.º 11
0
def get_calltip(win, word, syncvar):
    if not hasattr(win, 'syntax_info') or not win.syntax_info:
        return []
    
    pout('-'*50)
    pout('get_calltip', word)
    
    flag, object = guessWordObject(win, word, False, syncvar)

    pout(INDENT, 'ready to output:', flag, object)
    if object:
        if flag == 'obj':
            signature = getargspec(win,object)
            doc = object.__doc__
            return filter(None, [signature, doc])
        else:
            if object.type == 'function':
                return '\n'.join([object.info, object.docstring])
            elif object.type == 'class':
                s = []
                s.append(object.docstring)
                t = object.get_local_name('__init__')
                c = object.get_local_name('__call__')
                if  t:
                    _obj = t[1]
                    s.append("\n")
                    s.append(_obj.info)
                    s.append(_obj.docstring)
                if  c:
                    _obj1 = c[1]
                    s.append("\n")
                    s.append(_obj1.info)
                    s.append(_obj1.docstring)
                return '\n'.join(s)
                
    pout(INDENT, 'return:', None)
    return None
Ejemplo n.º 12
0
def get_calltip(win, word, syncvar):
    if not hasattr(win, 'syntax_info') or not win.syntax_info:
        return []
    
    pout('-'*50)
    pout('get_calltip', word)
    
    flag, object = guessWordObject(win, word, False, syncvar)

    pout(INDENT, 'ready to output:', flag, object)
    if object:
        if flag == 'obj':
            signature = getargspec(win,object)
            doc = object.__doc__
            return filter(None, [signature, doc])
        else:
            if object.type == 'function':
                return unicode('\n'.join([object.info, object.docstring]), 'utf8')
            elif object.type == 'class':
                s = []
                s.append(object.docstring)
                t = object.get_local_name('__init__')
                c = object.get_local_name('__call__')
                if  t:
                    _obj = t[1]
                    s.append("\n")
                    s.append(_obj.info)
                    s.append(_obj.docstring)
                if  c:
                    _obj1 = c[1]
                    s.append("\n")
                    s.append(_obj1.info)
                    s.append(_obj1.docstring)
                return unicode('\n'.join(s), 'utf8')
                
    pout(INDENT, 'return:', None)
    return None
Ejemplo n.º 13
0
def try_get_obj_attribute(win, firstword, flag, object, attributes):
    pout(INDENT, "try_get_obj_attribute", firstword, flag, object, attributes)
    root = win.syntax_info
    if object:
        if flag == "obj":
            if len(attributes) > 1 and attributes[:-1] == "":
                attrs = attributes[:-1]
            else:
                attrs = attributes
            s = []
            for a in attrs:
                if not a:
                    break
                pout(INDENT * 2, "get attribute", a)
                s.append(a)
                if hasattr(object, a):
                    object = getattr(object, a)
                    pout(INDENT * 2, "found", firstword, s)
                else:
                    pout(INDENT * 2, "unfound", "try to get", ".".join([firstword] + s))
                    object = getObject(win, ".".join([firstword] + s))
                    if not object:
                        break
        else:
            if not root:
                return flag, None

            o = attributes[0]
            del attributes[0]
            r = object.get_local_name(o)
            if r:
                t, v, line = r
                if t == "reference":
                    gt = root.guess_type(line, v)
                    if gt:
                        t, v = gt

                flag, object = try_get_obj_type(win, t, v, line)
                if attributes:
                    return try_get_obj_attribute(win, firstword, flag, object, attributes)
                else:
                    return flag, object
            else:
                for b in object.bases:
                    c = root.search_name(object.lineno, b)
                    if c:
                        cls = root.guess_class(c[2])
                        gr = cls.get_local_name(o)
                        if gr:
                            t, v, line = gr
                            if t == "reference":
                                gt = root.guess_type(line, v)
                                if gt:
                                    t, v = gt
                            flag, object = try_get_obj_type(win, t, v, line)
                            if attributes:
                                return try_get_obj_attribute(win, firstword, flag, object, attributes)
                            else:
                                return flag, object
                    else:
                        flag = "obj"
                        obj = getObject(win, b)
                        if hasattr(obj, o):
                            return flag, getattr(obj, o)

                object = None
    return flag, object
Ejemplo n.º 14
0
def guessWordObject(win, command, striplast=True, syncvar=None):
    """
    Guess command's type, if striplast is True, then don't care the last
    word. command will be splitted into list according to '.'
    """
    root = win.syntax_info
    attributes = []
    # Get the proper chunk of code from the command.
    flag = None
    object = None
    #    while command.endswith('.'):
    #        command = command[:-1]

    if syncvar and not syncvar.empty:
        raise StopException

    lineno = win.GetCurrentLine() + 1
    attributes = command.split(".")
    if command == "self.":  # process self.
        if not root:
            return flag, object
        cls = root.guess_class(lineno)
        if cls:
            return "source", cls
    elif command.startswith("self."):  # process self.a. then treat self.a as a var
        if len(attributes) == 2:  # self.xxx
            pass
        else:
            key = attributes[0] + "." + attributes[1]
            del attributes[0]
            attributes[0] = key
    else:
        if root:
            result = root.guess_type(lineno, command)
            if result:
                attributes = [command]

    if syncvar and not syncvar.empty:
        raise StopException

    # deal first word
    firstword = attributes[0]
    del attributes[0]
    pout(INDENT, "attributes:", attributes, "firstword:", firstword)
    if root:
        result = root.guess_type(lineno, firstword)
    else:
        result = None
    pout(INDENT, "guess [%s] result:" % firstword, result)

    if syncvar and not syncvar.empty:
        raise StopException

    if striplast:
        if attributes:
            del attributes[-1]

    if result:
        t, v = result
        pout(INDENT, "begin try_get_obj_type:", t, v, attributes)
        flag, object = try_get_obj_type(win, t, v, lineno)
        pout(INDENT, "result:", flag, object, attributes)

        if syncvar and not syncvar.empty:
            raise StopException

        if not attributes or attributes[0] == "":
            return flag, object

        if flag == "source" or attributes:
            # deal other rest
            flag, object = try_get_obj_attribute(win, firstword, flag, object, attributes)
            pout(INDENT, "result:", flag, "object=", object)
    else:
        if firstword.startswith("self."):
            word = firstword.split(".", 1)[1]
            if root:
                cls = root.guess_class(lineno)
            else:
                cls = None

            if syncvar and not syncvar.empty:
                raise StopException

            if cls:
                for b in cls.bases:
                    if syncvar and not syncvar.empty:
                        raise StopException

                    obj = getObject(win, b, syncvar)
                    if obj:
                        if hasattr(obj, word):
                            object = getattr(obj, word)
                            flag = "obj"
        else:
            flag = "obj"
            object = getObject(win, firstword, syncvar)
            if object:
                s = []
                for a in attributes:
                    if not a:
                        break
                    pout(INDENT * 2, "get attribute", a)
                    s.append(a)
                    if hasattr(object, a):
                        object = getattr(object, a)
                        pout(INDENT * 2, "found", firstword, s)
                    else:
                        pout(INDENT * 2, "unfound", "try to get", ".".join([firstword] + s))
                        object = getObject(win, ".".join([firstword] + s), syncvar)
                        if not object:
                            break

    if syncvar and not syncvar.empty:
        raise StopException

    return flag, object
Ejemplo n.º 15
0
def try_get_obj_attribute(win, firstword, flag, object, attributes):
    pout(INDENT, "try_get_obj_attribute", firstword, flag, object, attributes)
    root = win.syntax_info
    if object:
        if flag == 'obj':
            if len(attributes) > 1 and attributes[:-1] == '':
                attrs = attributes[:-1]
            else:
                attrs = attributes
            s = []
            for a in attrs:
                if not a:
                    break
                pout(INDENT*2, 'get attribute', a)
                s.append(a)
                if hasattr(object, a):
                    object = getattr(object, a)
                    pout(INDENT*2, 'found', firstword, s)
                else:
                    pout(INDENT*2, 'unfound', 'try to get', '.'.join([firstword]+s))
                    object = getObject(win, '.'.join([firstword]+s))
                    if not object:
                        break
        else:
            if not root:
                return flag, None
            
            o = attributes[0]
            del attributes[0]
            r = object.get_local_name(o)
            if r:
                t, v, line = r
                if t == 'reference':
                    gt = root.guess_type(line, v)
                    if gt:
                        t, v = gt
                
                flag, object = try_get_obj_type(win, t, v, line)
                if attributes:
                    return try_get_obj_attribute(win, firstword, flag, object, attributes)
                else:
                    return flag, object
            else:
                for b in object.bases:
                    c = root.search_name(object.lineno, b)
                    if c:
                        cls = root.guess_class(c[2])
                        gr = cls.get_local_name(o)
                        if gr:
                           t, v, line = gr
                           if t == 'reference':
                               gt = root.guess_type(line, v)
                               if gt:
                                   t, v = gt
                           flag, object = try_get_obj_type(win, t, v, line)
                           if attributes:
                               return try_get_obj_attribute(win, firstword, flag, object, attributes)
                           else:
                               return flag, object
                    else:
                        flag = 'obj'
                        obj = getObject(win, b)
                        if hasattr(obj, o):
                            return flag, getattr(obj, o)
                
                object = None
    return flag, object
Ejemplo n.º 16
0
def guessWordObject(win, command, striplast=True, syncvar=None):
    '''
    Guess command's type, if striplast is True, then don't care the last
    word. command will be splitted into list according to '.'
    '''
    root = win.syntax_info
    attributes = []
    # Get the proper chunk of code from the command.
    flag = None
    object = None
#    while command.endswith('.'):
#        command = command[:-1]
    
    if syncvar and not syncvar.empty:
        raise StopException
    
    lineno = win.GetCurrentLine() + 1
    attributes = command.split('.')
    if command == 'self.':    #process self.
        if not root:
            return flag, object
        cls = root.guess_class(lineno)
        if cls:
            return 'source', cls
    elif command.startswith('self.'):   #process self.a. then treat self.a as a var
        if len(attributes) == 2:    #self.xxx
            pass
        else:
            key = attributes[0] + '.' + attributes[1]
            del attributes[0]
            attributes[0] = key
    else:
        if root:
            result = root.guess_type(lineno, command)
            if result:
                attributes = [command]
        
    if syncvar and not syncvar.empty:
        raise StopException
   
    #deal first word
    firstword = attributes[0]
    del attributes[0]
    pout(INDENT, 'attributes:', attributes, 'firstword:', firstword)
    if root:
        result = root.guess_type(lineno, firstword)
    else:
        result = None
    pout(INDENT, 'guess [%s] result:' % firstword, result)
    
    if syncvar and not syncvar.empty:
        raise StopException
    
    if striplast:
        if attributes:
            del attributes[-1]
            
    if result:
        t, v = result
        pout(INDENT, 'begin try_get_obj_type:', t, v, attributes)
        flag, object = try_get_obj_type(win, t, v, lineno)
        pout(INDENT, 'result:', flag, object, attributes)
        
        if syncvar and not syncvar.empty:
            raise StopException
        
        if not attributes or attributes[0] == '':
            return flag, object
        
        if flag == 'source' or attributes:
            #deal other rest
            flag, object = try_get_obj_attribute(win, firstword, flag, object, attributes)
            pout(INDENT, 'result:', flag, 'object=', object)
    else:
        if firstword.startswith('self.'):
            word = firstword.split('.', 1)[1]
            if root:
                cls = root.guess_class(lineno)
            else:
                cls = None
            
            if syncvar and not syncvar.empty:
                raise StopException
            
            if cls:
                for b in cls.bases:
                    if syncvar and not syncvar.empty:
                        raise StopException
                    
                    obj = getObject(win, b, syncvar)
                    if obj:
                        if hasattr(obj, word):
                            object = getattr(obj, word)
                            flag = 'obj'
        else:
            flag = 'obj'
            object = getObject(win, firstword, syncvar)
            if object:
                s = []
                for a in attributes:
                    if not a:
                        break
                    pout(INDENT*2, 'get attribute', a)
                    s.append(a)
                    if hasattr(object, a):
                        object = getattr(object, a)
                        pout(INDENT*2, 'found', firstword, s)
                    else:
                        pout(INDENT*2, 'unfound', 'try to get', '.'.join([firstword]+s))
                        object = getObject(win, '.'.join([firstword]+s), syncvar)
                        if not object:
                            break

    if syncvar and not syncvar.empty:
        raise StopException
    
    return flag, object