Remove icon setting from config, and let the theme control it

This commit is contained in:
Veronica Berglyd Olsen
2022-10-26 22:01:04 +02:00
parent 8d7ebefa65
commit c7999831c9
6 changed files with 24 additions and 51 deletions
-9
View File
@@ -73,7 +73,6 @@ class Config:
# General
self.guiTheme = "" # GUI theme
self.guiSyntax = "" # Syntax theme
self.guiIcons = "" # Icon theme
self.guiFont = "" # Defaults to system default font
self.guiFontSize = 11 # Is overridden if system default is loaded
self.guiScale = 1.0 # Set automatically by Theme class
@@ -81,7 +80,6 @@ class Config:
self.setDefaultGuiTheme()
self.setDefaultSyntaxTheme()
self.setDefaultIconTheme()
# Localisation
self.qLocal = QLocale.system()
@@ -410,7 +408,6 @@ class Config:
cnfSec = "Main"
self.guiTheme = theConf.rdStr(cnfSec, "theme", self.guiTheme)
self.guiSyntax = theConf.rdStr(cnfSec, "syntax", self.guiSyntax)
self.guiIcons = theConf.rdStr(cnfSec, "icons", self.guiIcons)
self.guiFont = theConf.rdStr(cnfSec, "guifont", self.guiFont)
self.guiFontSize = theConf.rdInt(cnfSec, "guifontsize", self.guiFontSize)
self.lastNotes = theConf.rdStr(cnfSec, "lastnotes", self.lastNotes)
@@ -523,7 +520,6 @@ class Config:
"timestamp": formatTimeStamp(time()),
"theme": str(self.guiTheme),
"syntax": str(self.guiSyntax),
"icons": str(self.guiIcons),
"guifont": str(self.guiFont),
"guifontsize": str(self.guiFontSize),
"lastnotes": str(self.lastNotes),
@@ -810,11 +806,6 @@ class Config:
"""
self.guiSyntax = "default_light"
def setDefaultIconTheme(self):
"""Reset the icon theme to default value.
"""
self.guiIcons = "typicons_light"
##
# Getters
##
+9 -1
View File
@@ -96,6 +96,7 @@ class GuiNovelView(QWidget):
"""Update theme elements.
"""
self.novelBar.updateTheme()
self.novelTree.updateTheme()
self.refreshTree()
return
@@ -408,7 +409,6 @@ class GuiNovelTree(QTreeWidget):
fH2.setBold(True)
self._hFonts = [self.font(), fH1, fH2, self.font(), self.font()]
self._pMore = self.mainTheme.loadDecoration("deco_doc_more", pxH=iPx)
# Connect signals
self.clicked.connect(self._treeItemClicked)
@@ -417,6 +417,7 @@ class GuiNovelTree(QTreeWidget):
# Set custom settings
self.initSettings()
self.updateTheme()
logger.debug("GuiNovelTree initialisation complete")
@@ -438,6 +439,13 @@ class GuiNovelTree(QTreeWidget):
return
def updateTheme(self):
"""Update theme elements.
"""
iPx = self.mainTheme.baseIconSize
self._pMore = self.mainTheme.loadDecoration("deco_doc_more", pxH=iPx)
return
##
# Properties
##
+10 -30
View File
@@ -220,7 +220,7 @@ class GuiTheme:
else:
self.cssFile = self.themeFile[:-5]+".css"
self.loadTheme()
self.iconCache.updateTheme()
self.iconCache.updateTheme(self.themeIcons)
# Update dependant colours
backCol = qApp.palette().window().color()
@@ -305,9 +305,6 @@ 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:
@@ -511,8 +508,7 @@ class GuiIcons:
self._confName = "icons.conf"
# Icon Theme Path
self._iconPath = os.path.join(self.mainConf.assetPath, "icons")
self._themePath = os.path.join(self._iconPath, "system")
self._iconPath = os.path.join(self.mainConf.assetPath, "icons")
# Icon Theme Meta
self.themeName = ""
@@ -529,20 +525,19 @@ class GuiIcons:
# Actions
##
def updateTheme(self):
def updateTheme(self, iconTheme):
"""Update the theme map. This is more of an init, since many of
the GUI icons cannot really be replaced without writing specific
update functions for the classes where they're used.
"""
self._themeMap = {}
themePath = self._getThemePath()
if themePath is None:
logger.warning("No icons loaded")
themePath = os.path.join(self.mainConf.assetPath, "icons", iconTheme)
if not os.path.isdir(themePath):
logger.warning("No icons loaded for '%s'", iconTheme)
return False
self._themePath = themePath
themeConf = os.path.join(themePath, self._confName)
logger.info("Loading icon theme '%s'", self.mainConf.guiIcons)
logger.info("Loading icon theme '%s'", iconTheme)
# Config File
confParser = NWConfigParser()
@@ -572,7 +567,7 @@ class GuiIcons:
if iconName not in self.ICON_KEYS:
logger.error("Unknown icon name '%s' in config file", iconName)
else:
iconPath = os.path.join(self._themePath, iconFile)
iconPath = os.path.join(themePath, iconFile)
if os.path.isfile(iconPath):
self._themeMap[iconName] = iconPath
logger.debug("Icon slot '%s' using file '%s'", iconName, iconFile)
@@ -594,6 +589,8 @@ class GuiIcons:
qIcon = self._loadIcon(iconKey)
self._qIcons[iconKey] = qIcon
self._headerDec = []
return True
##
@@ -692,23 +689,6 @@ class GuiIcons:
# Internal Functions
##
def _getThemePath(self):
"""Get a valid theme path. Returns None if it fails.
"""
themePath = os.path.join(self.mainConf.assetPath, "icons", self.mainConf.guiIcons)
if not os.path.isdir(themePath):
logger.warning(
"Icon theme '%s' not found, resetting to default", self.mainConf.guiIcons
)
self.mainConf.setDefaultIconTheme()
themePath = os.path.join(self.mainConf.assetPath, "icons", self.mainConf.guiIcons)
if not os.path.isdir(themePath):
logger.error("Default icon theme not found")
return None
return themePath
def _loadIcon(self, iconKey):
"""Load an icon from the assets themes folder. Is guaranteed to
return a QIcon.
+1 -2
View File
@@ -1,8 +1,7 @@
[Main]
timestamp = 2021-12-31 16:45:32
timestamp = 2022-10-26 11:19:49
theme = default
syntax = default_light
icons = typicons_light
guifont =
guifontsize = 11
lastnotes = 0x0
@@ -1,9 +1,8 @@
[Main]
timestamp = 2021-12-31 16:45:34
timestamp = 2022-10-26 11:19:51
theme = default
syntax = default_light
icons = typicons_light
guifont = Sans
guifont = Cantarell
guifontsize = 12
lastnotes = 0x0
guilang = en_GB
@@ -12,7 +11,7 @@ hidehscroll = True
[Sizes]
geometry = 1200, 650
preferences = 670, 589
preferences = 699, 614
projcols = 200, 60, 140
mainpane = 300, 800
docpane = 400, 400
+1 -5
View File
@@ -50,7 +50,6 @@ 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_dark"
novelwriter.CONFIG.guiFont = "Cantarell"
novelwriter.CONFIG.guiFontSize = 11
novelwriter.CONFIG.confChanged = True
@@ -72,7 +71,6 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir):
assert novelwriter.CONFIG.guiTheme == "default_dark"
assert novelwriter.CONFIG.guiSyntax == "tomorrow_night_eighties"
assert novelwriter.CONFIG.guiIcons == "typicons_dark"
assert novelwriter.CONFIG.guiFont != ""
assert novelwriter.CONFIG.guiFontSize > 0
@@ -117,9 +115,7 @@ def testGuiTheme_Main(qtbot, monkeypatch, nwMinimal, tmpDir):
# Test Icon class
iconCache = nwGUI.mainTheme.iconCache
novelwriter.CONFIG.guiIcons = "invalid"
assert iconCache.updateTheme() is True
assert novelwriter.CONFIG.guiIcons == "typicons_light"
assert iconCache.updateTheme("invalid") is False
# Ask for a non-existent key
anImg = iconCache.loadDecoration("nonsense", 20, 20)