Skip to content
Permalink
Browse files

Ensure colors in Python console match colors for Python editors

used elsewhere in the application
  • Loading branch information
nyalldawson committed Oct 3, 2020
1 parent 89ace9a commit ad946d45c8186147b5d17945417da77b109233d5
@@ -30,30 +30,6 @@
class QgsPythonConsoleBase(QgsCodeEditorPython):

MARKER_NUM = 6
DEFAULT_COLOR = "#4d4d4c"
KEYWORD_COLOR = "#8959a8"
CLASS_COLOR = "#4271ae"
METHOD_COLOR = "#4271ae"
DECORATION_COLOR = "#3e999f"
NUMBER_COLOR = "#c82829"
COMMENT_COLOR = "#8e908c"
COMMENT_BLOCK_COLOR = "#8e908c"
BACKGROUND_COLOR = "#ffffff"
CURSOR_COLOR = "#636363"
CARET_LINE_COLOR = "#efefef"
SINGLE_QUOTE_COLOR = "#718c00"
DOUBLE_QUOTE_COLOR = "#718c00"
TRIPLE_SINGLE_QUOTE_COLOR = "#eab700"
TRIPLE_DOUBLE_QUOTE_COLOR = "#eab700"
MARGIN_BACKGROUND_COLOR = "#efefef"
MARGIN_FOREGROUND_COLOR = "#636363"
SELECTION_BACKGROUND_COLOR = "#d7d7d7"
SELECTION_FOREGROUND_COLOR = "#303030"
MATCHED_BRACE_BACKGROUND_COLOR = "#b7f907"
MATCHED_BRACE_FOREGROUND_COLOR = "#303030"
EDGE_COLOR = "#efefef"
FOLD_COLOR = "#efefef"
ERROR_COLOR = "#e31a1c"

def __init__(self, parent=None):
super().__init__(parent)
@@ -113,19 +89,19 @@ def setLexers(self):
font.setPointSize(fontSize)

self.lexer.setDefaultFont(font)
self.lexer.setDefaultColor(QColor(self.settings.value("pythonConsole/defaultFontColor", QColor(self.DEFAULT_COLOR))))
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentFontColor", QColor(self.COMMENT_COLOR))), 1)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/numberFontColor", QColor(self.NUMBER_COLOR))), 2)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/keywordFontColor", QColor(self.KEYWORD_COLOR))), 5)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/classFontColor", QColor(self.CLASS_COLOR))), 8)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/methodFontColor", QColor(self.METHOD_COLOR))), 9)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/decorFontColor", QColor(self.DECORATION_COLOR))), 15)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/commentBlockFontColor", QColor(self.COMMENT_BLOCK_COLOR))), 12)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/singleQuoteFontColor", QColor(self.SINGLE_QUOTE_COLOR))), 4)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/doubleQuoteFontColor", QColor(self.DOUBLE_QUOTE_COLOR))), 3)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/tripleSingleQuoteFontColor", QColor(self.TRIPLE_SINGLE_QUOTE_COLOR))), 6)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/tripleDoubleQuoteFontColor", QColor(self.TRIPLE_DOUBLE_QUOTE_COLOR))), 7)
self.lexer.setColor(QColor(self.settings.value("pythonConsole/defaultFontColor", QColor(self.DEFAULT_COLOR))), 13)
self.lexer.setDefaultColor(self.color(QgsCodeEditor.ColorRole.Default))
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Comment), 1)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Number), 2)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Keyword), 5)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Class), 8)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Method), 9)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Decoration), 15)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.CommentBlock), 12)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.SingleQuote), 4)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.DoubleQuote), 3)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.TripleSingleQuote), 6)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.TripleDoubleQuote), 7)
self.lexer.setColor(self.color(QgsCodeEditor.ColorRole.Default), 13)
self.lexer.setColor(QColor(Qt.red), 14)
self.lexer.setFont(font, 1)
self.lexer.setFont(font, 2)
@@ -134,8 +110,8 @@ def setLexers(self):
self.lexer.setFont(font, QsciLexerPython.UnclosedString)

# ? only for editor and console ?
paperColor = self.color(QgsCodeEditor.ColorRole.Background)
for style in range(0, 33):
paperColor = QColor(self.settings.value("pythonConsole/paperBackgroundColor", QColor(self.BACKGROUND_COLOR)))
self.lexer.setPaper(paperColor, style)

