Skip to content
Permalink
Browse files

[pyqgis-console] allows to set font color in python lexer

  • Loading branch information
slarosa committed Sep 14, 2013
1 parent 236c239 commit d8b8089e383781b58c50ecbe3c2a1384d6a70719
@@ -96,6 +96,7 @@
<file>themes/default/console/iconSearchNextEditorConsole.png</file>
<file>themes/default/console/iconSearchPrevEditorConsole.png</file>
<file>themes/default/console/iconSyntaxErrorConsole.png</file>
<file>themes/default/console/iconResetColorConsole.png</file>
<file>themes/default/copyright_label.png</file>
<file>themes/default/extents.png</file>
<file>themes/default/favourites.png</file>
Binary file not shown.
@@ -229,9 +229,12 @@ def setLexers(self):
font.setBold(False)

self.lexer.setDefaultFont(font)
self.lexer.setColor(Qt.red, 1)
self.lexer.setColor(Qt.darkGreen, 5)
self.lexer.setColor(Qt.darkBlue, 15)
self.lexer.setDefaultColor(QColor(self.settings.value("pythonConsole/defaultFontColorEditor", QColor(Qt.black))))
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentFontColorEditor", QColor(Qt.gray))), 1)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/keywordFontColorEditor", QColor(Qt.darkGreen))), 5)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/methodFontColorEditor", QColor(Qt.darkGray))), 9)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/decorFontColorEditor", QColor(Qt.darkBlue))), 15)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentBlockFontColorEditor", QColor(Qt.gray))), 12)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 3)
self.lexer.setFont(font, 4)
@@ -41,10 +41,14 @@ def __init__(self, shellOut, out=None, style=None):
def write(self, m):
if self.style == "_traceback":
# Show errors in red
stderrColor = QColor(self.sO.settings.value("pythonConsole/stderrFontColor", QColor(Qt.red)))
self.sO.SendScintilla(QsciScintilla.SCI_STYLESETFORE, 001, stderrColor)
self.sO.SendScintilla(QsciScintilla.SCI_STYLESETITALIC, 001, True)
self.sO.SendScintilla(QsciScintilla.SCI_STYLESETBOLD, 001, True)
pos = self.sO.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
self.sO.SendScintilla(QsciScintilla.SCI_STARTSTYLING, pos, 31)
self.sO.append(m)
self.sO.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 1)
self.sO.SendScintilla(QsciScintilla.SCI_SETSTYLING, len(m), 001)
else:
self.sO.append(m)

@@ -162,9 +166,13 @@ def setLexers(self):
font.setBold(False)

self.lexer.setDefaultFont(font)
self.lexer.setColor(Qt.red, 1)
self.lexer.setColor(Qt.darkGreen, 5)
self.lexer.setColor(Qt.darkBlue, 15)
self.lexer.setDefaultColor(QColor(self.settings.value("pythonConsole/defaultFontColor", QColor(Qt.black))))
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentFontColor", QColor(Qt.gray))), 1)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/keywordFontColor", QColor(Qt.darkGreen))), 5)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/methodFontColor", QColor(Qt.darkGray))), 9)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/decorFontColor", QColor(Qt.darkBlue))), 15)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentBlockFontColor", QColor(Qt.gray))), 12)
self.lexer.setColor(QColor(Qt.red), 14)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 2)
self.lexer.setFont(font, 3)
@@ -181,9 +181,12 @@ def setLexers(self):
font.setBold(False)

self.lexer.setDefaultFont(font)
self.lexer.setColor(Qt.red, 1)
self.lexer.setColor(Qt.darkGreen, 5)
self.lexer.setColor(Qt.darkBlue, 15)
self.lexer.setDefaultColor(QColor(self.settings.value("pythonConsole/defaultFontColor", QColor(Qt.black))))
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentFontColor", QColor(Qt.gray))), 1)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/keywordFontColor", QColor(Qt.darkGreen))), 5)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/methodFontColor", QColor(Qt.darkGray))), 9)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/decorFontColor", QColor(Qt.darkBlue))), 15)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentBlockFontColor", QColor(Qt.gray))), 12)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 3)
self.lexer.setFont(font, 4)
@@ -51,6 +51,11 @@ def __init__(self, parent):
SIGNAL("clicked()"), self.removeAPI)
self.compileAPIs.clicked.connect(self._prepareAPI)

self.resetFontColor.setIcon(QIcon(":/images/themes/default/console/iconResetColorConsole.png"))
self.resetFontColorEditor.setIcon(QIcon(":/images/themes/default/console/iconResetColorConsole.png"))
self.resetFontColor.clicked.connect(self._resetFontColor)
self.resetFontColorEditor.clicked.connect(self._resetFontColorEditor)

def initialCheck(self):
if self.preloadAPI.isChecked():
self.enableDisable(False)
@@ -176,6 +181,21 @@ def saveSettings(self):
settings.setValue("pythonConsole/autoCloseBracket", self.autoCloseBracket.isChecked())
settings.setValue("pythonConsole/autoCloseBracketEditor", self.autoCloseBracketEditor.isChecked())

