Skip to content
Permalink
Browse files

[pyqgis-console] close bracket automatically

  • Loading branch information
slarosa committed May 10, 2013
1 parent 26a59b3 commit 839343b1e5a540e9e991717f5acf41dffa96eb05
Showing with 27 additions and 2 deletions.
  1. +16 −1 python/console/console_editor.py
  2. +2 −1 python/console/console_output.py
  3. +9 −0 python/console/console_sci.py
@@ -78,6 +78,9 @@ def __init__(self, parent=None):
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 @@ def __init__(self, parent=None):
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 @@ def __init__(self, parent=None):
#self.setWrapMode(QsciScintilla.WrapCharacter)
self.setWhitespaceVisibility(QsciScintilla.WsVisibleAfterIndent)
#self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

self.settingsEditor()

@@ -552,6 +559,14 @@ def goToLine(self, objName, linenr):
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 @@ def write(self, m):
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 @@ def __init__(self, parent=None):

self.parent = parent

self.opening = ['(', '{', '[', "'", '"']
self.closing = [')', '}', ']', "'", '"']

self.settings = QSettings()

# Enable non-ascii chars for editor
@@ -69,6 +72,7 @@ def __init__(self, parent=None):
# 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 @@ def keyPressEvent(self, e):
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):

0 comments on commit 839343b

Please sign in to comment.
You can’t perform that action at this time.