Skip to content

Commit

Permalink
[pyqgis-console] allow to disable automatic parentheses insertion fro…
Browse files Browse the repository at this point in the history
…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 942d6bf
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 102 deletions.
2 changes: 2 additions & 0 deletions python/console/console.py
Original file line number Diff line number Diff line change
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
18 changes: 10 additions & 8 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 @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 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 Down
34 changes: 16 additions & 18 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,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):
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
23 changes: 9 additions & 14 deletions python/console/console_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)):
Expand All @@ -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)
Expand Down
138 changes: 76 additions & 62 deletions python/console/console_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 942d6bf

Please sign in to comment.