diff --git a/python/console/console_editor.py b/python/console/console_editor.py index deb287a4652..837423772b3 100644 --- a/python/console/console_editor.py +++ b/python/console/console_editor.py @@ -78,6 +78,9 @@ class Editor(QsciScintilla): self.parent = parent ## recent modification time self.mtime = 0 + self.opening = ['(', '{', '[', "'", '"'] + self.closing = [')', '}', ']', "'", '"'] + self.settings = QSettings() # Enable non-ascii chars for editor @@ -114,10 +117,13 @@ class Editor(QsciScintilla): self.setMinimumHeight(120) #self.setMinimumWidth(300) + self.setBraceMatching(QsciScintilla.SloppyBraceMatch) + self.setMatchedBraceBackgroundColor(QColor("#c6c6c6")) + # Folding self.setFolding(QsciScintilla.PlainFoldStyle) self.setFoldMarginColors(QColor("#f4f4f4"),QColor("#f4f4f4")) - #self.setWrapMode(QsciScintilla.WrapCharacter) + #self.setWrapMode(QsciScintilla.WrapWord) ## Edge Mode self.setEdgeMode(QsciScintilla.EdgeLine) @@ -127,6 +133,7 @@ class Editor(QsciScintilla): #self.setWrapMode(QsciScintilla.WrapCharacter) self.setWhitespaceVisibility(QsciScintilla.WsVisibleAfterIndent) #self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) + self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.settingsEditor() @@ -552,6 +559,14 @@ class Editor(QsciScintilla): self.ensureLineVisible(linenr) self.setFocus() + def keyPressEvent(self, e): + t = unicode(e.text()) + ## Close bracket automatically + if t in self.opening: + i = self.opening.index(t) + self.insert(self.closing[i]) + QsciScintilla.keyPressEvent(self, e) + def focusInEvent(self, e): pathfile = self.parent.path if pathfile: diff --git a/python/console/console_output.py b/python/console/console_output.py index 162a2f23782..1e4f6148578 100644 --- a/python/console/console_output.py +++ b/python/console/console_output.py @@ -47,11 +47,12 @@ class writeOut: self.sO.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1) else: self.sO.append(m) - self.move_cursor_to_end() if self.out: self.out.write(m) + self.move_cursor_to_end() + def move_cursor_to_end(self): """Move cursor to end of text""" line, index = self.get_end_pos() diff --git a/python/console/console_sci.py b/python/console/console_sci.py index 9de40baf622..872af396716 100644 --- a/python/console/console_sci.py +++ b/python/console/console_sci.py @@ -43,6 +43,9 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter): self.parent = parent + self.opening = ['(', '{', '[', "'", '"'] + self.closing = [')', '}', ']', "'", '"'] + self.settings = QSettings() # Enable non-ascii chars for editor @@ -69,6 +72,7 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter): # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(QsciScintilla.SloppyBraceMatch) + self.setMatchedBraceBackgroundColor(QColor("#c6c6c6")) # Current line visible with special background color self.setCaretWidth(2) @@ -387,6 +391,11 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter): self.showNext() ## TODO: press event for auto-completion file directory else: + t = unicode(e.text()) + ## Close bracket automatically + if t in self.opening: + i = self.opening.index(t) + self.insert(self.closing[i]) QsciScintilla.keyPressEvent(self, e) def contextMenuEvent(self, e):