Adds better style colors of references

This commit is contained in:
Olivier Keshavjee 2017-11-14 15:22:16 +01:00
parent a334e8bd1b
commit 31dcc6d53a
3 changed files with 22 additions and 12 deletions

View file

@ -9,12 +9,16 @@ import re
# A regex used to match references # A regex used to match references
from PyQt5.QtWidgets import qApp from PyQt5.QtWidgets import qApp
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt
from manuskript.enums import Outline from manuskript.enums import Outline
from manuskript.enums import Character from manuskript.enums import Character
from manuskript.enums import Plot from manuskript.enums import Plot
from manuskript.enums import PlotStep 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+):?.*?}" RegEx = r"{(\w):(\d+):?.*?}"
# A non-capturing regex used to identify references # A non-capturing regex used to identify references
@ -27,6 +31,12 @@ TextLetter = "T"
PlotLetter = "P" PlotLetter = "P"
WorldLetter = "W" 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): def plotReference(ID, searchable=False):
"""Takes the ID of a plot and returns a reference for that plot. """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): def infos(ref):
"""Returns a full paragraph in HTML format """Returns a full paragraph in HTML format
containing detailed infos about the reference ``ref``. containing detailed infos about the reference ``ref``.
""" """
match = re.fullmatch(RegEx, ref) match = re.fullmatch(RegEx, ref)

View file

@ -37,7 +37,7 @@ class basicHighlighter(QSyntaxHighlighter):
def highlightBlockBefore(self, text): def highlightBlockBefore(self, text):
"""Highlighting to do before anything else. """Highlighting to do before anything else.
When subclassing basicHighlighter, you must call highlightBlockBefore When subclassing basicHighlighter, you must call highlightBlockBefore
before you do any custom highlighting. before you do any custom highlighting.
""" """
@ -55,7 +55,7 @@ class basicHighlighter(QSyntaxHighlighter):
def highlightBlockAfter(self, text): def highlightBlockAfter(self, text):
"""Highlighting to do after everything else. """Highlighting to do after everything else.
When subclassing basicHighlighter, you must call highlightBlockAfter When subclassing basicHighlighter, you must call highlightBlockAfter
after your custom highlighting. after your custom highlighting.
""" """
@ -65,22 +65,22 @@ class basicHighlighter(QSyntaxHighlighter):
fmt = self.format(txt.start()) fmt = self.format(txt.start())
fmt.setFontFixedPitch(True) fmt.setFontFixedPitch(True)
fmt.setFontWeight(QFont.DemiBold) fmt.setFontWeight(QFont.DemiBold)
fmt.setForeground(Qt.black) # or text becomes unreadable in some color scheme
if txt.group(1) == Ref.TextLetter: 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: 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: 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: elif txt.group(1) == Ref.WorldLetter:
fmt.setBackground(QBrush(QColor(Qt.green).lighter(170))) fmt.setBackground(QBrush(Ref.WorldHighlightColor))
self.setFormat(txt.start(), self.setFormat(txt.start(),
txt.end() - txt.start(), txt.end() - txt.start(),
fmt) fmt)
# Spell checking # Spell checking
# Following algorithm would not check words at the end of line. # 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 # 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 # 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) != \ if self.currentBlock().position() + len(text) != \
self.editor.textCursor().position(): self.editor.textCursor().position():
textedText = text + " " textedText = text + " "
# Based on http://john.nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/ # 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 WORDS = '(?iu)([\w\']+)[^\'\w]' # (?iu) means case insensitive and unicode
if hasattr(self.editor, "spellcheck") and self.editor.spellcheck: if hasattr(self.editor, "spellcheck") and self.editor.spellcheck:

View file

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'manuskript/ui/importers/importer_ui.ui' # 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! # WARNING! All changes made in this file will be lost!