Ejemplo n.º 1
0
def check_for_assistance_completion(editorWidget, line):
    #This will be possible when code completion is working
    global patClass
    if patClass.match(line):
        source = unicode(editorWidget.toPlainText())
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [name for name in
            re.split("(\\s)*class(\\s)+|:|\(", line) \
            if name is not None and name.strip()][0]
        if 'classes' in symbols and clazzName in symbols['classes']:
            clazz = symbols['classes'][clazzName]
            if '__init__' in clazz[1]['functions']:
                return
        editorWidget.textCursor().insertText('\n')
        spaces = get_leading_spaces(line)
        indent = ' ' * 4
        if spaces:
            indent += ' ' * (len(spaces) - 1)
        editorWidget.textCursor().insertText(indent + 'def __init__(self):\n')
        indent += ' ' * 4
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                editorWidget.textCursor().insertText(
                    indent + "super({0}, self).__init__()\n".format(clazzName))
                editorWidget.textCursor().insertText(indent)
            else:
                editorWidget.textCursor().insertText(indent)
        else:
            editorWidget.textCursor().insertText(indent)
    elif patExcept.match(line):
        block = editorWidget.textCursor().block()
        previous = block.previous()
        while unicode(previous.text()).find('try:') == -1:
            previous = previous.previous()
        try_line = unicode(previous.text())
        if try_line.find('try:') != -1:
            cursor = editorWidget.textCursor()
            cursor.beginEditBlock()
            indentation = get_indentation(try_line)
            last_line = indentation + unicode(block.text()).strip()
            cursor.movePosition(QTextCursor.StartOfLine,
                QTextCursor.KeepAnchor)
            cursor.insertText(last_line)
            indentation = indentation[:-settings.INDENT]
            previous = block.previous()
            last_line = indentation + line.strip()
            cursor.movePosition(QTextCursor.Up)
            cursor.movePosition(QTextCursor.EndOfLine)
            cursor.movePosition(QTextCursor.StartOfLine,
                QTextCursor.KeepAnchor)
            cursor.insertText(last_line)
            cursor.endEditBlock()
Ejemplo n.º 2
0
 def create_class(self, path):
     content = file_manager.read_file_content(path)
     items = introspection.obtain_symbols(content)
     mYPadding = 10
     mXPadding = 10
     for classname, classdetail in list(items["classes"].items()):
         cl = ClassModel(self.graphicView, self.scene)
         cl.set_class_name(classname)
         self.fill_clases(cl, classdetail[1])
         self.scene.addItem(cl)
         cl.setPos(self.mX, self.mY)
         self.mX += cl._get_width() + mXPadding
         if self.hightestY < self.mY + cl.get_height():
             self.hightestY = self.mY + cl.get_height()
         if self.mX > 2000:
             self.mX = -400
             self.mY += self.hightestY + mYPadding
Ejemplo n.º 3
0
 def create_class(self, path):
     content = file_manager.read_file_content(path)
     items = introspection.obtain_symbols(content)
     mYPadding = 10
     mXPadding = 10
     for classname, classdetail in list(items["classes"].items()):
         cl = ClassModel(self.graphicView, self.scene)
         cl.set_class_name(classname)
         self.fill_clases(cl, classdetail[1])
         self.scene.addItem(cl)
         cl.setPos(self.mX, self.mY)
         self.mX += cl._get_width() + mXPadding
         if self.hightestY < self.mY + cl.get_height():
             self.hightestY = self.mY + cl.get_height()
         if self.mX > 2000:
             self.mX = -400
             self.mY += self.hightestY + mYPadding
Ejemplo n.º 4
0
def check_for_assistance_completion(editorWidget, line):
    global patClass
    if patClass.match(line) and editorWidget.lang == 'python':
        source = editorWidget.text()
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [
            name for name in re.split("(\\s)*class(\\s)+|:|\(", line)
            if name is not None and name.strip()
        ][0]
        clazz_key = [
            item for item in symbols.get('classes', [])
            if item.startswith(clazzName)
        ]
        if clazz_key:
            clazz = symbols['classes'][clazz_key['lineno']]
            if [
                    init for init in clazz['members']['functions']
                    if init.startswith('__init__')
            ]:
                return
        lnumber, index = editorWidget.getCursorPosition()
        indent = get_indentation(line, editorWidget._indent,
                                 editorWidget.useTabs)
        init_def = 'def __init__(self):'
        definition = "\n%s%s\n%s" % (indent, init_def, indent * 2)

        super_include = ''
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                super_include = "super({0}, self).__init__()".format(clazzName)
                definition = "\n%s%s\n%s%s\n%s" % (
                    indent, init_def, indent * 2, super_include, indent * 2)

        editorWidget.insertAt(definition, lnumber, index)
        lines = definition.count("\n") + 1
        line_pos = lnumber + lines
        editorWidget.setCursorPosition(line_pos,
                                       editorWidget.lineLength(line_pos))
