Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pyqgis-console] close bracket automatically
  • Loading branch information
slarosa committed May 10, 2013
1 parent 26a59b3 commit 839343b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 16 additions & 1 deletion python/console/console_editor.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion python/console/console_output.py
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions python/console/console_sci.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 839343b

Please sign in to comment.