Skip to content
Snippets Groups Projects
Commit 010dd90b authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Spruce up the visual appeal of the editor.

Refs #20251
parent 9c15f7b1
No related branches found
No related tags found
No related merge requests found
......@@ -17,12 +17,9 @@
from __future__ import (absolute_import, unicode_literals)
# 3rd party imports
from qtpy.QtCore import QObject
from qtpy.QtWidgets import QStatusBar, QTabWidget, QVBoxLayout, QWidget
# local imports
from mantidqt.utils.qt import import_qtlib
from .execution import PythonCodeExecution
# Import single-file editor from C++ wrapping
CodeEditor = import_qtlib('_widgetscore', 'mantidqt.widgets', 'ScriptEditor')
......@@ -18,6 +18,7 @@ from __future__ import (absolute_import, unicode_literals)
# 3rd party imports
from qtpy.QtCore import QObject
from qtpy.QtGui import QColor, QFont, QFontMetrics
from qtpy.QtWidgets import QStatusBar, QVBoxLayout, QWidget
# local imports
......@@ -25,9 +26,11 @@ from mantidqt.widgets.codeeditor.editor import CodeEditor
from mantidqt.widgets.codeeditor.execution import PythonCodeExecution
IDLE_STATUS_MSG = "Status: Idle"
RUNNING_STATUS_MSG = "Status: Running"
# Editor colors
CURRENTLINE_BKGD = QColor(247, 236, 248)
class PythonFileInterpreter(QWidget):
......@@ -38,7 +41,7 @@ class PythonFileInterpreter(QWidget):
super(PythonFileInterpreter, self).__init__(parent)
# layout
self.editor = CodeEditor("Python", self)
self.editor = CodeEditor("AlternateCSPythonLexer", self)
self.status = QStatusBar(self)
layout = QVBoxLayout()
layout.addWidget(self.editor)
......@@ -46,6 +49,8 @@ class PythonFileInterpreter(QWidget):
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
self._setup_editor()
# presenter
self._presenter = PythonFileInterpreterPresenter(self, PythonCodeExecution())
......@@ -58,6 +63,22 @@ class PythonFileInterpreter(QWidget):
def set_status_message(self, msg):
self.status.showMessage(msg)
def _setup_editor(self):
editor = self.editor
# use fixed with font
font = QFont("Courier New")
font.setPointSize(10)
editor.setFont(font)
# show current editing line but in a softer color
editor.setCaretLineBackgroundColor(CURRENTLINE_BKGD)
editor.setCaretLineVisible(True)
# set a margin large enough for sensible file sizes < 1000 lines
# and the progress marker
font_metrics = QFontMetrics(font)
editor.setMarginWidth(1, font_metrics.averageCharWidth()*3 + 12)
class PythonFileInterpreterPresenter(QObject):
"""Presenter part of MVP to control actions on the editor"""
......
......@@ -68,7 +68,11 @@ public:
bool isReadOnly() const;
QString text() const;
void setCaretLineBackgroundColor (const QColor & col);
void setCaretLineVisible(bool enable);
void setFileName(const QString &filename);
void setFont(const QFont &f);
void setMarginWidth(int margin, int width);
void setReadOnly(bool ro);
void setText(const QString &text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment