Showing with 186 additions and 133 deletions.
  1. +5 −3 python/console/console.py
  2. +55 −26 python/console/console_editor.py
  3. +19 −8 python/console/console_output.py
  4. +22 −20 python/console/console_sci.py
  5. +9 −14 python/console/console_settings.py
  6. +76 −62 python/console/console_settings.ui
8 changes: 5 additions & 3 deletions python/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def __init__(self, parent=None):
self.runScriptEditorButton.setToolTip(runScriptEditorBt)
self.runScriptEditorButton.setText(runScriptEditorBt)
## Action Run Script (subprocess)
commentEditorBt = QCoreApplication.translate("PythonConsole", "Comment code")
commentEditorBt = QCoreApplication.translate("PythonConsole", "Comment")
self.commentEditorButton = QAction(self)
self.commentEditorButton.setCheckable(False)
self.commentEditorButton.setEnabled(True)
Expand All @@ -231,7 +231,7 @@ def __init__(self, parent=None):
self.commentEditorButton.setToolTip(commentEditorBt)
self.commentEditorButton.setText(commentEditorBt)
## Action Run Script (subprocess)
uncommentEditorBt = QCoreApplication.translate("PythonConsole", "Uncomment code")
uncommentEditorBt = QCoreApplication.translate("PythonConsole", "Uncomment")
self.uncommentEditorButton = QAction(self)
self.uncommentEditorButton.setCheckable(False)
self.uncommentEditorButton.setEnabled(True)
Expand All @@ -252,7 +252,7 @@ def __init__(self, parent=None):
self.objectListButton.setToolTip(objList)
self.objectListButton.setText(objList)
## Action for Find text
findText = QCoreApplication.translate("PythonConsole", "Find text")
findText = QCoreApplication.translate("PythonConsole", "Find Text")
self.findTextButton = QAction(self)
self.findTextButton.setCheckable(True)
self.findTextButton.setEnabled(True)
Expand Down Expand Up @@ -704,6 +704,7 @@ def updateTabListScript(self, script, action=None):
QVariant(self.tabListScript))

def saveSettingsConsole(self):
self.settings.setValue("pythonConsole/splitterConsole", self.splitter.saveState())
self.settings.setValue("pythonConsole/splitterObj", self.splitterObj.saveState())
self.settings.setValue("pythonConsole/splitterEditor", self.splitterEditor.saveState())

Expand All @@ -712,6 +713,7 @@ def saveSettingsConsole(self):
def restoreSettingsConsole(self):
storedTabScripts = self.settings.value("pythonConsole/tabScripts")
self.tabListScript = storedTabScripts.toList()
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole").toByteArray())
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor").toByteArray())
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj").toByteArray())

Expand Down
81 changes: 55 additions & 26 deletions python/console/console_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self, parent=None):
#self.setMinimumWidth(300)

self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
self.setMatchedBraceBackgroundColor(QColor("#c6c6c6"))
self.setMatchedBraceBackgroundColor(QColor("#b7f907"))

