Improve dialogue highlighting (#1864)
This commit is contained in:
@@ -168,9 +168,8 @@ A syntax theme ``.conf`` file consists of the following settings:
|
||||
headertext = 0, 0, 0
|
||||
headertag = 0, 0, 0
|
||||
emphasis = 0, 0, 0
|
||||
straightquotes = 0, 0, 0
|
||||
doublequotes = 0, 0, 0
|
||||
singlequotes = 0, 0, 0
|
||||
dialog = 0, 0, 0
|
||||
altdialog = 0, 0, 0
|
||||
note = 0, 0, 0
|
||||
hidden = 0, 0, 0
|
||||
shortcode = 0, 0, 0
|
||||
@@ -201,4 +200,5 @@ Omitted syntax colours default to black, except ``background`` which defaults to
|
||||
The ``texthighlight`` syntax colour entry was added.
|
||||
|
||||
.. versionadded:: 2.5
|
||||
The ``note`` and ``tag`` syntax colour entries were added.
|
||||
The ``dialog``, ``altdialog``, ``note`` and ``tag`` syntax colour entries were added.
|
||||
``straightquotes``, ``doublequotes`` and ``singlequotes`` were removed.
|
||||
|
||||
@@ -12,9 +12,8 @@ link = 77, 077, 255
|
||||
headertext = 255, 255, 255
|
||||
headertag = 50, 0, 180
|
||||
emphasis = 0, 255, 255
|
||||
straightquotes = 7, 27, 219
|
||||
doublequotes = 0, 255, 0
|
||||
singlequotes = 0, 140, 255
|
||||
dialog = 0, 255, 0
|
||||
altdialog = 0, 140, 255
|
||||
note = 150, 150, 150
|
||||
hidden = 77, 77, 100
|
||||
shortcode = 255, 255, 0
|
||||
|
||||
@@ -26,9 +26,8 @@ link = 102, 153, 204
|
||||
headertext = 153, 204, 153
|
||||
headertag = 153, 204, 153, 160
|
||||
emphasis = 249, 145, 87
|
||||
straightquotes = 230, 66, 80
|
||||
doublequotes = 102, 153, 204
|
||||
singlequotes = 102, 153, 204
|
||||
dialog = 102, 153, 204
|
||||
altdialog = 102, 153, 204
|
||||
note = 255, 255, 216
|
||||
hidden = 150, 150, 150
|
||||
shortcode = 153, 204, 153
|
||||
|
||||
@@ -26,9 +26,8 @@ link = 0, 0, 200
|
||||
headertext = 0, 100, 0
|
||||
headertag = 0, 100, 0, 160
|
||||
emphasis = 174, 110, 30
|
||||
straightquotes = 200, 50, 50
|
||||
doublequotes = 0, 0, 200
|
||||
singlequotes = 0, 0, 200
|
||||
dialog = 0, 0, 200
|
||||
altdialog = 0, 0, 200
|
||||
note = 100, 100, 0
|
||||
hidden = 100, 100, 100
|
||||
shortcode = 0, 100, 0
|
||||
|
||||
@@ -28,9 +28,8 @@ link = 255, 121, 198
|
||||
headertext = 189, 147, 249
|
||||
headertag = 189, 147, 249, 160
|
||||
emphasis = 255, 184, 108
|
||||
straightquotes = 255, 85, 85
|
||||
doublequotes = 80, 250, 123
|
||||
singlequotes = 241, 250, 140
|
||||
dialog = 80, 250, 123
|
||||
altdialog = 241, 250, 140
|
||||
note = 255, 204, 233
|
||||
hidden = 98, 114, 164
|
||||
shortcode = 139, 233, 253
|
||||
|
||||
@@ -13,9 +13,8 @@ link = 200, 200, 200
|
||||
headertext = 225, 225, 225
|
||||
headertag = 225, 225, 225, 160
|
||||
emphasis = 200, 200, 200
|
||||
straightquotes = 200, 200, 200
|
||||
doublequotes = 200, 200, 200
|
||||
singlequotes = 200, 200, 200
|
||||
dialog = 200, 200, 200
|
||||
altdialog = 200, 200, 200
|
||||
note = 200, 200, 200
|
||||
hidden = 150, 150, 150
|
||||
shortcode = 225, 225, 225
|
||||
|
||||
@@ -13,9 +13,8 @@ link = 20, 20, 20
|
||||
headertext = 0, 0, 0
|
||||
headertag = 0, 0, 0, 160
|
||||
emphasis = 20, 20, 20
|
||||
straightquotes = 20, 20, 20
|
||||
doublequotes = 20, 20, 20
|
||||
singlequotes = 20, 20, 20
|
||||
dialog = 20, 20, 20
|
||||
altdialog = 20, 20, 20
|
||||
note = 20, 20, 20
|
||||
hidden = 100, 100, 100
|
||||
shortcode = 0, 0, 0
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 40, 142, 215
|
||||
headertext = 40, 142, 215
|
||||
headertag = 40, 142, 215, 160
|
||||
emphasis = 224, 175, 5
|
||||
straightquotes = 222, 61, 58
|
||||
doublequotes = 8, 145, 106
|
||||
singlequotes = 218, 170, 1
|
||||
dialog = 8, 145, 106
|
||||
altdialog = 218, 170, 1
|
||||
note = 128, 118, 75
|
||||
hidden = 152, 159, 177
|
||||
shortcode = 40, 142, 215
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 130, 170, 255
|
||||
headertext = 130, 170, 255
|
||||
headertag = 130, 170, 255, 160
|
||||
emphasis = 236, 196, 141
|
||||
straightquotes = 247, 140, 108
|
||||
doublequotes = 173, 219, 103
|
||||
singlequotes = 255, 235, 149
|
||||
dialog = 173, 219, 103
|
||||
altdialog = 255, 235, 149
|
||||
note = 255, 249, 202
|
||||
hidden = 99, 119, 119
|
||||
shortcode = 130, 170, 255
|
||||
|
||||
@@ -26,9 +26,8 @@ link = 9, 161, 237
|
||||
headertext = 45, 174, 88
|
||||
headertag = 45, 174, 88, 160
|
||||
emphasis = 19, 187, 183
|
||||
straightquotes = 255, 92, 87
|
||||
doublequotes = 207, 156, 0
|
||||
singlequotes = 207, 156, 0
|
||||
dialog = 207, 156, 0
|
||||
altdialog = 207, 156, 0
|
||||
note = 120, 187, 185
|
||||
hidden = 145, 148, 162
|
||||
shortcode = 247, 103, 187
|
||||
|
||||
@@ -13,9 +13,8 @@ link = 38, 139, 210
|
||||
headertext = 147, 161, 161
|
||||
headertag = 42, 161, 152
|
||||
emphasis = 38, 139, 210
|
||||
straightquotes = 211, 54, 130
|
||||
doublequotes = 42, 161, 152
|
||||
singlequotes = 42, 161, 152
|
||||
dialog = 42, 161, 152
|
||||
altdialog = 42, 161, 152
|
||||
note = 101, 161, 156
|
||||
hidden = 147, 161, 161
|
||||
shortcode = 147, 161, 161
|
||||
|
||||
@@ -13,9 +13,8 @@ link = 38, 139, 210
|
||||
headertext = 88, 110, 117
|
||||
headertag = 42, 161, 152
|
||||
emphasis = 38, 139, 210
|
||||
straightquotes = 211, 54, 130
|
||||
doublequotes = 42, 161, 152
|
||||
singlequotes = 42, 161, 152
|
||||
dialog = 42, 161, 152
|
||||
altdialog = 42, 161, 152
|
||||
note = 27, 102, 96
|
||||
hidden = 88, 110, 117
|
||||
shortcode = 88, 110, 117
|
||||
|
||||
@@ -23,9 +23,8 @@ link = 114, 159, 207
|
||||
headertext = 114, 159, 207
|
||||
headertag = 114, 159, 207, 160
|
||||
emphasis = 196, 160, 0
|
||||
straightquotes = 239, 41, 41
|
||||
doublequotes = 138, 226, 52
|
||||
singlequotes = 252, 233, 79
|
||||
dialog = 138, 226, 52
|
||||
altdialog = 252, 233, 79
|
||||
note = 252, 242, 164
|
||||
hidden = 143, 143, 141
|
||||
shortcode = 114, 159, 207
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 66, 113, 174
|
||||
headertext = 66, 113, 174
|
||||
headertag = 66, 113, 174, 160
|
||||
emphasis = 245, 135, 31
|
||||
straightquotes = 240, 40, 41
|
||||
doublequotes = 113, 140, 0
|
||||
singlequotes = 234, 183, 0
|
||||
dialog = 113, 140, 0
|
||||
altdialog = 234, 183, 0
|
||||
note = 115, 90, 0
|
||||
hidden = 142, 144, 140
|
||||
shortcode = 66, 113, 174
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 197, 200, 198, 160
|
||||
headertext = 129, 162, 190
|
||||
headertag = 94, 119, 139
|
||||
emphasis = 222, 147, 95
|
||||
straightquotes = 204, 102, 102
|
||||
doublequotes = 181, 189, 104
|
||||
singlequotes = 240, 198, 116
|
||||
dialog = 181, 189, 104
|
||||
altdialog = 240, 198, 116
|
||||
note = 240, 219, 178
|
||||
hidden = 150, 152, 150
|
||||
shortcode = 129, 162, 190
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 187, 218, 255
|
||||
headertext = 187, 218, 255
|
||||
headertag = 187, 218, 255, 160
|
||||
emphasis = 255, 197, 143
|
||||
straightquotes = 255, 157, 164
|
||||
doublequotes = 209, 241, 169
|
||||
singlequotes = 255, 238, 173
|
||||
dialog = 209, 241, 169
|
||||
altdialog = 255, 238, 173
|
||||
note = 255, 247, 214
|
||||
hidden = 114, 133, 183
|
||||
shortcode = 187, 218, 255
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 122, 166, 218
|
||||
headertext = 122, 166, 218
|
||||
headertag = 122, 166, 218, 160
|
||||
emphasis = 231, 140, 69
|
||||
straightquotes = 213, 78, 83
|
||||
doublequotes = 185, 202, 74
|
||||
singlequotes = 231, 197, 71
|
||||
dialog = 185, 202, 74
|
||||
altdialog = 231, 197, 71
|
||||
note = 231, 214, 150
|
||||
hidden = 150, 152, 150
|
||||
shortcode = 122, 166, 218
|
||||
|
||||
@@ -33,9 +33,8 @@ link = 102, 153, 204
|
||||
headertext = 102, 153, 204
|
||||
headertag = 102, 153, 204, 160
|
||||
emphasis = 249, 145, 57
|
||||
straightquotes = 242, 119, 122
|
||||
doublequotes = 153, 204, 153
|
||||
singlequotes = 255, 204, 102
|
||||
dialog = 153, 204, 153
|
||||
altdialog = 255, 204, 102
|
||||
note = 255, 230, 179
|
||||
hidden = 153, 153, 153
|
||||
shortcode = 102, 153, 204
|
||||
|
||||
+18
-9
@@ -158,9 +158,12 @@ class Config:
|
||||
self.autoScrollPos = 30 # Start point for typewriter-like scrolling
|
||||
self.scrollPastEnd = True # Scroll past end of document, and centre cursor
|
||||
|
||||
self.highlightQuotes = True # Highlight text in quotes
|
||||
self.allowOpenSQuote = False # Allow open-ended single quotes
|
||||
self.allowOpenDQuote = True # Allow open-ended double quotes
|
||||
self.dialogStyle = 2 # Quote type to use for dialogue
|
||||
self.allowOpenDial = True # Allow open-ended dialogue quotes
|
||||
self.narratorBreak = "" # Symbol to use for narrator break
|
||||
self.dialogLine = "" # Symbol to use for dialogue line
|
||||
self.altDialogOpen = "" # Alternative dialog symbol, open
|
||||
self.altDialogClose = "" # Alternative dialog symbol, close
|
||||
self.highlightEmph = True # Add colour to text emphasis
|
||||
|
||||
self.stopWhenIdle = True # Stop the status bar clock when the user is idle
|
||||
@@ -618,9 +621,12 @@ class Config:
|
||||
self.showMultiSpaces = conf.rdBool(sec, "showmultispaces", self.showMultiSpaces)
|
||||
self.incNotesWCount = conf.rdBool(sec, "incnoteswcount", self.incNotesWCount)
|
||||
self.showFullPath = conf.rdBool(sec, "showfullpath", self.showFullPath)
|
||||
self.highlightQuotes = conf.rdBool(sec, "highlightquotes", self.highlightQuotes)
|
||||
self.allowOpenSQuote = conf.rdBool(sec, "allowopensquote", self.allowOpenSQuote)
|
||||
self.allowOpenDQuote = conf.rdBool(sec, "allowopendquote", self.allowOpenDQuote)
|
||||
self.dialogStyle = conf.rdInt(sec, "dialogstyle", self.dialogStyle)
|
||||
self.allowOpenDial = conf.rdBool(sec, "allowopendial", self.allowOpenDial)
|
||||
self.narratorBreak = conf.rdStr(sec, "narratorbreak", self.narratorBreak)
|
||||
self.altDialogOpen = conf.rdStr(sec, "altdialogopen", self.altDialogOpen)
|
||||
self.altDialogClose = conf.rdStr(sec, "altdialogclose", self.altDialogClose)
|
||||
self.dialogLine = conf.rdStr(sec, "dialogline", self.dialogLine)
|
||||
self.highlightEmph = conf.rdBool(sec, "highlightemph", self.highlightEmph)
|
||||
self.stopWhenIdle = conf.rdBool(sec, "stopwhenidle", self.stopWhenIdle)
|
||||
self.userIdleTime = conf.rdInt(sec, "useridletime", self.userIdleTime)
|
||||
@@ -726,9 +732,12 @@ class Config:
|
||||
"showmultispaces": str(self.showMultiSpaces),
|
||||
"incnoteswcount": str(self.incNotesWCount),
|
||||
"showfullpath": str(self.showFullPath),
|
||||
"highlightquotes": str(self.highlightQuotes),
|
||||
"allowopensquote": str(self.allowOpenSQuote),
|
||||
"allowopendquote": str(self.allowOpenDQuote),
|
||||
"dialogstyle": str(self.dialogStyle),
|
||||
"allowopendial": str(self.allowOpenDial),
|
||||
"narratorbreak": str(self.narratorBreak),
|
||||
"altdialogopen": str(self.altDialogOpen),
|
||||
"altdialogclose": str(self.altDialogClose),
|
||||
"dialogline": str(self.dialogLine),
|
||||
"highlightemph": str(self.highlightEmph),
|
||||
"stopwhenidle": str(self.stopWhenIdle),
|
||||
"useridletime": str(self.userIdleTime),
|
||||
|
||||
@@ -133,6 +133,7 @@ class GuiPreferences(QDialog):
|
||||
"""Build the settings form."""
|
||||
section = 0
|
||||
iSz = SHARED.theme.baseIconSize
|
||||
boxFixed = 5*SHARED.theme.textNWidth
|
||||
minWidth = CONFIG.pxInt(200)
|
||||
|
||||
# Label
|
||||
@@ -538,26 +539,59 @@ class GuiPreferences(QDialog):
|
||||
self.sidebar.addButton(title, section)
|
||||
self.mainForm.addGroupLabel(title, section)
|
||||
|
||||
self.highlightQuotes = NSwitch(self)
|
||||
self.highlightQuotes.setChecked(CONFIG.highlightQuotes)
|
||||
self.highlightQuotes.toggled.connect(self._toggleHighlightQuotes)
|
||||
self.dialogStyle = NComboBox(self)
|
||||
self.dialogStyle.addItem(self.tr("None"), 0)
|
||||
self.dialogStyle.addItem(self.tr("Single Quotes"), 1)
|
||||
self.dialogStyle.addItem(self.tr("Double Quotes"), 2)
|
||||
self.dialogStyle.addItem(self.tr("Both"), 3)
|
||||
self.dialogStyle.setCurrentData(CONFIG.dialogStyle, 2)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Highlight text wrapped in quotes"), self.highlightQuotes,
|
||||
self.tr("Applies to the document editor only.")
|
||||
self.tr("Highlight dialogue"), self.dialogStyle,
|
||||
self.tr("Applies to the selected quote styles.")
|
||||
)
|
||||
|
||||
self.allowOpenSQuote = NSwitch(self)
|
||||
self.allowOpenSQuote.setChecked(CONFIG.allowOpenSQuote)
|
||||
self.allowOpenDial = NSwitch(self)
|
||||
self.allowOpenDial.setChecked(CONFIG.allowOpenDial)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Allow open-ended single quotes"), self.allowOpenSQuote,
|
||||
self.tr("Highlight single-quoted line with no closing quote.")
|
||||
self.tr("Allow open-ended sialogue"), self.allowOpenDial,
|
||||
self.tr("Highlight dialogue line with no closing quote.")
|
||||
)
|
||||
|
||||
self.allowOpenDQuote = NSwitch(self)
|
||||
self.allowOpenDQuote.setChecked(CONFIG.allowOpenDQuote)
|
||||
self.narratorBreak = QLineEdit(self)
|
||||
self.narratorBreak.setMaxLength(1)
|
||||
self.narratorBreak.setFixedWidth(boxFixed)
|
||||
self.narratorBreak.setAlignment(QtAlignCenter)
|
||||
self.narratorBreak.setText(CONFIG.narratorBreak)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Allow open-ended double quotes"), self.allowOpenDQuote,
|
||||
self.tr("Highlight double-quoted line with no closing quote.")
|
||||
self.tr("Dialogue narrator break symbol"), self.narratorBreak,
|
||||
self.tr("Symbol to indicate injected narrator break.")
|
||||
)
|
||||
|
||||
self.dialogLine = QLineEdit(self)
|
||||
self.dialogLine.setMaxLength(1)
|
||||
self.dialogLine.setFixedWidth(boxFixed)
|
||||
self.dialogLine.setAlignment(QtAlignCenter)
|
||||
self.dialogLine.setText(CONFIG.dialogLine)
|
||||
self.mainForm.addRow(
|
||||
self.tr("Dialogue line symbol"), self.dialogLine,
|
||||
self.tr("Lines starting with this symbol are dialogue.")
|
||||
)
|
||||
|
||||
self.altDialogOpen = QLineEdit(self)
|
||||
self.altDialogOpen.setMaxLength(4)
|
||||
self.altDialogOpen.setFixedWidth(boxFixed)
|
||||
self.altDialogOpen.setAlignment(QtAlignCenter)
|
||||
self.altDialogOpen.setText(CONFIG.altDialogOpen)
|
||||
|
||||
self.altDialogClose = QLineEdit(self)
|
||||
self.altDialogClose.setMaxLength(4)
|
||||
self.altDialogClose.setFixedWidth(boxFixed)
|
||||
self.altDialogClose.setAlignment(QtAlignCenter)
|
||||
self.altDialogClose.setText(CONFIG.altDialogClose)
|
||||
|
||||
self.mainForm.addRow(
|
||||
self.tr("Alternative dialog symbols"), [self.altDialogOpen, self.altDialogClose],
|
||||
self.tr("Custom highlighting of dialog text.")
|
||||
)
|
||||
|
||||
self.highlightEmph = NSwitch(self)
|
||||
@@ -667,13 +701,12 @@ class GuiPreferences(QDialog):
|
||||
self.mainForm.addGroupLabel(title, section)
|
||||
|
||||
self.quoteSym = {}
|
||||
qWidth = CONFIG.pxInt(40)
|
||||
|
||||
# Single Quote Style
|
||||
self.quoteSym["SO"] = QLineEdit(self)
|
||||
self.quoteSym["SO"].setMaxLength(1)
|
||||
self.quoteSym["SO"].setReadOnly(True)
|
||||
self.quoteSym["SO"].setFixedWidth(qWidth)
|
||||
self.quoteSym["SO"].setFixedWidth(boxFixed)
|
||||
self.quoteSym["SO"].setAlignment(QtAlignCenter)
|
||||
self.quoteSym["SO"].setText(CONFIG.fmtSQuoteOpen)
|
||||
self.btnSingleStyleO = NIconToolButton(self, iSz, "more")
|
||||
@@ -687,7 +720,7 @@ class GuiPreferences(QDialog):
|
||||
self.quoteSym["SC"] = QLineEdit(self)
|
||||
self.quoteSym["SC"].setMaxLength(1)
|
||||
self.quoteSym["SC"].setReadOnly(True)
|
||||
self.quoteSym["SC"].setFixedWidth(qWidth)
|
||||
self.quoteSym["SC"].setFixedWidth(boxFixed)
|
||||
self.quoteSym["SC"].setAlignment(QtAlignCenter)
|
||||
self.quoteSym["SC"].setText(CONFIG.fmtSQuoteClose)
|
||||
self.btnSingleStyleC = NIconToolButton(self, iSz, "more")
|
||||
@@ -702,7 +735,7 @@ class GuiPreferences(QDialog):
|
||||
self.quoteSym["DO"] = QLineEdit(self)
|
||||
self.quoteSym["DO"].setMaxLength(1)
|
||||
self.quoteSym["DO"].setReadOnly(True)
|
||||
self.quoteSym["DO"].setFixedWidth(qWidth)
|
||||
self.quoteSym["DO"].setFixedWidth(boxFixed)
|
||||
self.quoteSym["DO"].setAlignment(QtAlignCenter)
|
||||
self.quoteSym["DO"].setText(CONFIG.fmtDQuoteOpen)
|
||||
self.btnDoubleStyleO = NIconToolButton(self, iSz, "more")
|
||||
@@ -716,7 +749,7 @@ class GuiPreferences(QDialog):
|
||||
self.quoteSym["DC"] = QLineEdit(self)
|
||||
self.quoteSym["DC"].setMaxLength(1)
|
||||
self.quoteSym["DC"].setReadOnly(True)
|
||||
self.quoteSym["DC"].setFixedWidth(qWidth)
|
||||
self.quoteSym["DC"].setFixedWidth(boxFixed)
|
||||
self.quoteSym["DC"].setAlignment(QtAlignCenter)
|
||||
self.quoteSym["DC"].setText(CONFIG.fmtDQuoteClose)
|
||||
self.btnDoubleStyleC = NIconToolButton(self, iSz, "more")
|
||||
@@ -823,13 +856,6 @@ class GuiPreferences(QDialog):
|
||||
self.askBeforeBackup.setEnabled(state)
|
||||
return
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def _toggleHighlightQuotes(self, state: bool) -> None:
|
||||
"""Toggle switches controlled by the highlight quotes switch."""
|
||||
self.allowOpenSQuote.setEnabled(state)
|
||||
self.allowOpenDQuote.setEnabled(state)
|
||||
return
|
||||
|
||||
@pyqtSlot(bool)
|
||||
def _toggleAutoReplaceMain(self, state: bool) -> None:
|
||||
"""Toggle switches controlled by the auto replace switch."""
|
||||
@@ -927,19 +953,32 @@ class GuiPreferences(QDialog):
|
||||
CONFIG.scrollPastEnd = self.scrollPastEnd.isChecked()
|
||||
|
||||
# Text Highlighting
|
||||
highlightQuotes = self.highlightQuotes.isChecked()
|
||||
dialogueStyle = self.dialogStyle.currentData()
|
||||
allowOpenDial = self.allowOpenDial.isChecked()
|
||||
narratorBreak = self.narratorBreak.text()
|
||||
dialogueLine = self.dialogLine.text()
|
||||
altDialogOpen = self.altDialogOpen.text()
|
||||
altDialogClose = self.altDialogClose.text()
|
||||
highlightEmph = self.highlightEmph.isChecked()
|
||||
showMultiSpaces = self.showMultiSpaces.isChecked()
|
||||
|
||||
updateSyntax |= CONFIG.highlightQuotes != highlightQuotes
|
||||
updateSyntax |= CONFIG.dialogStyle != dialogueStyle
|
||||
updateSyntax |= CONFIG.allowOpenDial != allowOpenDial
|
||||
updateSyntax |= CONFIG.narratorBreak != narratorBreak
|
||||
updateSyntax |= CONFIG.dialogLine != dialogueLine
|
||||
updateSyntax |= CONFIG.altDialogOpen != altDialogOpen
|
||||
updateSyntax |= CONFIG.altDialogClose != altDialogClose
|
||||
updateSyntax |= CONFIG.highlightEmph != highlightEmph
|
||||
updateSyntax |= CONFIG.showMultiSpaces != showMultiSpaces
|
||||
|
||||
CONFIG.highlightQuotes = highlightQuotes
|
||||
CONFIG.dialogStyle = dialogueStyle
|
||||
CONFIG.allowOpenDial = allowOpenDial
|
||||
CONFIG.narratorBreak = narratorBreak
|
||||
CONFIG.dialogLine = dialogueLine
|
||||
CONFIG.altDialogOpen = altDialogOpen
|
||||
CONFIG.altDialogClose = altDialogClose
|
||||
CONFIG.highlightEmph = highlightEmph
|
||||
CONFIG.showMultiSpaces = showMultiSpaces
|
||||
CONFIG.allowOpenSQuote = self.allowOpenSQuote.isChecked()
|
||||
CONFIG.allowOpenDQuote = self.allowOpenDQuote.isChecked()
|
||||
|
||||
# Text Automation
|
||||
CONFIG.doReplace = self.doReplace.isChecked()
|
||||
|
||||
@@ -180,16 +180,26 @@ class NScrollableForm(QScrollArea):
|
||||
self._sections[identifier] = qLabel
|
||||
return
|
||||
|
||||
def addRow(self, label: str, widget: QWidget, helpText: str = "", unit: str | None = None,
|
||||
button: QWidget | None = None, editable: str | None = None,
|
||||
def addRow(self, label: str, widget: QWidget | list[QWidget], helpText: str = "",
|
||||
unit: str | None = None, button: QWidget | None = None, editable: str | None = None,
|
||||
stretch: tuple[int, int] = (1, 0)) -> None:
|
||||
"""Add a label and a widget as a new row of the form."""
|
||||
row = QHBoxLayout()
|
||||
row.setSpacing(CONFIG.pxInt(12))
|
||||
|
||||
if isinstance(widget, list):
|
||||
wBox = QHBoxLayout()
|
||||
wBox.setContentsMargins(0, 0, 0, 0)
|
||||
for item in widget:
|
||||
wBox.addWidget(item)
|
||||
qWidget = QWidget(self)
|
||||
qWidget.setLayout(wBox)
|
||||
else:
|
||||
qWidget = widget
|
||||
|
||||
qLabel = QLabel(label, self)
|
||||
qLabel.setIndent(self._indent)
|
||||
qLabel.setBuddy(widget)
|
||||
qLabel.setBuddy(qWidget)
|
||||
|
||||
if helpText:
|
||||
qHelp = NColourLabel(
|
||||
@@ -208,19 +218,19 @@ class NScrollableForm(QScrollArea):
|
||||
|
||||
if isinstance(unit, str):
|
||||
box = QHBoxLayout()
|
||||
box.addWidget(widget, 1)
|
||||
box.addWidget(qWidget, 1)
|
||||
box.addWidget(QLabel(unit, self), 0)
|
||||
row.addLayout(box, stretch[1])
|
||||
elif isinstance(button, QAbstractButton):
|
||||
box = QHBoxLayout()
|
||||
box.addWidget(widget, 1)
|
||||
box.addWidget(qWidget, 1)
|
||||
box.addWidget(button, 0)
|
||||
row.addLayout(box, stretch[1])
|
||||
else:
|
||||
row.addWidget(widget, stretch[1])
|
||||
row.addWidget(qWidget, stretch[1])
|
||||
|
||||
self._layout.addLayout(row)
|
||||
self._index[label.strip()] = widget
|
||||
self._index[label.strip()] = qWidget
|
||||
self._first = False
|
||||
|
||||
return
|
||||
|
||||
@@ -93,7 +93,7 @@ class NComboBox(QComboBox):
|
||||
event.ignore()
|
||||
return
|
||||
|
||||
def setCurrentData(self, data: str | Enum, default: str | Enum) -> None:
|
||||
def setCurrentData(self, data: str | int | Enum, default: str | int | Enum) -> None:
|
||||
"""Set the current index from data, with a fallback."""
|
||||
idx = self.findData(data)
|
||||
self.setCurrentIndex(self.findData(default) if idx < 0 else idx)
|
||||
|
||||
@@ -94,39 +94,42 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
colBreak.setAlpha(64)
|
||||
|
||||
# Create Character Formats
|
||||
self._addCharFormat("header1", SHARED.theme.colHead, "b", 1.8)
|
||||
self._addCharFormat("header2", SHARED.theme.colHead, "b", 1.6)
|
||||
self._addCharFormat("header3", SHARED.theme.colHead, "b", 1.4)
|
||||
self._addCharFormat("header4", SHARED.theme.colHead, "b", 1.2)
|
||||
self._addCharFormat("head1h", SHARED.theme.colHeadH, "b", 1.8)
|
||||
self._addCharFormat("head2h", SHARED.theme.colHeadH, "b", 1.6)
|
||||
self._addCharFormat("head3h", SHARED.theme.colHeadH, "b", 1.4)
|
||||
self._addCharFormat("head4h", SHARED.theme.colHeadH, "b", 1.2)
|
||||
self._addCharFormat("bold", colEmph, "b")
|
||||
self._addCharFormat("italic", colEmph, "i")
|
||||
self._addCharFormat("strike", SHARED.theme.colHidden, "s")
|
||||
self._addCharFormat("mspaces", SHARED.theme.colError, "err")
|
||||
self._addCharFormat("nobreak", colBreak, "bg")
|
||||
self._addCharFormat("dialog1", SHARED.theme.colDialN)
|
||||
self._addCharFormat("dialog2", SHARED.theme.colDialD)
|
||||
self._addCharFormat("dialog3", SHARED.theme.colDialS)
|
||||
self._addCharFormat("replace", SHARED.theme.colRepTag)
|
||||
self._addCharFormat("hidden", SHARED.theme.colHidden)
|
||||
self._addCharFormat("markup", SHARED.theme.colHidden)
|
||||
self._addCharFormat("note", SHARED.theme.colNote)
|
||||
self._addCharFormat("code", SHARED.theme.colCode)
|
||||
self._addCharFormat("keyword", SHARED.theme.colKey)
|
||||
self._addCharFormat("tag", SHARED.theme.colTag)
|
||||
self._addCharFormat("modifier", SHARED.theme.colMod)
|
||||
self._addCharFormat("value", SHARED.theme.colVal)
|
||||
self._addCharFormat("optional", SHARED.theme.colOpt)
|
||||
self._addCharFormat("invalid", None, "err")
|
||||
self._addCharFormat("text", SHARED.theme.colText)
|
||||
self._addCharFormat("header1", SHARED.theme.colHead, "b", 1.8)
|
||||
self._addCharFormat("header2", SHARED.theme.colHead, "b", 1.6)
|
||||
self._addCharFormat("header3", SHARED.theme.colHead, "b", 1.4)
|
||||
self._addCharFormat("header4", SHARED.theme.colHead, "b", 1.2)
|
||||
self._addCharFormat("head1h", SHARED.theme.colHeadH, "b", 1.8)
|
||||
self._addCharFormat("head2h", SHARED.theme.colHeadH, "b", 1.6)
|
||||
self._addCharFormat("head3h", SHARED.theme.colHeadH, "b", 1.4)
|
||||
self._addCharFormat("head4h", SHARED.theme.colHeadH, "b", 1.2)
|
||||
self._addCharFormat("bold", colEmph, "b")
|
||||
self._addCharFormat("italic", colEmph, "i")
|
||||
self._addCharFormat("strike", SHARED.theme.colHidden, "s")
|
||||
self._addCharFormat("mspaces", SHARED.theme.colError, "err")
|
||||
self._addCharFormat("nobreak", colBreak, "bg")
|
||||
self._addCharFormat("altdialog", SHARED.theme.colDialA)
|
||||
self._addCharFormat("dialog", SHARED.theme.colDialN)
|
||||
self._addCharFormat("replace", SHARED.theme.colRepTag)
|
||||
self._addCharFormat("hidden", SHARED.theme.colHidden)
|
||||
self._addCharFormat("markup", SHARED.theme.colHidden)
|
||||
self._addCharFormat("note", SHARED.theme.colNote)
|
||||
self._addCharFormat("code", SHARED.theme.colCode)
|
||||
self._addCharFormat("keyword", SHARED.theme.colKey)
|
||||
self._addCharFormat("tag", SHARED.theme.colTag)
|
||||
self._addCharFormat("modifier", SHARED.theme.colMod)
|
||||
self._addCharFormat("value", SHARED.theme.colVal)
|
||||
self._addCharFormat("optional", SHARED.theme.colOpt)
|
||||
self._addCharFormat("invalid", None, "err")
|
||||
|
||||
# Cache Spell Error Format
|
||||
self._spellErr = QTextCharFormat()
|
||||
self._spellErr.setUnderlineColor(SHARED.theme.colSpell)
|
||||
self._spellErr.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
|
||||
|
||||
self._txtRules.clear()
|
||||
self._cmnRules.clear()
|
||||
|
||||
# Multiple or Trailing Spaces
|
||||
if CONFIG.showMultiSpaces:
|
||||
rxRule = QRegularExpression(r"[ ]{2,}|[ ]*$")
|
||||
@@ -146,36 +149,50 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
||||
self._txtRules.append((rxRule, hlRule))
|
||||
self._cmnRules.append((rxRule, hlRule))
|
||||
|
||||
# Quoted Strings
|
||||
if CONFIG.highlightQuotes:
|
||||
fmtDblO = CONFIG.fmtDQuoteOpen
|
||||
fmtDblC = CONFIG.fmtDQuoteClose
|
||||
fmtSngO = CONFIG.fmtSQuoteOpen
|
||||
fmtSngC = CONFIG.fmtSQuoteClose
|
||||
# Dialogue
|
||||
if CONFIG.dialogStyle > 0:
|
||||
symO = ""
|
||||
symC = ""
|
||||
if CONFIG.dialogStyle in (1, 3):
|
||||
symO += CONFIG.fmtSQuoteOpen
|
||||
symC += CONFIG.fmtSQuoteClose
|
||||
if CONFIG.dialogStyle in (2, 3):
|
||||
symO += CONFIG.fmtDQuoteOpen
|
||||
symC += CONFIG.fmtDQuoteClose
|
||||
|
||||
# Straight Quotes
|
||||
rxRule = QRegularExpression(r'(\B")(.*?)("\B)')
|
||||
rxEnd = "|$" if CONFIG.allowOpenDial else ""
|
||||
rxRule = QRegularExpression(f"\\B[{symO}].*?[{symC}]\\B{rxEnd}")
|
||||
rxRule.setPatternOptions(QRegExUnicode)
|
||||
hlRule = {
|
||||
0: self._hStyles["dialog1"],
|
||||
0: self._hStyles["dialog"],
|
||||
}
|
||||
self._txtRules.append((rxRule, hlRule))
|
||||
|
||||
# Double Quotes
|
||||
dblEnd = "|$" if CONFIG.allowOpenDQuote else ""
|
||||
rxRule = QRegularExpression(f"(\\B{fmtDblO})(.*?)({fmtDblC}\\B{dblEnd})")
|
||||
if CONFIG.dialogLine:
|
||||
sym = QRegularExpression.escape(CONFIG.dialogLine)
|
||||
rxRule = QRegularExpression(f"^{sym}.*?$")
|
||||
rxRule.setPatternOptions(QRegExUnicode)
|
||||
hlRule = {
|
||||
0: self._hStyles["dialog2"],
|
||||
0: self._hStyles["dialog"],
|
||||
}
|
||||
self._txtRules.append((rxRule, hlRule))
|
||||
|
||||
# Single Quotes
|
||||
sngEnd = "|$" if CONFIG.allowOpenSQuote else ""
|
||||
rxRule = QRegularExpression(f"(\\B{fmtSngO})(.*?)({fmtSngC}\\B{sngEnd})")
|
||||
if CONFIG.narratorBreak:
|
||||
sym = QRegularExpression.escape(CONFIG.narratorBreak)
|
||||
rxRule = QRegularExpression(f"({sym}\\b)(.*?)(\\b{sym})")
|
||||
rxRule.setPatternOptions(QRegExUnicode)
|
||||
hlRule = {
|
||||
0: self._hStyles["dialog3"],
|
||||
0: self._hStyles["text"],
|
||||
}
|
||||
self._txtRules.append((rxRule, hlRule))
|
||||
|
||||
if CONFIG.altDialogOpen and CONFIG.altDialogClose:
|
||||
symO = QRegularExpression.escape(CONFIG.altDialogOpen)
|
||||
symC = QRegularExpression.escape(CONFIG.altDialogClose)
|
||||
rxRule = QRegularExpression(f"\\B{symO}.*?{symC}\\B")
|
||||
rxRule.setPatternOptions(QRegExUnicode)
|
||||
hlRule = {
|
||||
0: self._hStyles["altdialog"],
|
||||
}
|
||||
self._txtRules.append((rxRule, hlRule))
|
||||
|
||||
|
||||
@@ -96,8 +96,7 @@ class GuiTheme:
|
||||
self.colHeadH = QColor(0, 0, 0)
|
||||
self.colEmph = QColor(0, 0, 0)
|
||||
self.colDialN = QColor(0, 0, 0)
|
||||
self.colDialD = QColor(0, 0, 0)
|
||||
self.colDialS = QColor(0, 0, 0)
|
||||
self.colDialA = QColor(0, 0, 0)
|
||||
self.colHidden = QColor(0, 0, 0)
|
||||
self.colNote = QColor(0, 0, 0)
|
||||
self.colCode = QColor(0, 0, 0)
|
||||
@@ -338,9 +337,8 @@ class GuiTheme:
|
||||
self.colHead = self._parseColour(confParser, cnfSec, "headertext")
|
||||
self.colHeadH = self._parseColour(confParser, cnfSec, "headertag")
|
||||
self.colEmph = self._parseColour(confParser, cnfSec, "emphasis")
|
||||
self.colDialN = self._parseColour(confParser, cnfSec, "straightquotes")
|
||||
self.colDialD = self._parseColour(confParser, cnfSec, "doublequotes")
|
||||
self.colDialS = self._parseColour(confParser, cnfSec, "singlequotes")
|
||||
self.colDialN = self._parseColour(confParser, cnfSec, "dialog")
|
||||
self.colDialA = self._parseColour(confParser, cnfSec, "altdialog")
|
||||
self.colHidden = self._parseColour(confParser, cnfSec, "hidden")
|
||||
self.colNote = self._parseColour(confParser, cnfSec, "note")
|
||||
self.colCode = self._parseColour(confParser, cnfSec, "shortcode")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Meta]
|
||||
timestamp = 2024-04-13 18:57:38
|
||||
timestamp = 2024-05-13 15:59:59
|
||||
|
||||
[Main]
|
||||
theme = default
|
||||
@@ -59,9 +59,12 @@ showlineendings = False
|
||||
showmultispaces = True
|
||||
incnoteswcount = True
|
||||
showfullpath = True
|
||||
highlightquotes = True
|
||||
allowopensquote = False
|
||||
allowopendquote = True
|
||||
dialogstyle = 2
|
||||
allowopendial = True
|
||||
narratorbreak =
|
||||
altdialogopen =
|
||||
altdialogclose =
|
||||
dialogline =
|
||||
highlightemph = True
|
||||
stopwhenidle = True
|
||||
useridletime = 300
|
||||
|
||||
@@ -266,18 +266,21 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
||||
assert CONFIG.autoScrollPos == 30
|
||||
|
||||
# Text Highlighting
|
||||
prefs.allowOpenSQuote.setChecked(True)
|
||||
prefs.allowOpenDQuote.setChecked(False)
|
||||
prefs.highlightQuotes.setChecked(False)
|
||||
prefs.dialogStyle.setCurrentData(3, 0)
|
||||
prefs.allowOpenDial.setChecked(False)
|
||||
prefs.narratorBreak.setText("–")
|
||||
prefs.dialogLine.setText("–")
|
||||
prefs.altDialogOpen.setText("<")
|
||||
prefs.altDialogClose.setText(">")
|
||||
prefs.highlightEmph.setChecked(False)
|
||||
prefs.showMultiSpaces.setChecked(False)
|
||||
|
||||
assert prefs.allowOpenSQuote.isEnabled() is False
|
||||
assert prefs.allowOpenDQuote.isEnabled() is False
|
||||
|
||||
assert CONFIG.highlightQuotes is True
|
||||
assert CONFIG.allowOpenSQuote is False
|
||||
assert CONFIG.allowOpenDQuote is True
|
||||
assert CONFIG.dialogStyle == 2
|
||||
assert CONFIG.allowOpenDial is True
|
||||
assert CONFIG.narratorBreak == ""
|
||||
assert CONFIG.dialogLine == ""
|
||||
assert CONFIG.altDialogOpen == ""
|
||||
assert CONFIG.altDialogClose == ""
|
||||
assert CONFIG.highlightEmph is True
|
||||
assert CONFIG.showMultiSpaces is True
|
||||
|
||||
@@ -384,9 +387,12 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, tstPaths):
|
||||
assert CONFIG.autoScrollPos == 31
|
||||
|
||||
# Text Highlighting
|
||||
assert CONFIG.highlightQuotes is False
|
||||
assert CONFIG.allowOpenSQuote is True
|
||||
assert CONFIG.allowOpenDQuote is False
|
||||
assert CONFIG.dialogStyle == 3
|
||||
assert CONFIG.allowOpenDial is False
|
||||
assert CONFIG.narratorBreak == "–"
|
||||
assert CONFIG.dialogLine == "–"
|
||||
assert CONFIG.altDialogOpen == "<"
|
||||
assert CONFIG.altDialogClose == ">"
|
||||
assert CONFIG.highlightEmph is False
|
||||
assert CONFIG.showMultiSpaces is False
|
||||
|
||||
|
||||
@@ -231,7 +231,15 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
||||
# Text Editor
|
||||
# ===========
|
||||
|
||||
docEditor: GuiDocEditor = nwGUI.docEditor
|
||||
# Syntax Highlighting
|
||||
CONFIG.dialogStyle = 3
|
||||
CONFIG.dialogLine = "–"
|
||||
CONFIG.narratorBreak = "–"
|
||||
CONFIG.altDialogOpen = "<|"
|
||||
CONFIG.altDialogClose = "|>"
|
||||
|
||||
docEditor = nwGUI.docEditor
|
||||
docEditor._qDocument.syntaxHighlighter.initHighlighter()
|
||||
|
||||
# Type something into the document
|
||||
nwGUI.switchFocus(nwWidget.EDITOR)
|
||||
|
||||
Reference in New Issue
Block a user