Skip to content

Commit

Permalink
Move font, margin and caret code to baseclass
Browse files Browse the repository at this point in the history
  • Loading branch information
rduivenvoorde committed Aug 27, 2020
1 parent ab83e57 commit 354b959
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 47 deletions.
19 changes: 19 additions & 0 deletions python/console/console_base.py
Expand Up @@ -56,6 +56,25 @@ class QgsQsciScintillaBase(QsciScintilla):
def __init__(self, parent=None):
super(QgsQsciScintillaBase, self).__init__(parent)

# Enable non-ascii chars
self.setUtf8(True)

# Set the default font
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
self.setFont(font)
self.setMarginsFont(font)

# Margin 0 is used for line numbers (editor and output)
self.setMarginWidth(0, "00000")
# Margin 1 is used for the '>>>' prompt (console input)
self.setMarginWidth(1, "0")
self.setMarginType(1, 5) # TextMarginRightJustified=5
# Margin 2 is used for the 'folding' (editor)
self.setMarginWidth(2, "0")

self.setCaretLineVisible(True)
self.setCaretWidth(2)

self.iconRun = QgsApplication.getThemeIcon("console/mIconRunConsole.svg")
self.iconRunScript = QgsApplication.getThemeIcon("mActionStart.svg")
self.iconUndo = QgsApplication.getThemeIcon("mActionUndo.svg")
Expand Down
14 changes: 0 additions & 14 deletions python/console/console_editor.py
Expand Up @@ -92,20 +92,6 @@ def __init__(self, parent=None):

self.settings = QgsSettings()

# Enable non-ascii chars for editor
self.setUtf8(True)

# Set the default font
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
self.setFont(font)
self.setMarginsFont(font)
# Margin 0 is used for line numbers
fontmetrics = QFontMetrics(font)
self.setMarginWidth(0, fontmetrics.width("0000") + 5)
self.setMarginLineNumbers(0, True)
self.setCaretLineVisible(True)
self.setCaretWidth(2)

self.markerDefine(QgsApplication.getThemePixmap("console/iconSyntaxErrorConsole.svg"),
self.MARKER_NUM)

Expand Down
17 changes: 1 addition & 16 deletions python/console/console_output.py
Expand Up @@ -114,29 +114,14 @@ def __init__(self, parent=None):
self.infoBar.setSizePolicy(sizePolicy)
self.layout.addWidget(self.infoBar, 0, 0, 1, 1)

# Enable non-ascii chars for editor
self.setUtf8(True)

sys.stdout = writeOut(self, sys.stdout)
sys.stderr = writeOut(self, sys.stderr, "_traceback")

self.insertInitText()
self.refreshSettingsOutput()
self.setReadOnly(True)

# Set the default font
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
self.setFont(font)
self.setMarginsFont(font)
# Margin 0 is used for line numbers
self.setMarginWidth(0, 0)
self.setMarginWidth(1, 0)
self.setMarginWidth(2, 0)
self.setMarginsFont(font)
self.setMarginWidth(1, "00000")
self.setMarginLineNumbers(1, True)
self.setCaretLineVisible(True)
self.setCaretWidth(0)
self.setCaretWidth(0) # NO (blinking) caret in the output

self.setMinimumHeight(120)

Expand Down
18 changes: 1 addition & 17 deletions python/console/console_sci.py
Expand Up @@ -58,23 +58,10 @@ def __init__(self, parent=None):

self.settings = QgsSettings()

# Enable non-ascii chars for editor
self.setUtf8(True)

self.new_input_line = True

# Set the default font
font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
self.setFont(font)
self.setMarginsFont(font)
# Margin 0 is used for line numbers
self.setMarginWidth(0, 0)
self.setMarginWidth(1, 0)
self.setMarginWidth(2, 0)
self.setMarginsFont(font)
self.setMarginWidth(1, "00000")
self.setMarginType(1, 5)
self.setCaretLineVisible(False)
self.setMarginLineNumbers(0, False) # NO linenumbers for the input line

self.buffer = []

Expand All @@ -94,9 +81,6 @@ def __init__(self, parent=None):
# the current position
self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

# Current line visible with special background color
self.setCaretWidth(2)

self.refreshSettingsShell()

# Don't want to see the horizontal scrollbar at all
Expand Down

0 comments on commit 354b959

Please sign in to comment.