From 31dcc6d53a7d02445534de6af96ce4ec40c319fa Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Tue, 14 Nov 2017 15:22:16 +0100 Subject: [PATCH] Adds better style colors of references --- manuskript/models/references.py | 14 ++++++++++++-- manuskript/ui/editors/basicHighlighter.py | 18 +++++++++--------- manuskript/ui/importers/importer_ui.py | 2 +- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/manuskript/models/references.py b/manuskript/models/references.py index 0223b76..66660f7 100644 --- a/manuskript/models/references.py +++ b/manuskript/models/references.py @@ -9,12 +9,16 @@ import re # A regex used to match references from PyQt5.QtWidgets import qApp +from PyQt5.QtGui import QColor +from PyQt5.QtCore import Qt from manuskript.enums import Outline from manuskript.enums import Character from manuskript.enums import Plot from manuskript.enums import PlotStep -from manuskript.functions import mainWindow +from manuskript.functions import mainWindow, mixColors +from manuskript.ui import style as S + RegEx = r"{(\w):(\d+):?.*?}" # A non-capturing regex used to identify references @@ -27,6 +31,12 @@ TextLetter = "T" PlotLetter = "P" WorldLetter = "W" +# Colors +TextHighlightColor = QColor(mixColors(QColor(Qt.blue).name(), S.window, .3)) +CharacterHighlightColor = QColor(mixColors(QColor(Qt.yellow).name(), S.window, .3)) +PlotHighlightColor = QColor(mixColors(QColor(Qt.red).name(), S.window, .3)) +WorldHighlightColor = QColor(mixColors(QColor(Qt.green).name(), S.window, .3)) + def plotReference(ID, searchable=False): """Takes the ID of a plot and returns a reference for that plot. @@ -69,7 +79,7 @@ def worldReference(ID, searchable=False): ############################################################################### def infos(ref): - """Returns a full paragraph in HTML format + """Returns a full paragraph in HTML format containing detailed infos about the reference ``ref``. """ match = re.fullmatch(RegEx, ref) diff --git a/manuskript/ui/editors/basicHighlighter.py b/manuskript/ui/editors/basicHighlighter.py index 1b69033..a09b53a 100644 --- a/manuskript/ui/editors/basicHighlighter.py +++ b/manuskript/ui/editors/basicHighlighter.py @@ -37,7 +37,7 @@ class basicHighlighter(QSyntaxHighlighter): def highlightBlockBefore(self, text): """Highlighting to do before anything else. - + When subclassing basicHighlighter, you must call highlightBlockBefore before you do any custom highlighting. """ @@ -55,7 +55,7 @@ class basicHighlighter(QSyntaxHighlighter): def highlightBlockAfter(self, text): """Highlighting to do after everything else. - + When subclassing basicHighlighter, you must call highlightBlockAfter after your custom highlighting. """ @@ -65,22 +65,22 @@ class basicHighlighter(QSyntaxHighlighter): fmt = self.format(txt.start()) fmt.setFontFixedPitch(True) fmt.setFontWeight(QFont.DemiBold) - fmt.setForeground(Qt.black) # or text becomes unreadable in some color scheme + if txt.group(1) == Ref.TextLetter: - fmt.setBackground(QBrush(QColor(Qt.blue).lighter(190))) + fmt.setBackground(QBrush(Ref.TextHighlightColor)) elif txt.group(1) == Ref.CharacterLetter: - fmt.setBackground(QBrush(QColor(Qt.yellow).lighter(170))) + fmt.setBackground(QBrush(Ref.CharacterHighlightColor)) elif txt.group(1) == Ref.PlotLetter: - fmt.setBackground(QBrush(QColor(Qt.red).lighter(170))) + fmt.setBackground(QBrush(Ref.PlotHighlightColor)) elif txt.group(1) == Ref.WorldLetter: - fmt.setBackground(QBrush(QColor(Qt.green).lighter(170))) + fmt.setBackground(QBrush(Ref.WorldHighlightColor)) self.setFormat(txt.start(), txt.end() - txt.start(), fmt) # Spell checking - + # Following algorithm would not check words at the end of line. # This hacks adds a space to every line where the text cursor is not # So that it doesn't spellcheck while typing, but still spellchecks at @@ -89,7 +89,7 @@ class basicHighlighter(QSyntaxHighlighter): if self.currentBlock().position() + len(text) != \ self.editor.textCursor().position(): textedText = text + " " - + # Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/ WORDS = '(?iu)([\w\']+)[^\'\w]' # (?iu) means case insensitive and unicode if hasattr(self.editor, "spellcheck") and self.editor.spellcheck: diff --git a/manuskript/ui/importers/importer_ui.py b/manuskript/ui/importers/importer_ui.py index 327914c..d23c8e4 100644 --- a/manuskript/ui/importers/importer_ui.py +++ b/manuskript/ui/importers/importer_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'manuskript/ui/importers/importer_ui.ui' # -# Created by: PyQt5 UI code generator 5.5.1 +# Created by: PyQt5 UI code generator 5.9 # # WARNING! All changes made in this file will be lost!