Ejemplo n.º 5
0
def check_for_assistance_completion(editorWidget, line):
    global patClass
    if patClass.match(line) and editorWidget.lang == 'python':
        source = editorWidget.text()
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [
            name for name in re.split("(\\s)*class(\\s)+|:|\(", line)
            if name is not None and name.strip()
        ][0]
        clazz_key = [
            item for item in symbols.get('classes', [])
            if item.startswith(clazzName)
        ]
        if clazz_key:
            clazz = symbols['classes'][clazz_key['lineno']]
            if [
                    init for init in clazz['members']['functions']
                    if init.startswith('__init__')
            ]:
                return
        lnumber, index = editorWidget.getCursorPosition()
        indent = get_indentation(line, editorWidget._indent,
                                 editorWidget.useTabs)
        init_def = 'def __init__(self):'
        definition = "\n%s%s\n%s" % (indent, init_def, indent * 2)

        super_include = ''
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                super_include = "super({0}, self).__init__()".format(clazzName)
                definition = "\n%s%s\n%s%s\n%s" % (
                    indent, init_def, indent * 2, super_include, indent * 2)

        editorWidget.insertAt(definition, lnumber, index)
        lines = definition.count("\n") + 1
        line_pos = lnumber + lines
        editorWidget.setCursorPosition(line_pos,
                                       editorWidget.lineLength(line_pos))
Ejemplo n.º 6
0
def check_for_assistance_completion(editorWidget, line):
    #This will be possible when code completion is working
    global patClass
    if patClass.match(line) and editorWidget.lang == 'python':
        source = editorWidget.toPlainText()
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [
            name for name in re.split("(\\s)*class(\\s)+|:|\(", line)
            if name is not None and name.strip()
        ][0]
        clazz_key = [
            item for item in symbols.get('classes', [])
            if item.startswith(clazzName)
        ]
        if clazz_key:
            clazz = symbols['classes'][clazz_key['lineno']]
            if [
                    init for init in clazz['members']['functions']
                    if init.startswith('__init__')
            ]:
                return
        editorWidget.textCursor().insertText('\n')
        indent = get_indentation(line, editorWidget.indent,
                                 editorWidget.useTabs)
        editorWidget.textCursor().insertText(indent + 'def __init__(self):\n')
        if editorWidget.useTabs:
            indent += '\t'
        else:
            indent += ' ' * editorWidget.indent
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                editorWidget.textCursor().insertText(
                    indent + "super({0}, self).__init__()\n".format(clazzName))
                editorWidget.textCursor().insertText(indent)
            else:
                editorWidget.textCursor().insertText(indent)
        else:
            editorWidget.textCursor().insertText(indent)
Ejemplo n.º 7
0
def check_for_assistance_completion(editorWidget, line):
    #This will be possible when code completion is working
    global patClass
    if patClass.match(line) and editorWidget.lang == 'python':
        source = editorWidget.toPlainText()
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [name for name in
            re.split("(\\s)*class(\\s)+|:|\(", line)
            if name is not None and name.strip()][0]
        clazz_key = [item for item in symbols.get('classes', [])
            if item.startswith(clazzName)]
        if clazz_key:
            clazz = symbols['classes'][clazz_key[0]]
            if [init for init in clazz[1]['functions']
               if init.startswith('__init__')]:
                return
        editorWidget.textCursor().insertText('\n')
        indent = get_indentation(
            line, editorWidget.indent, editorWidget.useTabs)
        editorWidget.textCursor().insertText(indent + 'def __init__(self):\n')
        if editorWidget.useTabs:
            indent += '\t'
        else:
            indent += ' ' * editorWidget.indent
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                editorWidget.textCursor().insertText(
                    indent + "super({0}, self).__init__()\n".format(clazzName))
                editorWidget.textCursor().insertText(indent)
            else:
                editorWidget.textCursor().insertText(indent)
        else:
            editorWidget.textCursor().insertText(indent)
Ejemplo n.º 8
0
def check_for_assistance_completion(editorWidget, line):
    #This will be possible when code completion is working
    global patClass
    global patInit
    if patClass.match(line):
        source = unicode(editorWidget.toPlainText())
        source = source.encode(editorWidget.encoding)
        symbols = introspection.obtain_symbols(source)
        clazzName = [name for name in
            re.split("(\\s)*class(\\s)+|:|\(", line) \
            if name is not None and name.strip()][0]
        if 'classes' in symbols and clazzName in symbols['classes']:
            clazz = symbols['classes'][clazzName]
            if '__init__' in clazz[1]['functions']:
                return
        editorWidget.textCursor().insertText('\n')
        spaces = get_leading_spaces(line)
        indent = ' ' * 4
        if spaces:
            indent += ' ' * (len(spaces) - 1)
        editorWidget.textCursor().insertText(indent + 'def __init__(self):\n')
        indent += ' ' * 4
        if line.find('(') != -1:
            classes = line.split('(')
            parents = []
            if len(classes) > 1:
                parents += classes[1].split(',')
            if len(parents) > 0 and 'object):' not in parents:
                editorWidget.textCursor().insertText(
                    indent + "super({0}, self).__init__()\n".format(clazzName))
                editorWidget.textCursor().insertText(indent)
            else:
                editorWidget.textCursor().insertText(indent)
        else:
            editorWidget.textCursor().insertText(indent)
    if patInit.match(line):
        pass
Ejemplo n.º 9
0
 def obtain_symbols(self, source):
     """
     Returns the symbols for Python Language
     """
     return introspection.obtain_symbols(source)