# Folding
self.setFolding(QsciScintilla.PlainFoldStyle)
Expand Down Expand Up @@ -271,53 +271,76 @@ def contextMenuEvent(self, e):
iconSettings = QgsApplication.getThemeIcon("console/iconSettingsConsole.png")
iconFind = QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png")
iconSyntaxCk = QgsApplication.getThemeIcon("console/iconSyntaxErrorConsole.png")
hideEditorAction = menu.addAction("Hide Editor",
self.hideEditor)
iconObjInsp = QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png")
hideEditorAction = menu.addAction(QCoreApplication.translate("PythonConsole", "Hide Editor"),
self.hideEditor)
menu.addSeparator()
syntaxCheck = menu.addAction(iconSyntaxCk, "Check Syntax",
syntaxCheck = menu.addAction(iconSyntaxCk,
QCoreApplication.translate("PythonConsole",
"Check Syntax"),
self.syntaxCheck, 'Ctrl+4')
menu.addSeparator()
runSelected = menu.addAction(iconRun,
"Enter selected",
QCoreApplication.translate("PythonConsole",
"Enter selected"),
self.runSelectedCode, 'Ctrl+E')
runScript = menu.addAction(iconRunScript,
"Run Script",
QCoreApplication.translate("PythonConsole",
"Run Script"),
self.runScriptCode, 'Shift+Ctrl+E')
menu.addSeparator()
undoAction = menu.addAction("Undo", self.undo, QKeySequence.Undo)
redoAction = menu.addAction("Redo", self.redo, 'Ctrl+Shift+Z')
undoAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Undo"),
self.undo, QKeySequence.Undo)
redoAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Redo"),
self.redo, 'Ctrl+Shift+Z')
menu.addSeparator()
findAction = menu.addAction(iconFind,
"Find Text",
QCoreApplication.translate("PythonConsole",
"Find Text"),
self.showFindWidget)
menu.addSeparator()
cutAction = menu.addAction("Cut",
cutAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Cut"),
self.cut,
QKeySequence.Cut)
copyAction = menu.addAction("Copy",
copyAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Copy"),
self.copy,
QKeySequence.Copy)
pasteAction = menu.addAction("Paste", self.paste, QKeySequence.Paste)
pasteAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Paste"),
self.paste, QKeySequence.Paste)
menu.addSeparator()
commentCodeAction = menu.addAction(iconCommentEditor, "Comment",
commentCodeAction = menu.addAction(iconCommentEditor,
QCoreApplication.translate("PythonConsole",
"Comment"),
self.parent.pc.commentCode, 'Ctrl+3')
uncommentCodeAction = menu.addAction(iconUncommentEditor, "Uncomment",
uncommentCodeAction = menu.addAction(iconUncommentEditor,
QCoreApplication.translate("PythonConsole",
"Uncomment"),
self.parent.pc.uncommentCode,
'Shift+Ctrl+3')
menu.addSeparator()
codePadAction = menu.addAction(iconCodePad,
"Share on codepad",
self.codepad)
QCoreApplication.translate("PythonConsole",
"Share on codepad"),
self.codepad)
menu.addSeparator()
showCodeInspection = menu.addAction("Hide/Show Object list",
showCodeInspection = menu.addAction(iconObjInsp,
QCoreApplication.translate("PythonConsole",
"Hide/Show Object Inspector"),
self.objectListEditor)
menu.addSeparator()
selectAllAction = menu.addAction("Select All",
selectAllAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Select All"),
self.selectAll,
QKeySequence.SelectAll)
menu.addSeparator()
settingsDialog = menu.addAction(iconSettings,
"Settings",
QCoreApplication.translate("PythonConsole",
"Settings"),
self.parent.pc.openSettings)
syntaxCheck.setEnabled(False)
pasteAction.setEnabled(False)
Expand All @@ -328,6 +351,7 @@ def contextMenuEvent(self, e):
selectAllAction.setEnabled(False)
undoAction.setEnabled(False)
redoAction.setEnabled(False)
showCodeInspection.setEnabled(False)
if self.hasSelectedText():
runSelected.setEnabled(True)
copyAction.setEnabled(True)
Expand All @@ -342,6 +366,9 @@ def contextMenuEvent(self, e):
redoAction.setEnabled(True)
if QApplication.clipboard().text():
pasteAction.setEnabled(True)
if self.settings.value("pythonConsole/enableObjectInsp",
False).toBool():
showCodeInspection.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))

def findText(self, forward):
Expand Down Expand Up @@ -613,11 +640,12 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):
return True

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])
if self.settings.value("pythonConsole/autoCloseBracketEditor", True).toBool():
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):
Expand Down Expand Up @@ -1145,11 +1173,12 @@ def refreshSettingsEditor(self):
objInspectorEnabled = self.settings.value("pythonConsole/enableObjectInsp",
False).toBool()
listObj = self.parent.objectListButton
listObj.setChecked(objInspectorEnabled)
if self.parent.listClassMethod.isVisible():
listObj.setChecked(objInspectorEnabled)
listObj.setEnabled(objInspectorEnabled)
if objInspectorEnabled:
cW = self.currentWidget()
if cW:
if cW and not self.parent.listClassMethod.isVisible():
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
self.listObject(cW)
QApplication.restoreOverrideCursor()
Expand Down
27 changes: 19 additions & 8 deletions python/console/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def setLexers(self):
font = QFont(loadFont)
font.setFixedPitch(True)
font.setPointSize(fontSize)
font.setStyleHint(QFont.TypeWriter)
font.setStretch(QFont.SemiCondensed)
font.setLetterSpacing(QFont.PercentageSpacing, 87.0)
font.setBold(False)

