From 25c4330fd0c7bb2a9b4bfd9ad6de1ab21396156a Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:27:55 +0200 Subject: [PATCH] Make icon theme a part of the GUI theme (solves #1172) --- novelwriter/assets/themes/default.conf | 3 +- novelwriter/assets/themes/default_dark.conf | 1 + novelwriter/assets/themes/solarized_dark.conf | 1 + .../assets/themes/solarized_light.conf | 1 + novelwriter/config.py | 6 ---- novelwriter/dialogs/preferences.py | 19 ------------- novelwriter/gui/theme.py | 28 ++++--------------- tests/test_base/test_base_config.py | 26 ----------------- tests/test_gui/test_gui_theme.py | 2 +- 9 files changed, 11 insertions(+), 76 deletions(-) diff --git a/novelwriter/assets/themes/default.conf b/novelwriter/assets/themes/default.conf index 004b811d..db780c75 100644 --- a/novelwriter/assets/themes/default.conf +++ b/novelwriter/assets/themes/default.conf @@ -1,2 +1,3 @@ [Main] -name = Default System Theme +name = Default Theme +icontheme = typicons_light diff --git a/novelwriter/assets/themes/default_dark.conf b/novelwriter/assets/themes/default_dark.conf index 44317ac1..97039825 100644 --- a/novelwriter/assets/themes/default_dark.conf +++ b/novelwriter/assets/themes/default_dark.conf @@ -5,6 +5,7 @@ credit = Veronica Berglyd Olsen url = https://github.com/vkbo/novelWriter license = CC BY-SA 4.0 licenseurl = https://creativecommons.org/licenses/by-sa/4.0/ +icontheme = typicons_dark [Palette] window = 54, 54, 54 diff --git a/novelwriter/assets/themes/solarized_dark.conf b/novelwriter/assets/themes/solarized_dark.conf index 812d968d..cf46d519 100644 --- a/novelwriter/assets/themes/solarized_dark.conf +++ b/novelwriter/assets/themes/solarized_dark.conf @@ -5,6 +5,7 @@ credit = Ethan Schoonover url = https://ethanschoonover.com/solarized/ license = MIT licenseurl = https://github.com/altercation/solarized/blob/master/LICENSE +icontheme = typicons_dark [Palette] window = 0, 43, 54 diff --git a/novelwriter/assets/themes/solarized_light.conf b/novelwriter/assets/themes/solarized_light.conf index 855e4e76..c9fb50c0 100644 --- a/novelwriter/assets/themes/solarized_light.conf +++ b/novelwriter/assets/themes/solarized_light.conf @@ -5,6 +5,7 @@ credit = Ethan Schoonover url = https://ethanschoonover.com/solarized/ license = MIT licenseurl = https://github.com/altercation/solarized/blob/master/LICENSE +icontheme = typicons_light [Palette] window = 238, 232, 213 diff --git a/novelwriter/config.py b/novelwriter/config.py index 73a8c3c6..ecc5f4db 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -508,12 +508,6 @@ class Config: logger.info("Using straight double quotes, so disabling auto-replace") self.doReplaceDQuote = False - # Check deprecated settings - if self.guiIcons in ("typicons_colour_dark", "typicons_grey_dark"): - self.guiIcons = "typicons_dark" - elif self.guiIcons in ("typicons_colour_light", "typicons_grey_light"): - self.guiIcons = "typicons_light" - return True def saveConfig(self): diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index ae2df4c5..4551d3e6 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -185,22 +185,6 @@ class GuiPreferencesGeneral(QWidget): self.tr("Requires restart.") ) - # Select Icon Theme - self.guiIcons = QComboBox() - self.guiIcons.setMinimumWidth(minWidth) - self.iconCache = self.mainTheme.iconCache.listThemes() - for iconDir, iconName in self.iconCache: - self.guiIcons.addItem(iconName, iconDir) - iconIdx = self.guiIcons.findData(self.mainConf.guiIcons) - if iconIdx != -1: - self.guiIcons.setCurrentIndex(iconIdx) - - self.mainForm.addRow( - self.tr("Main icon theme"), - self.guiIcons, - self.tr("Requires restart.") - ) - # Editor Theme self.guiSyntax = QComboBox() self.guiSyntax.setMinimumWidth(self.mainConf.pxInt(200)) @@ -288,7 +272,6 @@ class GuiPreferencesGeneral(QWidget): """ guiLang = self.guiLang.currentData() guiTheme = self.guiTheme.currentData() - guiIcons = self.guiIcons.currentData() guiSyntax = self.guiSyntax.currentData() guiFont = self.guiFont.text() guiFontSize = self.guiFontSize.value() @@ -298,7 +281,6 @@ class GuiPreferencesGeneral(QWidget): needsRestart = False needsRestart |= self.mainConf.guiLang != guiLang needsRestart |= self.mainConf.guiTheme != guiTheme - needsRestart |= self.mainConf.guiIcons != guiIcons needsRestart |= self.mainConf.guiFont != guiFont needsRestart |= self.mainConf.guiFontSize != guiFontSize @@ -308,7 +290,6 @@ class GuiPreferencesGeneral(QWidget): self.mainConf.guiLang = guiLang self.mainConf.guiTheme = guiTheme - self.mainConf.guiIcons = guiIcons self.mainConf.guiSyntax = guiSyntax self.mainConf.guiFont = guiFont self.mainConf.guiFontSize = guiFontSize diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 4c76179d..b13e43ca 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -67,6 +67,7 @@ class GuiTheme: self.themeUrl = "" self.themeLicense = "" self.themeLicenseUrl = "" + self.themeIcons = "" # GUI self.statNone = [120, 120, 120] @@ -267,6 +268,7 @@ class GuiTheme: self.themeUrl = confParser.rdStr(cnfSec, "url", "") self.themeLicense = confParser.rdStr(cnfSec, "license", "N/A") self.themeLicenseUrl = confParser.rdStr(cnfSec, "licenseurl", "") + self.themeIcons = confParser.rdStr(cnfSec, "icontheme", "") # Palette cnfSec = "Palette" @@ -293,6 +295,9 @@ class GuiTheme: self.statUnsaved = self._loadColour(confParser, cnfSec, "statusunsaved") self.statSaved = self._loadColour(confParser, cnfSec, "statussaved") + # Set Icon Theme + self.mainConf.guiIcons = self.themeIcons + # CSS File cssData = readTextFile(self.cssFile) if cssData: @@ -492,7 +497,6 @@ class GuiIcons: # Storage self._qIcons = {} self._themeMap = {} - self._themeList = [] self._headerDec = [] self._confName = "icons.conf" @@ -668,28 +672,6 @@ class GuiIcons: ] return self._headerDec[minmax(hLevel, 0, 4)] - def listThemes(self): - """Scan the icons themes folder and list all themes. - """ - if self._themeList: - return self._themeList - - confParser = NWConfigParser() - for themeDir in os.listdir(self._iconPath): - themePath = os.path.join(self._iconPath, themeDir) - if not os.path.isdir(themePath): - continue - - logger.debug("Checking icon theme config for '%s'", themeDir) - themeConf = os.path.join(themePath, self._confName) - themeName = _loadInternalName(confParser, themeConf) - if themeName: - self._themeList.append((themeDir, themeName)) - - self._themeList = sorted(self._themeList, key=lambda x: x[1]) - - return self._themeList - ## # Internal Functions ## diff --git a/tests/test_base/test_base_config.py b/tests/test_base/test_base_config.py index f6721493..61994f04 100644 --- a/tests/test_base/test_base_config.py +++ b/tests/test_base/test_base_config.py @@ -192,32 +192,6 @@ def testBaseConfig_Init(monkeypatch, tmpDir, fncDir, outDir, refDir, filesDir): tstConf.doReplaceSQuote = orDoSng assert tstConf.saveConfig() is True - # Test Correcting icon theme - origIcons = tstConf.guiIcons - - tstConf.guiIcons = "typicons_colour_dark" - assert tstConf.saveConfig() is True - assert tstConf.loadConfig() is True - assert tstConf.guiIcons == "typicons_dark" - - tstConf.guiIcons = "typicons_grey_dark" - assert tstConf.saveConfig() is True - assert tstConf.loadConfig() is True - assert tstConf.guiIcons == "typicons_dark" - - tstConf.guiIcons = "typicons_colour_light" - assert tstConf.saveConfig() is True - assert tstConf.loadConfig() is True - assert tstConf.guiIcons == "typicons_light" - - tstConf.guiIcons = "typicons_grey_light" - assert tstConf.saveConfig() is True - assert tstConf.loadConfig() is True - assert tstConf.guiIcons == "typicons_light" - - tstConf.guiIcons = origIcons - assert tstConf.saveConfig() - # Localisation # ============ diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index 0014a4da..3c93ad60 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -50,7 +50,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir): assert novelwriter.CONFIG.confPath == nwMinimal novelwriter.CONFIG.guiTheme = "default_dark" novelwriter.CONFIG.guiSyntax = "tomorrow_night_eighties" - novelwriter.CONFIG.guiIcons = "typicons_colour_dark" + novelwriter.CONFIG.guiIcons = "typicons_dark" novelwriter.CONFIG.guiFont = "Cantarell" novelwriter.CONFIG.guiFontSize = 11 novelwriter.CONFIG.confChanged = True