Add new logic for dialogue narrator break
This commit is contained in:
@@ -59,7 +59,8 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
"_tHandle", "_isNovel", "_isInactive", "_spellCheck", "_spellErr",
|
"_tHandle", "_isNovel", "_isInactive", "_spellCheck", "_spellErr",
|
||||||
"_hStyles", "_minRules", "_txtRules", "_cmnRules",
|
"_hStyles", "_minRules", "_txtRules", "_cmnRules", "_dialogLine",
|
||||||
|
"_narratorBreak",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, document: QTextDocument) -> None:
|
def __init__(self, document: QTextDocument) -> None:
|
||||||
@@ -78,6 +79,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self._txtRules: list[tuple[re.Pattern, dict[int, QTextCharFormat]]] = []
|
self._txtRules: list[tuple[re.Pattern, dict[int, QTextCharFormat]]] = []
|
||||||
self._cmnRules: list[tuple[re.Pattern, dict[int, QTextCharFormat]]] = []
|
self._cmnRules: list[tuple[re.Pattern, dict[int, QTextCharFormat]]] = []
|
||||||
|
|
||||||
|
self._dialogLine = ""
|
||||||
|
self._narratorBreak = ""
|
||||||
|
|
||||||
self.initHighlighter()
|
self.initHighlighter()
|
||||||
|
|
||||||
logger.debug("Ready: GuiDocHighlighter")
|
logger.debug("Ready: GuiDocHighlighter")
|
||||||
@@ -132,6 +136,9 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self._txtRules.clear()
|
self._txtRules.clear()
|
||||||
self._cmnRules.clear()
|
self._cmnRules.clear()
|
||||||
|
|
||||||
|
self._dialogLine = CONFIG.dialogLine
|
||||||
|
self._narratorBreak = CONFIG.narratorBreak
|
||||||
|
|
||||||
# Multiple or Trailing Spaces
|
# Multiple or Trailing Spaces
|
||||||
if CONFIG.showMultiSpaces:
|
if CONFIG.showMultiSpaces:
|
||||||
rxRule = re.compile(r"[ ]{2,}|[ ]*$", re.UNICODE)
|
rxRule = re.compile(r"[ ]{2,}|[ ]*$", re.UNICODE)
|
||||||
@@ -159,20 +166,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
}
|
}
|
||||||
self._txtRules.append((rxRule, hlRule))
|
self._txtRules.append((rxRule, hlRule))
|
||||||
|
|
||||||
if CONFIG.dialogLine:
|
|
||||||
rxRule = REGEX_PATTERNS.dialogLine
|
|
||||||
hlRule = {
|
|
||||||
0: self._hStyles["dialog"],
|
|
||||||
}
|
|
||||||
self._txtRules.append((rxRule, hlRule))
|
|
||||||
|
|
||||||
if CONFIG.narratorBreak:
|
|
||||||
rxRule = REGEX_PATTERNS.narratorBreak
|
|
||||||
hlRule = {
|
|
||||||
0: self._hStyles["text"],
|
|
||||||
}
|
|
||||||
self._txtRules.append((rxRule, hlRule))
|
|
||||||
|
|
||||||
if CONFIG.altDialogOpen and CONFIG.altDialogClose:
|
if CONFIG.altDialogOpen and CONFIG.altDialogClose:
|
||||||
rxRule = REGEX_PATTERNS.altDialogStyle
|
rxRule = REGEX_PATTERNS.altDialogStyle
|
||||||
hlRule = {
|
hlRule = {
|
||||||
@@ -411,6 +404,17 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self.setCurrentBlockState(BLOCK_TEXT)
|
self.setCurrentBlockState(BLOCK_TEXT)
|
||||||
hRules = self._txtRules if self._isNovel else self._minRules
|
hRules = self._txtRules if self._isNovel else self._minRules
|
||||||
|
|
||||||
|
if self._dialogLine and text.startswith(self._dialogLine):
|
||||||
|
if self._narratorBreak:
|
||||||
|
tPos = 0
|
||||||
|
for tNum, tBit in enumerate(text[1:].split(self._narratorBreak), 1):
|
||||||
|
tLen = len(tBit) + 1
|
||||||
|
if tNum%2:
|
||||||
|
self.setFormat(tPos, tLen, self._hStyles["dialog"])
|
||||||
|
tPos += tLen
|
||||||
|
else:
|
||||||
|
self.setFormat(0, len(text), self._hStyles["dialog"])
|
||||||
|
|
||||||
if hRules:
|
if hRules:
|
||||||
for rX, hRule in hRules:
|
for rX, hRule in hRules:
|
||||||
for res in re.finditer(rX, text[xOff:]):
|
for res in re.finditer(rX, text[xOff:]):
|
||||||
|
|||||||
Reference in New Issue
Block a user