self.api = QsciAPIs(self.lexer)
@@ -24,7 +24,7 @@
from qgis.PyQt.QtWidgets import QShortcut, QMenu, QApplication, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
from qgis.PyQt.Qsci import QsciScintilla, QsciAPIs, QsciStyle
from qgis.core import Qgis, QgsApplication, QgsSettings, QgsBlockingNetworkRequest
from qgis.gui import QgsMessageBar
from qgis.gui import QgsMessageBar, QgsCodeEditor
from qgis.utils import OverrideCursor
from .console_base import QgsPythonConsoleBase
import sys
@@ -167,16 +167,16 @@ def __init__(self, parent=None):
self.modificationAttempted.connect(self.fileReadOnly)

def settingsEditor(self):
self.setSelectionForegroundColor(QColor(self.settings.value("pythonConsole/selectionForegroundColor", QColor(self.SELECTION_FOREGROUND_COLOR))))
self.setSelectionBackgroundColor(QColor(self.settings.value("pythonConsole/selectionBackgroundColor", QColor(self.SELECTION_BACKGROUND_COLOR))))
self.setMatchedBraceBackgroundColor(QColor(self.settings.value("pythonConsole/matchedBraceBackgroundColor", QColor(self.MATCHED_BRACE_BACKGROUND_COLOR))))
self.setMatchedBraceForegroundColor(QColor(self.settings.value("pythonConsole/matchedBraceForegroundColor", QColor(self.MATCHED_BRACE_FOREGROUND_COLOR))))
self.setMarginsForegroundColor(QColor(self.settings.value("pythonConsole/marginForegroundColor", QColor(self.MARGIN_FOREGROUND_COLOR))))
self.setMarginsBackgroundColor(QColor(self.settings.value("pythonConsole/marginBackgroundColor", QColor(self.MARGIN_BACKGROUND_COLOR))))
self.setIndentationGuidesForegroundColor(QColor(self.settings.value("pythonConsole/marginForegroundColor", QColor(self.MARGIN_FOREGROUND_COLOR))))
self.setIndentationGuidesBackgroundColor(QColor(self.settings.value("pythonConsole/marginBackgroundColor", QColor(self.MARGIN_BACKGROUND_COLOR))))
self.setEdgeColor(QColor(self.settings.value("pythonConsole/edgeColor", QColor(self.EDGE_COLOR))))
foldColor = QColor(self.settings.value("pythonConsole/foldColor", QColor(self.FOLD_COLOR)))
self.setSelectionForegroundColor(self.color(QgsCodeEditor.ColorRole.SelectionForeground))
self.setSelectionBackgroundColor(self.color(QgsCodeEditor.ColorRole.SelectionBackground))
self.setMatchedBraceBackgroundColor(self.color(QgsCodeEditor.ColorRole.MatchedBraceBackground))
self.setMatchedBraceForegroundColor(self.color(QgsCodeEditor.ColorRole.MatchedBraceForeground))
self.setMarginsForegroundColor(self.color(QgsCodeEditor.ColorRole.MarginForeground))
self.setMarginsBackgroundColor(self.color(QgsCodeEditor.ColorRole.MarginBackground))
self.setIndentationGuidesForegroundColor(self.color(QgsCodeEditor.ColorRole.MarginForeground))
self.setIndentationGuidesBackgroundColor(self.color(QgsCodeEditor.ColorRole.MarginBackground))
self.setEdgeColor(self.color(QgsCodeEditor.ColorRole.Edge))
foldColor = self.color(QgsCodeEditor.ColorRole.Fold)
self.setFoldMarginColors(foldColor, foldColor)

# Set Python lexer
@@ -195,10 +195,8 @@ def settingsEditor(self):
else:
self.setAutoCompletionSource(self.AcsNone)

caretLineColor = self.settings.value("pythonConsole/caretLineColor", QColor(self.CARET_LINE_COLOR))
cursorColor = self.settings.value("pythonConsole/cursorColor", QColor(self.CURSOR_COLOR))
self.setCaretLineBackgroundColor(caretLineColor)
self.setCaretForegroundColor(cursorColor)
self.setCaretLineBackgroundColor(self.color(QgsCodeEditor.ColorRole.CaretLine))
self.setCaretForegroundColor(self.color(QgsCodeEditor.ColorRole.Cursor))

def autoCompleteKeyBinding(self):
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource", 'fromAPI')
@@ -24,7 +24,7 @@
from qgis.PyQt.QtWidgets import QGridLayout, QSpacerItem, QSizePolicy, QShortcut, QMenu, QApplication
from qgis.PyQt.Qsci import QsciScintilla
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.gui import QgsMessageBar
from qgis.gui import QgsMessageBar, QgsCodeEditor
from .console_base import QgsPythonConsoleBase
import sys

