Limit narrator symbols to dashes (#2324)

This commit is contained in:
Veronica Berglyd Olsen
2025-05-04 21:53:49 +02:00
parent 68cc38e443
commit 6f38867972
4 changed files with 28 additions and 19 deletions
+6 -3
View File
@@ -44,7 +44,7 @@ from novelwriter.common import (
NWConfigParser, checkInt, checkPath, describeFont, fontMatcher, NWConfigParser, checkInt, checkPath, describeFont, fontMatcher,
formatTimeStamp formatTimeStamp
) )
from novelwriter.constants import nwFiles, nwHtmlUnicode, nwUnicode from novelwriter.constants import nwFiles, nwHtmlUnicode, nwQuotes, nwUnicode
from novelwriter.error import formatException, logException from novelwriter.error import formatException, logException
if TYPE_CHECKING: if TYPE_CHECKING:
@@ -681,8 +681,8 @@ class Config:
self.dialogStyle = conf.rdInt(sec, "dialogstyle", self.dialogStyle) self.dialogStyle = conf.rdInt(sec, "dialogstyle", self.dialogStyle)
self.allowOpenDial = conf.rdBool(sec, "allowopendial", self.allowOpenDial) self.allowOpenDial = conf.rdBool(sec, "allowopendial", self.allowOpenDial)
self.dialogLine = conf.rdStr(sec, "dialogline", self.dialogLine) self.dialogLine = conf.rdStr(sec, "dialogline", self.dialogLine)
self.narratorBreak = conf.rdStr(sec, "narratorbreak", self.narratorBreak) narratorBreak = conf.rdStr(sec, "narratorbreak", self.narratorBreak)
self.narratorDialog = conf.rdStr(sec, "narratordialog", self.narratorDialog) narratorDialog = conf.rdStr(sec, "narratordialog", self.narratorDialog)
self.altDialogOpen = conf.rdStr(sec, "altdialogopen", self.altDialogOpen) self.altDialogOpen = conf.rdStr(sec, "altdialogopen", self.altDialogOpen)
self.altDialogClose = conf.rdStr(sec, "altdialogclose", self.altDialogClose) self.altDialogClose = conf.rdStr(sec, "altdialogclose", self.altDialogClose)
self.highlightEmph = conf.rdBool(sec, "highlightemph", self.highlightEmph) self.highlightEmph = conf.rdBool(sec, "highlightemph", self.highlightEmph)
@@ -721,6 +721,9 @@ class Config:
logger.info("Using straight double quotes, so disabling auto-replace") logger.info("Using straight double quotes, so disabling auto-replace")
self.doReplaceDQuote = False self.doReplaceDQuote = False
self.narratorBreak = narratorBreak if narratorBreak in nwQuotes.DASHES else ""
self.narratorDialog = narratorDialog if narratorDialog in nwQuotes.DASHES else ""
return True return True
def saveConfig(self) -> bool: def saveConfig(self) -> bool:
+7
View File
@@ -505,6 +505,13 @@ class nwQuotes:
"\u300f": QT_TRANSLATE_NOOP("Constant", "Right white corner bracket"), "\u300f": QT_TRANSLATE_NOOP("Constant", "Right white corner bracket"),
} }
DASHES: Final[dict[str, str]] = {
"": QT_TRANSLATE_NOOP("Constant", "None"),
"\u2013": QT_TRANSLATE_NOOP("Constant", "Short dash"),
"\u2014": QT_TRANSLATE_NOOP("Constant", "Long dash"),
"\u2015": QT_TRANSLATE_NOOP("Constant", "Horizontal bar"),
}
class nwUnicode: class nwUnicode:
"""Supported unicode character constants and their HTML equivalents.""" """Supported unicode character constants and their HTML equivalents."""
+13 -14
View File
@@ -36,7 +36,7 @@ from PyQt6.QtWidgets import (
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import compact, describeFont, uniqueCompact from novelwriter.common import compact, describeFont, uniqueCompact
from novelwriter.config import DEF_GUI, DEF_ICONS, DEF_SYNTAX, DEF_TREECOL from novelwriter.config import DEF_GUI, DEF_ICONS, DEF_SYNTAX, DEF_TREECOL
from novelwriter.constants import nwLabels, nwUnicode, trConst from novelwriter.constants import nwLabels, nwQuotes, nwUnicode, trConst
from novelwriter.dialogs.quotes import GuiQuoteSelect from novelwriter.dialogs.quotes import GuiQuoteSelect
from novelwriter.extensions.configlayout import NColorLabel, NScrollableForm from novelwriter.extensions.configlayout import NColorLabel, NScrollableForm
from novelwriter.extensions.modified import ( from novelwriter.extensions.modified import (
@@ -636,21 +636,20 @@ class GuiPreferences(NDialog):
self.tr("Lines starting with any of these symbols are dialogue.") self.tr("Lines starting with any of these symbols are dialogue.")
) )
self.narratorBreak = QLineEdit(self) self.narratorBreak = NComboBox(self)
self.narratorBreak.setMaxLength(1) self.narratorDialog = NComboBox(self)
self.narratorBreak.setFixedWidth(boxFixed) for key, value in nwQuotes.DASHES.items():
self.narratorBreak.setAlignment(QtAlignCenter) label = trConst(value)
self.narratorBreak.setText(CONFIG.narratorBreak) self.narratorBreak.addItem(label, key)
self.narratorDialog.addItem(label, key)
self.narratorBreak.setCurrentData(CONFIG.narratorBreak, "")
self.narratorDialog.setCurrentData(CONFIG.narratorDialog, "")
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Narrator break symbol"), self.narratorBreak, self.tr("Narrator break symbol"), self.narratorBreak,
self.tr("Symbol to indicate a narrator break in dialogue.") self.tr("Symbol to indicate a narrator break in dialogue.")
) )
self.narratorDialog = QLineEdit(self)
self.narratorDialog.setMaxLength(1)
self.narratorDialog.setFixedWidth(boxFixed)
self.narratorDialog.setAlignment(QtAlignCenter)
self.narratorDialog.setText(CONFIG.narratorDialog)
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Alternating dialogue/narration symbol"), self.narratorDialog, self.tr("Alternating dialogue/narration symbol"), self.narratorDialog,
self.tr("Alternates dialogue highlighting within any paragraph.") self.tr("Alternates dialogue highlighting within any paragraph.")
@@ -1035,8 +1034,8 @@ class GuiPreferences(NDialog):
dialogueStyle = self.dialogStyle.currentData() dialogueStyle = self.dialogStyle.currentData()
allowOpenDial = self.allowOpenDial.isChecked() allowOpenDial = self.allowOpenDial.isChecked()
dialogueLine = uniqueCompact(self.dialogLine.text()) dialogueLine = uniqueCompact(self.dialogLine.text())
narratorBreak = self.narratorBreak.text().strip() narratorBreak = self.narratorBreak.currentData()
narratorDialog = self.narratorDialog.text().strip() narratorDialog = self.narratorDialog.currentData()
altDialogOpen = compact(self.altDialogOpen.text()) altDialogOpen = compact(self.altDialogOpen.text())
altDialogClose = compact(self.altDialogClose.text()) altDialogClose = compact(self.altDialogClose.text())
highlightEmph = self.highlightEmph.isChecked() highlightEmph = self.highlightEmph.isChecked()
+2 -2
View File
@@ -265,8 +265,8 @@ def testDlgPreferences_Settings(qtbot, monkeypatch, nwGUI, fncPath, tstPaths):
prefs.dialogStyle.setCurrentData(3, 0) prefs.dialogStyle.setCurrentData(3, 0)
prefs.allowOpenDial.setChecked(False) prefs.allowOpenDial.setChecked(False)
prefs.dialogLine.setText("") prefs.dialogLine.setText("")
prefs.narratorBreak.setText("") prefs.narratorBreak.setCurrentData("", "")
prefs.narratorDialog.setText("") prefs.narratorDialog.setCurrentData("", "")
prefs.altDialogOpen.setText("<") prefs.altDialogOpen.setText("<")
prefs.altDialogClose.setText(">") prefs.altDialogClose.setText(">")
prefs.highlightEmph.setChecked(False) prefs.highlightEmph.setChecked(False)