settings.setValue("pythonConsole/defaultFontColor", self.defaultFontColor.color())
settings.setValue("pythonConsole/keywordFontColor", self.keywordFontColor.color())
settings.setValue("pythonConsole/decorFontColor", self.decorFontColor.color())
settings.setValue("pythonConsole/methodFontColor", self.methodFontColor.color())
settings.setValue("pythonConsole/commentFontColor", self.commentFontColor.color())
settings.setValue("pythonConsole/commentBlockFontColor", self.commentBlockFontColor.color())
settings.setValue("pythonConsole/stderrFontColor", self.stderrFontColor.color())

settings.setValue("pythonConsole/defaultFontColorEditor", self.defaultFontColorEditor.color())
settings.setValue("pythonConsole/keywordFontColorEditor", self.keywordFontColorEditor.color())
settings.setValue("pythonConsole/decorFontColorEditor", self.decorFontColorEditor.color())
settings.setValue("pythonConsole/methodFontColorEditor", self.methodFontColorEditor.color())
settings.setValue("pythonConsole/commentFontColorEditor", self.commentFontColorEditor.color())
settings.setValue("pythonConsole/commentBlockFontColorEditor", self.commentBlockFontColorEditor.color())

def restoreSettings(self):
settings = QSettings()
self.spinBox.setValue(settings.value("pythonConsole/fontsize", 10, type=int))
@@ -218,5 +238,47 @@ def restoreSettings(self):
elif settings.value("pythonConsole/autoCompleteSourceEditor") == 'fromDocAPI':
self.autoCompFromDocAPIEditor.setChecked(True)

## Setting font lexer color
self.defaultFontColor.setColor(QColor(settings.value("pythonConsole/defaultFontColor", QColor(Qt.black))))
self.keywordFontColor.setColor(QColor(settings.value("pythonConsole/keywordFontColor", QColor(Qt.darkGreen))))
self.methodFontColor.setColor(QColor(settings.value("pythonConsole/methodFontColor", QColor(Qt.darkGray))))
self.decorFontColor.setColor(QColor(settings.value("pythonConsole/decorFontColor", QColor(Qt.darkBlue))))
self.commentFontColor.setColor(QColor(settings.value("pythonConsole/commentFontColor", QColor(Qt.gray))))
self.commentBlockFontColor.setColor(QColor(settings.value("pythonConsole/commentBlockFontColor", QColor(Qt.gray))))
self.defaultFontColorEditor.setColor(QColor(settings.value("pythonConsole/defaultFontColorEditor", QColor(Qt.black))))
self.keywordFontColorEditor.setColor(QColor(settings.value("pythonConsole/keywordFontColorEditor", QColor(Qt.darkGreen))))
self.methodFontColorEditor.setColor(QColor(settings.value("pythonConsole/methodFontColorEditor", QColor(Qt.darkGray))))
self.decorFontColorEditor.setColor(QColor(settings.value("pythonConsole/decorFontColorEditor", QColor(Qt.darkBlue))))
self.commentFontColorEditor.setColor(QColor(settings.value("pythonConsole/commentFontColorEditor", QColor(Qt.gray))))
self.commentBlockFontColorEditor.setColor(QColor(settings.value("pythonConsole/commentBlockFontColorEditor", QColor(Qt.gray))))
self.stderrFontColor.setColor(QColor(settings.value("pythonConsole/stderrFontColor", QColor(Qt.red))))

self.defaultFontColor.setButtonBackground()
self.defaultFontColorEditor.setButtonBackground()

def _resetFontColor(self):
self.defaultFontColor.setColor(QColor(Qt.black))
self.keywordFontColor.setColor(QColor(Qt.darkGreen))
self.methodFontColor.setColor(QColor(Qt.darkGray))
self.decorFontColor.setColor(QColor(Qt.darkBlue))
self.commentFontColor.setColor(QColor(Qt.gray))
self.commentBlockFontColor.setColor(QColor(Qt.gray))
self.stderrFontColor.setColor(QColor(Qt.red))

def _resetFontColorEditor(self):
self.defaultFontColorEditor.setColor(QColor(Qt.black))
self.keywordFontColorEditor.setColor(QColor(Qt.darkGreen))
self.methodFontColorEditor.setColor(QColor(Qt.darkGray))
self.decorFontColorEditor.setColor(QColor(Qt.darkBlue))
self.commentFontColorEditor.setColor(QColor(Qt.gray))
self.commentBlockFontColorEditor.setColor(QColor(Qt.gray))

# def _setButtonBack(self, w):
# from qgis.gui import QgsColorButton
# objs = [w.itemAt(i) for i in range(w.count())]
# for obj in objs:
# if isinstance(obj, QgsColorButton):
# return obj.setButtonBackground()

def reject(self):
QDialog.reject(self)

0 comments on commit d8b8089

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