Improve build settings
This commit is contained in:
@@ -40,15 +40,15 @@ from novelwriter.constants import nwFiles, nwHeadFmt
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.enum import nwBuildFmt
|
||||
from novelwriter.error import logException
|
||||
from novelwriter.types import T_Basic
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# The Settings Template
|
||||
# =====================
|
||||
# Each entry contains a tuple on the form:
|
||||
# (type, default, [min value, max value])
|
||||
# Each entry contains a tuple on the form: (type, default)
|
||||
|
||||
SETTINGS_TEMPLATE = {
|
||||
SETTINGS_TEMPLATE: dict[str, tuple[type, T_Basic]] = {
|
||||
"filter.includeNovel": (bool, True),
|
||||
"filter.includeNotes": (bool, False),
|
||||
"filter.includeInactive": (bool, False),
|
||||
@@ -83,7 +83,7 @@ SETTINGS_TEMPLATE = {
|
||||
"text.ignoredKeywords": (str, ""),
|
||||
"text.addNoteHeadings": (bool, True),
|
||||
"format.textFont": (str, CONFIG.textFont.toString()),
|
||||
"format.lineHeight": (float, 1.15, 0.75, 3.0),
|
||||
"format.lineHeight": (float, 1.15),
|
||||
"format.justifyText": (bool, False),
|
||||
"format.stripUnicode": (bool, False),
|
||||
"format.replaceTabs": (bool, False),
|
||||
@@ -356,18 +356,12 @@ class BuildSettings:
|
||||
self._changed = True
|
||||
return
|
||||
|
||||
def setValue(self, key: str, value: str | int | bool | float) -> bool:
|
||||
def setValue(self, key: str, value: T_Basic) -> None:
|
||||
"""Set a specific value for a build setting."""
|
||||
if key not in SETTINGS_TEMPLATE:
|
||||
return False
|
||||
definition = SETTINGS_TEMPLATE[key]
|
||||
if not isinstance(value, definition[0]):
|
||||
return False
|
||||
if len(definition) == 4 and isinstance(value, (int, float)):
|
||||
value = min(max(value, definition[2]), definition[3])
|
||||
self._changed = value != self._settings[key]
|
||||
self._settings[key] = value
|
||||
return True
|
||||
if (d := SETTINGS_TEMPLATE.get(key)) and len(d) == 2 and isinstance(value, d[0]):
|
||||
self._changed = value != self._settings[key]
|
||||
self._settings[key] = value
|
||||
return
|
||||
|
||||
##
|
||||
# Methods
|
||||
|
||||
@@ -27,6 +27,10 @@ from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QColor, QFont, QPainter, QTextCharFormat, QTextCursor, QTextFormat
|
||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QSizePolicy, QStyle
|
||||
|
||||
# Type Aliases
|
||||
|
||||
T_Basic = str | int | float | bool
|
||||
|
||||
# Qt Alignment Flags
|
||||
|
||||
QtAlignAbsolute = Qt.AlignmentFlag.AlignAbsolute
|
||||
|
||||
Reference in New Issue
Block a user