Add icon theme selector to Preferences

This commit is contained in:
Veronica Berglyd Olsen
2025-01-08 02:09:22 +01:00
parent 24eb99cdaa
commit 5650792be8
2 changed files with 34 additions and 3 deletions
+16 -1
View File
@@ -173,7 +173,19 @@ class GuiPreferences(NDialog):
self.mainForm.addRow( self.mainForm.addRow(
self.tr("Colour theme"), self.guiTheme, self.tr("Colour theme"), self.guiTheme,
self.tr("General colour theme and icons."), stretch=(3, 2) self.tr("User interface colour theme."), stretch=(3, 2)
)
# Icon Theme
self.guiIcons = NComboBox(self)
self.guiIcons.setMinimumWidth(minWidth)
for theme, name in SHARED.theme.iconCache.listThemes():
self.guiIcons.addItem(name, theme)
self.guiIcons.setCurrentData(CONFIG.guiIcons, "material_rounded_bold")
self.mainForm.addRow(
self.tr("Icon theme"), self.guiIcons,
self.tr("User interface icon theme."), stretch=(3, 2)
) )
# Application Font Family # Application Font Family
@@ -902,13 +914,16 @@ class GuiPreferences(NDialog):
# Appearance # Appearance
guiLocale = self.guiLocale.currentData() guiLocale = self.guiLocale.currentData()
guiTheme = self.guiTheme.currentData() guiTheme = self.guiTheme.currentData()
guiIcons = self.guiIcons.currentData()
updateTheme |= CONFIG.guiTheme != guiTheme updateTheme |= CONFIG.guiTheme != guiTheme
updateTheme |= CONFIG.guiIcons != guiIcons
needsRestart |= CONFIG.guiLocale != guiLocale needsRestart |= CONFIG.guiLocale != guiLocale
needsRestart |= CONFIG.guiFont != self._guiFont needsRestart |= CONFIG.guiFont != self._guiFont
CONFIG.guiLocale = guiLocale CONFIG.guiLocale = guiLocale
CONFIG.guiTheme = guiTheme CONFIG.guiTheme = guiTheme
CONFIG.guiIcons = guiIcons
CONFIG.hideVScroll = self.hideVScroll.isChecked() CONFIG.hideVScroll = self.hideVScroll.isChecked()
CONFIG.hideHScroll = self.hideHScroll.isChecked() CONFIG.hideHScroll = self.hideHScroll.isChecked()
CONFIG.nativeFont = self.nativeFont.isChecked() CONFIG.nativeFont = self.nativeFont.isChecked()
+18 -2
View File
@@ -443,8 +443,9 @@ class GuiTheme:
"""Parse a colour value from a config string.""" """Parse a colour value from a config string."""
return QColor(*parser.rdIntList(section, name, [0, 0, 0, 255])) return QColor(*parser.rdIntList(section, name, [0, 0, 0, 255]))
def _setPalette(self, parser: NWConfigParser, section: str, def _setPalette(
name: str, value: QPalette.ColorRole) -> None: self, parser: NWConfigParser, section: str, name: str, value: QPalette.ColorRole
) -> None:
"""Set a palette colour value from a config string.""" """Set a palette colour value from a config string."""
self._guiPalette.setColor(value, self._parseColour(parser, section, name)) self._guiPalette.setColor(value, self._parseColour(parser, section, name))
return return
@@ -515,6 +516,7 @@ class GuiIcons:
self._headerDecNarrow: list[QPixmap] = [] self._headerDecNarrow: list[QPixmap] = []
# Icon Theme Path # Icon Theme Path
self._themeList: list[tuple[str, str]] = []
self._iconPath = CONFIG.assetPath("icons") self._iconPath = CONFIG.assetPath("icons")
# None Icon # None Icon
@@ -692,6 +694,20 @@ class GuiIcons:
] ]
return self._headerDecNarrow[minmax(hLevel, 0, 5)] return self._headerDecNarrow[minmax(hLevel, 0, 5)]
def listThemes(self) -> list[tuple[str, str]]:
"""Scan the GUI icons folder and list all themes."""
if self._themeList:
return self._themeList
for item in self._iconPath.iterdir():
if item.is_file() and item.suffix == ".icons":
if name := _loadIconName(item):
self._themeList.append((item.stem, name))
self._themeList = sorted(self._themeList, key=_sortTheme)
return self._themeList
## ##
# Internal Functions # Internal Functions
## ##