Improve dialogue line symbol setting box (#2453)

This commit is contained in:
Veronica Berglyd Olsen
2025-07-06 18:20:13 +02:00
parent dadc7edbd9
commit ec9e478399
3 changed files with 35 additions and 12 deletions
+1 -1
View File
@@ -301,7 +301,7 @@ def uniqueCompact(text: str) -> str:
def processDialogSymbols(symbols: str) -> str: def processDialogSymbols(symbols: str) -> str:
"""Process dialogue line symbols.""" """Process dialogue line symbols."""
result = "" result = ""
for c in uniqueCompact(symbols): for c in uniqueCompact("".join(symbols.split())):
if c in nwQuotes.ALLOWED: if c in nwQuotes.ALLOWED:
result += c result += c
return result return result
+25 -5
View File
@@ -29,7 +29,7 @@ import logging
from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot from PyQt6.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QAction, QCloseEvent, QKeyEvent, QKeySequence from PyQt6.QtGui import QAction, QCloseEvent, QKeyEvent, QKeySequence
from PyQt6.QtWidgets import ( from PyQt6.QtWidgets import (
QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit, QCompleter, QDialogButtonBox, QFileDialog, QHBoxLayout, QLineEdit, QMenu,
QPushButton, QVBoxLayout, QWidget QPushButton, QVBoxLayout, QWidget
) )
@@ -639,14 +639,26 @@ class GuiPreferences(NDialog):
) )
# Dialogue Line # Dialogue Line
self.mnLineSymbols = QMenu(self)
for symbol in nwQuotes.ALLOWED:
label = trConst(nwQuotes.SYMBOLS.get(symbol, nwQuotes.DASHES.get(symbol, "None")))
self.mnLineSymbols.addAction(
f"[ {symbol } ] {label}",
lambda symbol=symbol: self._insertDialogLineSymbol(symbol)
)
self.dialogLine = QLineEdit(self) self.dialogLine = QLineEdit(self)
self.dialogLine.setMaxLength(4) self.dialogLine.setMinimumWidth(100)
self.dialogLine.setFixedWidth(boxFixed)
self.dialogLine.setAlignment(QtAlignCenter) self.dialogLine.setAlignment(QtAlignCenter)
self.dialogLine.setText(CONFIG.dialogLine) self.dialogLine.setText(" ".join(CONFIG.dialogLine))
self.dialogLineButton = NIconToolButton(self, iSz, "add", "green")
self.dialogLineButton.setMenu(self.mnLineSymbols)
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Dialogue line symbols"), self.dialogLine, self.tr("Dialogue line symbols"), self.dialogLine,
self.tr("Lines starting with any of these symbols are dialogue.") self.tr("Lines starting with any of these symbols are dialogue."),
button=self.dialogLineButton
) )
# Narrator Break # Narrator Break
@@ -913,6 +925,14 @@ class GuiPreferences(NDialog):
self.askBeforeBackup.setEnabled(state) self.askBeforeBackup.setEnabled(state)
return return
@pyqtSlot(str)
def _insertDialogLineSymbol(self, symbol: str) -> None:
"""Insert a symbol in the dialogue line box."""
current = self.dialogLine.text()
values = processDialogSymbols(f"{current} {symbol}")
self.dialogLine.setText(" ".join(values))
return
@pyqtSlot(bool) @pyqtSlot(bool)
def _toggleAutoReplaceMain(self, state: bool) -> None: def _toggleAutoReplaceMain(self, state: bool) -> None:
"""Toggle switches controlled by the auto replace switch.""" """Toggle switches controlled by the auto replace switch."""
+9 -6
View File
@@ -268,14 +268,17 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
# Text Highlighting # Text Highlighting
prefs.dialogStyle.setCurrentData(3, 0) prefs.dialogStyle.setCurrentData(3, 0)
prefs.allowOpenDial.setChecked(False) prefs.allowOpenDial.setChecked(False)
prefs.dialogLine.setText("") prefs.dialogLine.setText(nwUnicode.U_EMDASH)
prefs.narratorBreak.setCurrentData("", "") prefs.narratorBreak.setCurrentData(nwUnicode.U_EMDASH, "")
prefs.narratorDialog.setCurrentData("", "") prefs.narratorDialog.setCurrentData(nwUnicode.U_EMDASH, "")
prefs.altDialogOpen.setText("%") # Symbol also tests for #2455 prefs.altDialogOpen.setText("%") # Symbol also tests for #2455
prefs.altDialogClose.setText("%") # Symbol also tests for #2455 prefs.altDialogClose.setText("%") # Symbol also tests for #2455
prefs.highlightEmph.setChecked(False) prefs.highlightEmph.setChecked(False)
prefs.showMultiSpaces.setChecked(False) prefs.showMultiSpaces.setChecked(False)
prefs._insertDialogLineSymbol(nwUnicode.U_ENDASH)
assert prefs.dialogLine.text() == f"{nwUnicode.U_ENDASH} {nwUnicode.U_EMDASH}"
assert CONFIG.dialogStyle == 2 assert CONFIG.dialogStyle == 2
assert CONFIG.allowOpenDial is True assert CONFIG.allowOpenDial is True
assert CONFIG.dialogLine == "" assert CONFIG.dialogLine == ""
@@ -398,9 +401,9 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
# Text Highlighting # Text Highlighting
assert CONFIG.dialogStyle == 3 assert CONFIG.dialogStyle == 3
assert CONFIG.allowOpenDial is False assert CONFIG.allowOpenDial is False
assert CONFIG.dialogLine == "" assert CONFIG.dialogLine == f"{nwUnicode.U_ENDASH}{nwUnicode.U_EMDASH}"
assert CONFIG.narratorBreak == "" assert CONFIG.narratorBreak == nwUnicode.U_EMDASH
assert CONFIG.narratorDialog == "" assert CONFIG.narratorDialog == nwUnicode.U_EMDASH
assert CONFIG.altDialogOpen == "%" assert CONFIG.altDialogOpen == "%"
assert CONFIG.altDialogClose == "%" assert CONFIG.altDialogClose == "%"
assert CONFIG.highlightEmph is False assert CONFIG.highlightEmph is False