@@ -156,18 +156,13 @@ def insertInitText(self):
def refreshSettingsOutput(self):
# Set Python lexer
self.setLexers()
self.setSelectionForegroundColor(QColor(
self.settings.value("pythonConsole/selectionForegroundColor", QColor(self.SELECTION_FOREGROUND_COLOR))))
self.setSelectionBackgroundColor(QColor(
self.settings.value("pythonConsole/selectionBackgroundColor", QColor(self.SELECTION_BACKGROUND_COLOR))))
self.setMarginsForegroundColor(
QColor(self.settings.value("pythonConsole/marginForegroundColor", QColor(self.MARGIN_FOREGROUND_COLOR))))
self.setMarginsBackgroundColor(
QColor(self.settings.value("pythonConsole/marginBackgroundColor", QColor(self.MARGIN_BACKGROUND_COLOR))))
caretLineColor = self.settings.value("pythonConsole/caretLineColor", QColor(self.CARET_LINE_COLOR))
cursorColor = self.settings.value("pythonConsole/cursorColor", QColor(self.CURSOR_COLOR))
self.setCaretLineBackgroundColor(caretLineColor)
self.setCaretForegroundColor(cursorColor)
self.setSelectionForegroundColor(self.color(QgsCodeEditor.ColorRole.SelectionForeground))
self.setSelectionBackgroundColor(self.color(QgsCodeEditor.ColorRole.SelectionBackground))
self.setMarginsForegroundColor(self.color(QgsCodeEditor.ColorRole.MarginForeground))
self.setMarginsBackgroundColor(self.color(QgsCodeEditor.ColorRole.MarginBackground))

self.setCaretLineBackgroundColor(self.color(QgsCodeEditor.ColorRole.CaretLine))
self.setCaretForegroundColor(self.color(QgsCodeEditor.ColorRole.Cursor))

def clearConsole(self):
self.setText('')
@@ -24,6 +24,7 @@
from qgis.PyQt.QtGui import QColor, QKeySequence, QFont, QFontMetrics, QStandardItemModel, QStandardItem, QClipboard, \
QFontDatabase
from qgis.PyQt.Qsci import QsciScintilla
from qgis.gui import QgsCodeEditor

import sys
import os
@@ -135,17 +136,14 @@ def refreshSettingsShell(self):
else:
self.setAutoCompletionSource(self.AcsNone)

cursorColor = self.settings.value("pythonConsole/cursorColor", QColor(self.CURSOR_COLOR))
self.setCaretForegroundColor(cursorColor)
self.setSelectionForegroundColor(QColor(
self.settings.value("pythonConsole/selectionForegroundColor", QColor(self.SELECTION_FOREGROUND_COLOR))))
self.setSelectionBackgroundColor(QColor(
self.settings.value("pythonConsole/selectionBackgroundColor", QColor(self.SELECTION_BACKGROUND_COLOR))))
self.setMatchedBraceBackgroundColor(QColor(self.settings.value("pythonConsole/matchedBraceBackgroundColor",
QColor(self.MATCHED_BRACE_BACKGROUND_COLOR))))
self.setMatchedBraceForegroundColor(QColor(self.settings.value("pythonConsole/matchedBraceForegroundColor",
QColor(self.MATCHED_BRACE_FOREGROUND_COLOR))))
self.setMarginsBackgroundColor(QColor(self.settings.value("pythonConsole/paperBackgroundColor", QColor(self.BACKGROUND_COLOR))))
self.setCaretLineBackgroundColor(self.color(QgsCodeEditor.ColorRole.CaretLine))
self.setCaretForegroundColor(self.color(QgsCodeEditor.ColorRole.Cursor))

self.setSelectionForegroundColor(self.color(QgsCodeEditor.ColorRole.SelectionForeground))
self.setSelectionBackgroundColor(self.color(QgsCodeEditor.ColorRole.SelectionBackground))
self.setMatchedBraceBackgroundColor(self.color(QgsCodeEditor.ColorRole.MatchedBraceBackground))
self.setMatchedBraceForegroundColor(self.color(QgsCodeEditor.ColorRole.MatchedBraceForeground))
self.setMarginsBackgroundColor(self.color(QgsCodeEditor.ColorRole.Background))

# Sets minimum height for input area based of font metric
self._setMinimumHeight()

0 comments on commit ad946d4

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