Beispiel #1
0
    def __init__(self, parent=None, text=None,
                 EditorHighlighterClass=PythonHighlighter,
                 indenter=PythonCodeIndenter):
        QPlainTextEdit.__init__(self, parent)
        self.setFrameStyle(QFrame.NoFrame)
        self.setTabStopWidth(4)
        self.setLineWrapMode(QPlainTextEdit.NoWrap)
        font = QFont()
        font.setFamily("lucidasanstypewriter")
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.highlighter = EditorHighlighterClass(self)
        if text:
            self.setPlainText(text)
        self.frame_style = self.frameStyle()
        self.draw_line = True
        self.print_width = self.fontMetrics().width("x"*78)
        self.line_pen = QPen(QColor("lightgrey"))
        self.last_row = self.last_col = -1
        self.last_block = None
        self.highlight_line = True
        self.highlight_color = self.palette().highlight().color().light(175)
        self.highlight_brush = QBrush(QColor(self.highlight_color))
        self.connect(self, SIGNAL("cursorPositionChanged()"), 
                        self.onCursorPositionChanged)
        self.indenter = indenter(RopeEditorWrapper(self))
        # True if you want to catch Emacs keys in actions
        self.disable_shortcuts = False

        self.prj = get_no_project()
        self.prj.root = None
        self.calltip = CallTip(self)
        self.autocomplete = AutoComplete(self)
Beispiel #2
0
    def __init__(self,
                 parent=None,
                 text=None,
                 EditorHighlighterClass=PythonHighlighter,
                 indenter=PythonCodeIndenter):
        QPlainTextEdit.__init__(self, parent)
        self.setFrameStyle(QFrame.NoFrame)
        self.setTabStopWidth(4)
        self.setLineWrapMode(QPlainTextEdit.NoWrap)
        font = QFont()
        font.setFamily("lucidasanstypewriter")
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.highlighter = EditorHighlighterClass(self)
        if text:
            self.setPlainText(text)
        self.frame_style = self.frameStyle()
        self.draw_line = True
        self.print_width = self.fontMetrics().width("x" * 78)
        self.line_pen = QPen(QColor("lightgrey"))
        self.last_row = self.last_col = -1
        self.last_block = None
        self.highlight_line = True
        self.highlight_color = self.palette().highlight().color().light(175)
        self.highlight_brush = QBrush(QColor(self.highlight_color))
        self.connect(self, SIGNAL("cursorPositionChanged()"),
                     self.onCursorPositionChanged)
        self.indenter = indenter(RopeEditorWrapper(self))
        # True if you want to catch Emacs keys in actions
        self.disable_shortcuts = False

        self.prj = get_no_project()
        self.prj.root = None
        self.calltip = CallTip(self)
        self.autocomplete = AutoComplete(self)