self.lexer.setDefaultFont(font)
self.lexer.setColor(Qt.red, 1)
Expand All @@ -172,30 +176,37 @@ def contextMenuEvent(self, e):
iconHideTool = QgsApplication.getThemeIcon("console/iconHideToolConsole.png")
iconSettings = QgsApplication.getThemeIcon("console/iconSettingsConsole.png")
hideToolBar = menu.addAction(iconHideTool,
"Hide/Show Toolbar",
QCoreApplication.translate("PythonConsole",
"Hide/Show Toolbar"),
self.hideToolBar)
menu.addSeparator()
showEditorAction = menu.addAction("Show Editor",
self.showEditor)
showEditorAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Show Editor"),
self.showEditor)
menu.addSeparator()
runAction = menu.addAction(iconRun,
"Enter Selected",
QCoreApplication.translate("PythonConsole",
"Enter Selected"),
self.enteredSelected,
QKeySequence(Qt.CTRL + Qt.Key_E))
clearAction = menu.addAction(iconClear,
"Clear console",
QCoreApplication.translate("PythonConsole",
"Clear console"),
self.clearConsole)
menu.addSeparator()
copyAction = menu.addAction("Copy",
copyAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Copy"),
self.copy,
QKeySequence.Copy)
menu.addSeparator()
selectAllAction = menu.addAction("Select All",
selectAllAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Select All"),
self.selectAll,
QKeySequence.SelectAll)
menu.addSeparator()
settingsDialog = menu.addAction(iconSettings,
"Settings",
QCoreApplication.translate("PythonConsole",
"Settings"),
self.parent.openSettings)
runAction.setEnabled(False)
clearAction.setEnabled(False)
Expand Down
42 changes: 22 additions & 20 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +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"))
self.setMatchedBraceBackgroundColor(QColor("#b7f907"))

# Current line visible with special background color
self.setCaretWidth(2)
Expand Down Expand Up @@ -380,8 +380,9 @@ def keyPressEvent(self, e):
self.setCursorPosition(line, 4)
self.recolor()

elif e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and \
e.key() == Qt.Key_V:
elif (e.modifiers() & (Qt.ControlModifier | Qt.MetaModifier) and \
e.key() == Qt.Key_V) or \
(e.modifiers() & Qt.ShiftModifier and e.key() == Qt.Key_Insert):
self.paste()
e.accept()

Expand All @@ -391,17 +392,22 @@ 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])
if self.settings.value("pythonConsole/autoCloseBracket", True).toBool():
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):
menu = QMenu(self)
copyAction = menu.addAction("Copy", self.copy, QKeySequence.Copy)
pasteAction = menu.addAction("Paste", self.paste, QKeySequence.Paste)
copyAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Copy"),
self.copy, QKeySequence.Copy)
pasteAction = menu.addAction(QCoreApplication.translate("PythonConsole",
"Paste"),
self.paste, QKeySequence.Paste)
copyAction.setEnabled(False)
pasteAction.setEnabled(False)
if self.hasSelectedText():
Expand Down Expand Up @@ -494,10 +500,6 @@ def runCommand(self, cmd):
self.writeCMD(cmd)
import webbrowser
self.updateHistory(cmd)
line, pos = self.getCursorPosition()
selCmdLenght = self.text(line).length()
self.setSelection(line, 0, line, selCmdLenght)
self.removeSelectedText()
if cmd in ('_save', '_clear', '_clearAll', '_pyqgis', '_api'):
if cmd == '_save':
self.writeHistoryFile()
Expand All @@ -516,18 +518,18 @@ def runCommand(self, cmd):
if msgText:
self.parent.callWidgetMessageBar(msgText)

self.displayPrompt(False)
more = False
else:
self.buffer.append(cmd)
src = u"\n".join(self.buffer)
more = self.runsource(src, "<input>")
if not more:
self.buffer = []
## prevents to commands with more lines to break the console
## in the case they have a eol different from '\n'
self.setText('')
self.move_cursor_to_end()
self.displayPrompt(more)
## prevents to commands with more lines to break the console
## in the case they have a eol different from '\n'
self.setText('')
self.move_cursor_to_end()
self.displayPrompt(more)

def write(self, txt):
sys.stderr.write(txt)
Expand Down
Loading