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