Beispiel #3
0
class EditorView(QPlainTextEdit):


    def __init__(self, parent=None, text=None,
                 EditorHighlighterClass=PythonHighlighter,
                 indenter=PythonCodeIndenter):
        QPlainTextEdit.__init__(self, parent)
        self.setFrameStyle(QFrame.NoFrame)
        self.setTabStopWidth(4)
        self.setLineWrapMode(QPlainTextEdit.NoWrap)
        font = QFont()
        font.setFamily("lucidasanstypewriter")
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.highlighter = EditorHighlighterClass(self)
        if text:
            self.setPlainText(text)
        self.frame_style = self.frameStyle()
        self.draw_line = True
        self.print_width = self.fontMetrics().width("x"*78)
        self.line_pen = QPen(QColor("lightgrey"))
        self.last_row = self.last_col = -1
        self.last_block = None
        self.highlight_line = True
        self.highlight_color = self.palette().highlight().color().light(175)
        self.highlight_brush = QBrush(QColor(self.highlight_color))
        self.connect(self, SIGNAL("cursorPositionChanged()"), 
                        self.onCursorPositionChanged)
        self.indenter = indenter(RopeEditorWrapper(self))
        # True if you want to catch Emacs keys in actions
        self.disable_shortcuts = False

        self.prj = get_no_project()
        self.prj.root = None
        self.calltip = CallTip(self)
        self.autocomplete = AutoComplete(self)


    def closeEvent(self, event):
        self.calltip.close()
        self.autocomplete.close()


    def isModified(self):
        return self.document().isModified()


    def setModified(self, flag):
        self.document().setModified(flag)


    def length(self):
        return self.document().blockCount()


    def goto(self, line_no):
        cursor = self.textCursor()
        block = cursor.block()
        row = cursor.blockNumber()
        while row > line_no:
            block = block.previous()
            row -= 1
        while row < line_no:
            block = block.next()
            row += 1
        cursor = QTextCursor(block)
        self.setTextCursor(cursor)


    def move_start_of_doc(self):
        cursor = self.textCursor()
        cursor.setPosition(0)
        self.setTextCursor(cursor)


    def move_end_of_doc(self):
        cursor = self.textCursor()
        block = cursor.block()
        while block.isValid():
            last_block = block
            block = block.next()
        cursor.setPosition(last_block.position())
        cursor.movePosition(
                QTextCursor.EndOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)


    def move_start_of_row(self):
        cursor = self.textCursor()
        cursor.movePosition(
                QTextCursor.StartOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)


    def move_end_of_row(self):
        cursor = self.textCursor()
        cursor.movePosition(
                QTextCursor.EndOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)


    def highline(self, cursor):
        self.viewport().update()


    def onCursorPositionChanged(self):
        cursor = self.textCursor()
        row, col = cursor.blockNumber(), cursor.columnNumber()
        if self.last_row != row:
            self.last_row = row
            if self.highlight_line:
                self.highline(cursor)
        if col != self.last_col:
            self.last_col = col
        self.emit(SIGNAL("cursorPositionChanged(int,int)"), row, col)


    def _create_line(self):
        x = self.print_width
        self.line = QLine(x, 0, x, self.height())

    
    def resizeEvent(self, event):
        self._create_line()
        QPlainTextEdit.resizeEvent(self, event)


    def paintEvent(self, event):
        painter = QPainter(self.viewport())
        if self.highlight_line:
            r = self.cursorRect()
            r.setX(0)
            r.setWidth(self.viewport().width())
            painter.fillRect(r, self.highlight_brush)
        if self.draw_line:
            painter.setPen(self.line_pen)
            painter.drawLine(self.line)
        painter.end()
        QPlainTextEdit.paintEvent(self, event)


    def setDocument(self, document):
        QPlainTextEdit.setDocument(self, document)
        self.highlighter.setDocument(document)


    def indent(self):
        self.indenter.correct_indentation(self.textCursor().blockNumber())


    def tab_pressed(self):
        self.indent()


    def dedent(self):
        self.indenter.deindent(self.textCursor().blockNumber())


    def backtab_pressed(self):
        self.dedent()
        return True


    def backspace_pressed(self):
        cursor = self.textCursor()
        text = unicode(cursor.block().text())
        col = cursor.columnNumber()
        if col > 0 and text[:col].strip() == "":
            self.indenter.deindent(self.textCursor().blockNumber())
            return True


    def autocomplete_pressed(self):
        try:
            items = code_assist(self.prj,
                                unicode(self.toPlainText()),
                                self.textCursor().position())
        except Exception,  e:
            items = []
        if items:
            self.autocomplete.setItems(items)
            self.autocomplete.show()
