mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[pyqgis-console] close bracket automatically
This commit is contained in:
parent
26a59b332f
commit
839343b1e5
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user