From be89dd62383dc8c9caa04f15910f8223388b9f3b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 30 May 2020 22:01:55 +0200 Subject: [PATCH 1/2] Added the option to change GUI font size --- nw/config.py | 27 +++++++++++++++------------ nw/gui/dialogs/preferences.py | 20 ++++++++++++++++++-- nw/gui/theme.py | 8 ++++++-- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/nw/config.py b/nw/config.py index 18529f610..07b58c7e6 100644 --- a/nw/config.py +++ b/nw/config.py @@ -36,7 +36,6 @@ from PyQt5.Qt import PYQT_VERSION_STR from PyQt5.QtCore import QT_VERSION_STR, QStandardPaths, QSysInfo -from PyQt5.QtWidgets import QErrorMessage from nw.constants import nwFiles, nwUnicode from nw.common import splitVersionNumber, formatTimeStamp @@ -82,11 +81,12 @@ def __init__(self): self.confChanged = False ## General - self.guiTheme = "default" - self.guiSyntax = "default_light" - self.guiIcons = "typicons_grey_light" - self.guiDark = False - self.guiLang = "en" # Hardcoded for now + self.guiTheme = "default" + self.guiSyntax = "default_light" + self.guiIcons = "typicons_grey_light" + self.guiDark = False + self.guiLang = "en" # Hardcoded for now + self.guiFontSize = 12 ## Sizes self.winGeometry = [1100, 650] @@ -202,7 +202,6 @@ def initConfig(self, confPath=None, dataPath=None): """Initialise the config class. The manual setting of confPath and dataPath is mainly intended for the test suite. """ - if confPath is None: confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation) self.confPath = path.join(path.abspath(confRoot), self.appHandle) @@ -318,6 +317,9 @@ def loadConfig(self): self.guiDark = self._parseLine( cnfParse, cnfSec, "guidark", self.CNF_BOOL, self.guiDark ) + self.guiFontSize = self._parseLine( + cnfParse, cnfSec, "guifontsize", self.CNF_INT, self.guiFontSize + ) ## Sizes cnfSec = "Sizes" @@ -464,11 +466,12 @@ def saveConfig(self): ## Main cnfSec = "Main" cnfParse.add_section(cnfSec) - cnfParse.set(cnfSec,"timestamp", formatTimeStamp(time())) - cnfParse.set(cnfSec,"theme", str(self.guiTheme)) - cnfParse.set(cnfSec,"syntax", str(self.guiSyntax)) - cnfParse.set(cnfSec,"icons", str(self.guiIcons)) - cnfParse.set(cnfSec,"guidark", str(self.guiDark)) + cnfParse.set(cnfSec,"timestamp", formatTimeStamp(time())) + cnfParse.set(cnfSec,"theme", str(self.guiTheme)) + cnfParse.set(cnfSec,"syntax", str(self.guiSyntax)) + cnfParse.set(cnfSec,"icons", str(self.guiIcons)) + cnfParse.set(cnfSec,"guidark", str(self.guiDark)) + cnfParse.set(cnfSec,"guifontsize", str(self.guiFontSize)) ## Sizes cnfSec = "Sizes" diff --git a/nw/gui/dialogs/preferences.py b/nw/gui/dialogs/preferences.py index eaa034d14..e6e6ca4f5 100644 --- a/nw/gui/dialogs/preferences.py +++ b/nw/gui/dialogs/preferences.py @@ -183,6 +183,19 @@ def __init__(self, theParent): "This may improve the look of icons on dark themes." ) + ## Font Size + self.guiFontSize = QSpinBox(self) + self.guiFontSize.setMinimum(8) + self.guiFontSize.setMaximum(60) + self.guiFontSize.setSingleStep(1) + self.guiFontSize.setValue(self.mainConf.guiFontSize) + self.mainForm.addRow( + "Font size", + self.guiFontSize, + "Changing this requires restarting %s." % nw.__package__, + theUnit="pt" + ) + # GUI Settings # ============ self.mainForm.addGroupLabel("GUI Settings") @@ -266,6 +279,7 @@ def saveValues(self): guiTheme = self.selectTheme.currentData() guiIcons = self.selectIcons.currentData() guiDark = self.preferDarkIcons.isChecked() + guiFontSize = self.guiFontSize.value() showFullPath = self.showFullPath.isChecked() autoSaveDoc = self.autoSaveDoc.value() autoSaveProj = self.autoSaveProj.value() @@ -276,10 +290,12 @@ def saveValues(self): # Check if restart is needed needsRestart |= self.mainConf.guiTheme != guiTheme needsRestart |= self.mainConf.guiIcons != guiIcons + needsRestart |= self.mainConf.guiFontSize != guiFontSize self.mainConf.guiTheme = guiTheme self.mainConf.guiIcons = guiIcons self.mainConf.guiDark = guiDark + self.mainConf.guiFontSize = guiFontSize self.mainConf.showFullPath = showFullPath self.mainConf.autoSaveDoc = autoSaveDoc self.mainConf.autoSaveProj = autoSaveProj @@ -353,8 +369,8 @@ def __init__(self, theParent): ## Font Size self.textStyleSize = QSpinBox(self) - self.textStyleSize.setMinimum(5) - self.textStyleSize.setMaximum(120) + self.textStyleSize.setMinimum(8) + self.textStyleSize.setMaximum(60) self.textStyleSize.setSingleStep(1) self.textStyleSize.setValue(self.mainConf.textSize) self.mainForm.addRow( diff --git a/nw/gui/theme.py b/nw/gui/theme.py index cf29e4b02..5d74036f6 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -111,6 +111,11 @@ def __init__(self, theParent): self.confFile = None self.cssFile = None + # Set Font Size and Theme + self.guiFont = qApp.font() + self.guiFont.setPointSizeF(self.mainConf.guiFontSize) + qApp.setFont(self.guiFont) + self.updateTheme() self.theIcons.updateTheme() @@ -119,8 +124,7 @@ def __init__(self, theParent): self.loadDecoration = self.theIcons.loadDecoration # Extract Other Info - self.guiDPI = qApp.primaryScreen().physicalDotsPerInch() - self.guiFont = qApp.font() + self.guiDPI = qApp.primaryScreen().physicalDotsPerInch() qMetric = QFontMetrics(self.guiFont) self.fontPointSize = self.guiFont.pointSizeF() From 521ab956d9ee0fcffed45d7a9f14ab38f990a495 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 30 May 2020 22:05:21 +0200 Subject: [PATCH 2/2] Fixed tests --- tests/reference/novelwriter.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf index acc95a943..5f4768e66 100644 --- a/tests/reference/novelwriter.conf +++ b/tests/reference/novelwriter.conf @@ -4,6 +4,7 @@ theme = default syntax = default_light icons = typicons_grey_light guidark = False +guifontsize = 12 [Sizes] geometry = 1100, 650