Beispiel #4
0
class EditorView(QPlainTextEdit):
    def __init__(self,
                 parent=None,
                 text=None,
                 EditorHighlighterClass=PythonHighlighter,
                 indenter=PythonCodeIndenter):
        QPlainTextEdit.__init__(self, parent)
        self.setFrameStyle(QFrame.NoFrame)
        self.setTabStopWidth(4)
        self.setLineWrapMode(QPlainTextEdit.NoWrap)
        font = QFont()
        font.setFamily("lucidasanstypewriter")
        font.setFixedPitch(True)
        font.setPointSize(10)
        self.setFont(font)
        self.highlighter = EditorHighlighterClass(self)
        if text:
            self.setPlainText(text)
        self.frame_style = self.frameStyle()
        self.draw_line = True
        self.print_width = self.fontMetrics().width("x" * 78)
        self.line_pen = QPen(QColor("lightgrey"))
        self.last_row = self.last_col = -1
        self.last_block = None
        self.highlight_line = True
        self.highlight_color = self.palette().highlight().color().light(175)
        self.highlight_brush = QBrush(QColor(self.highlight_color))
        self.connect(self, SIGNAL("cursorPositionChanged()"),
                     self.onCursorPositionChanged)
        self.indenter = indenter(RopeEditorWrapper(self))
        # True if you want to catch Emacs keys in actions
        self.disable_shortcuts = False

        self.prj = get_no_project()
        self.prj.root = None
        self.calltip = CallTip(self)
        self.autocomplete = AutoComplete(self)

    def closeEvent(self, event):
        self.calltip.close()
        self.autocomplete.close()

    def isModified(self):
        return self.document().isModified()

    def setModified(self, flag):
        self.document().setModified(flag)

    def length(self):
        return self.document().blockCount()

    def goto(self, line_no):
        cursor = self.textCursor()
        block = cursor.block()
        row = cursor.blockNumber()
        while row > line_no:
            block = block.previous()
            row -= 1
        while row < line_no:
            block = block.next()
            row += 1
        cursor = QTextCursor(block)
        self.setTextCursor(cursor)

    def move_start_of_doc(self):
        cursor = self.textCursor()
        cursor.setPosition(0)
        self.setTextCursor(cursor)

    def move_end_of_doc(self):
        cursor = self.textCursor()
        block = cursor.block()
        while block.isValid():
            last_block = block
            block = block.next()
        cursor.setPosition(last_block.position())
        cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)

    def move_start_of_row(self):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.StartOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)

    def move_end_of_row(self):
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.MoveAnchor)
        self.setTextCursor(cursor)

    def highline(self, cursor):
        self.viewport().update()

    def onCursorPositionChanged(self):
        cursor = self.textCursor()
        row, col = cursor.blockNumber(), cursor.columnNumber()
        if self.last_row != row:
            self.last_row = row
            if self.highlight_line:
                self.highline(cursor)
        if col != self.last_col:
            self.last_col = col
        self.emit(SIGNAL("cursorPositionChanged(int,int)"), row, col)

    def _create_line(self):
        x = self.print_width
        self.line = QLine(x, 0, x, self.height())

    def resizeEvent(self, event):
        self._create_line()
        QPlainTextEdit.resizeEvent(self, event)

    def paintEvent(self, event):
        painter = QPainter(self.viewport())
        if self.highlight_line:
            r = self.cursorRect()
            r.setX(0)
            r.setWidth(self.viewport().width())
            painter.fillRect(r, self.highlight_brush)
        if self.draw_line:
            painter.setPen(self.line_pen)
            painter.drawLine(self.line)
        painter.end()
        QPlainTextEdit.paintEvent(self, event)

    def setDocument(self, document):
        QPlainTextEdit.setDocument(self, document)
        self.highlighter.setDocument(document)

    def indent(self):
        self.indenter.correct_indentation(self.textCursor().blockNumber())

    def tab_pressed(self):
        self.indent()

    def dedent(self):
        self.indenter.deindent(self.textCursor().blockNumber())

    def backtab_pressed(self):
        self.dedent()
        return True

    def backspace_pressed(self):
        cursor = self.textCursor()
        text = unicode(cursor.block().text())
        col = cursor.columnNumber()
        if col > 0 and text[:col].strip() == "":
            self.indenter.deindent(self.textCursor().blockNumber())
            return True

    def autocomplete_pressed(self):
        try:
            items = code_assist(self.prj, unicode(self.toPlainText()),
                                self.textCursor().position())
        except Exception, e:
            items = []
        if items:
            self.autocomplete.setItems(items)
            self.autocomplete.show()