Skip to content
Permalink
Browse files

[pyqgis-console] allow to disable automatic parentheses insertion fro…

…m settings:

- fix: add Shift+Insert to paste action
- fix: set default Monospaced font at the first start
- allow to save state for console splitter
- fix for mousePressEvent into console
  • Loading branch information
slarosa committed May 19, 2013
1 parent 4109a10 commit 942d6bfa5d5e9cc7471efcd34717613fa6a8b7db
@@ -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())

@@ -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())

@@ -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)
@@ -613,11 +613,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):
@@ -1145,11 +1146,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()
@@ -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)
@@ -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)
@@ -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()

@@ -391,11 +392,12 @@ 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):
@@ -494,10 +496,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()
@@ -516,18 +514,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)
@@ -36,7 +36,6 @@ def __init__(self, parent):
self.restoreSettings()
self.initialCheck()
self.autoCompletionOptions()
self.fontConfig()

self.addAPIpath.setIcon(QIcon(":/images/themes/default/symbologyAdd.png"))
self.addAPIpath.setToolTip(QCoreApplication.translate("PythonConsole", "Add API path"))
@@ -124,25 +123,13 @@ def removeAPI(self):
for index in reversed(listItemSel):
self.tableWidget.removeRow(index.row())

def fontConfig(self):
#fontFamily = ['Courier','Monospace','Aurulent Sans','Bitstream Vera Serif']
#for i in range(0, len(fontFamily)):
#self.comboBox.addItem(fontFamily[i])
settings = QSettings()
self.fontComboBox.setCurrentIndex(settings.value("pythonConsole/fontfamilyindex").toInt()[0])
self.fontComboBoxEditor.setCurrentIndex(settings.value("pythonConsole/fontfamilyindexEditor").toInt()[0])

def saveSettings(self):
settings = QSettings()
settings.setValue("pythonConsole/preloadAPI", QVariant(self.preloadAPI.isChecked()))
settings.setValue("pythonConsole/autoSaveScript", QVariant(self.autoSaveScript.isChecked()))
fontFamilyIndex = self.fontComboBox.currentIndex()
settings.setValue("pythonConsole/fontfamilyindex", QVariant(fontFamilyIndex))

fontFamilyText = self.fontComboBox.currentText()
settings.setValue("pythonConsole/fontfamilytext", QVariant(fontFamilyText))

fontFamilyIndexEditor = self.fontComboBoxEditor.currentIndex()
settings.setValue("pythonConsole/fontfamilyindexEditor", QVariant(fontFamilyIndexEditor))
fontFamilyTextEditor = self.fontComboBoxEditor.currentText()
settings.setValue("pythonConsole/fontfamilytextEditor", QVariant(fontFamilyTextEditor))

@@ -176,11 +163,17 @@ def saveSettings(self):
settings.setValue("pythonConsole/autoCompleteEnabledEditor", QVariant(self.autoCompleteEnabledEditor.isChecked()))
settings.setValue("pythonConsole/autoCompleteEnabled", QVariant(self.autoCompleteEnabled.isChecked()))
settings.setValue("pythonConsole/enableObjectInsp", QVariant(self.enableObjectInspector.isChecked()))
settings.setValue("pythonConsole/autoCloseBracket", QVariant(self.autoCloseBracket.isChecked()))
settings.setValue("pythonConsole/autoCloseBracketEditor", QVariant(self.autoCloseBracketEditor.isChecked()))

def restoreSettings(self):
settings = QSettings()
self.spinBox.setValue(settings.value("pythonConsole/fontsize", 10).toInt()[0])
self.spinBoxEditor.setValue(settings.value("pythonConsole/fontsizeEditor", 10).toInt()[0])
self.fontComboBox.setCurrentFont(QFont(settings.value("pythonConsole/fontfamilytext",
"Monospace").toString()))
self.fontComboBoxEditor.setCurrentFont(QFont(settings.value("pythonConsole/fontfamilytextEditor",
"Monospace").toString()))
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True).toBool())
itemTable = settings.value("pythonConsole/userAPI").toStringList()
for i in range(len(itemTable)):
@@ -198,6 +191,8 @@ def restoreSettings(self):
self.autoCompleteEnabledEditor.setChecked(settings.value("pythonConsole/autoCompleteEnabledEditor", True).toBool())
self.autoCompleteEnabled.setChecked(settings.value("pythonConsole/autoCompleteEnabled", True).toBool())
self.enableObjectInspector.setChecked(settings.value("pythonConsole/enableObjectInsp", False).toBool())
self.autoCloseBracketEditor.setChecked(settings.value("pythonConsole/autoCloseBracketEditor", True).toBool())
self.autoCloseBracket.setChecked(settings.value("pythonConsole/autoCloseBracket", True).toBool())

if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
self.autoCompFromDoc.setChecked(True)
@@ -59,11 +59,11 @@
<x>0</x>
<y>0</y>
<width>543</width>
<height>622</height>
<height>674</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Editor</string>
@@ -132,7 +132,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QgsCollapsibleGroupBox" name="groupBoxAutoCompletionEditor">
<property name="title">
<string>Autocompletion</string>
@@ -239,6 +239,13 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="autoCloseBracketEditor">
<property name="text">
<string>Automatic parentheses insertion</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -248,69 +255,13 @@
<string>Console</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QFontComboBox" name="fontComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="minimumSize">
<size>
<width>51</width>
<height>26</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>51</width>
<height>26</height>
</size>
</property>
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>15</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QgsCollapsibleGroupBox" name="groupBoxAutoCompletion">
<property name="title">
<string>Autocompletion</string>
</property>
<property name="collapsed" stdset="0">
<bool>true</bool>
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
@@ -401,10 +352,73 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QFontComboBox" name="fontComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="minimumSize">
<size>
<width>51</width>
<height>26</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>51</width>
<height>26</height>
</size>
</property>
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>15</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="autoCloseBracket">
<property name="text">
<string>Automatic parentheses insertion</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>APIs</string>

0 comments on commit 942d6bf

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