mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-06 14:02:25 +12:00
Adds better style colors of references
This commit is contained in:
parent
a334e8bd1b
commit
31dcc6d53a
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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!
|
||||
|
||||
|
|
Loading…
Reference in a new issue