Finished the code for icon themes

This commit is contained in:
Veronica K. B. Olsen
2020-05-14 18:38:41 +02:00
parent 0566df433b
commit 0eb4319fc1
12 changed files with 376 additions and 64 deletions
+26 -6
View File
@@ -58,7 +58,11 @@ class GuiConfigEditor(QDialog):
self.innerBox = QVBoxLayout()
self.setWindowTitle("Preferences")
self.guiDeco = self.theParent.theTheme.loadDecoration("settings",(64,64))
self.guiDeco = self.theParent.theTheme.loadDecoration("settings", (64,64))
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.outerBox.setSpacing(16)
self.setLayout(self.outerBox)
self.tabGeneral = GuiConfigEditGeneralTab(self.theParent)
self.tabLayout = GuiConfigEditLayoutTab(self.theParent)
@@ -72,10 +76,6 @@ class GuiConfigEditor(QDialog):
self.tabWidget.addTab(self.tabEditing, "Editing")
self.tabWidget.addTab(self.tabAutoRep, "Auto-Replace")
self.setLayout(self.outerBox)
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self._doClose)
@@ -169,6 +169,22 @@ class GuiConfigEditGeneralTab(QWidget):
"Changing this requires restarting %s." % nw.__package__
)
## Select Icon Theme
self.selectIcons = QComboBox()
self.selectIcons.setMinimumWidth(200)
self.theIcons = self.theTheme.theIcons.listThemes()
for iconDir, iconName in self.theIcons:
self.selectIcons.addItem(iconName, iconDir)
iconIdx = self.selectIcons.findData(self.mainConf.guiIcons)
if iconIdx != -1:
self.selectIcons.setCurrentIndex(iconIdx)
self.mainForm.addRow(
"Main icon theme",
self.selectIcons,
"Changing this requires restarting %s." % nw.__package__
)
## Syntax Highlighting
self.selectSyntax = QComboBox()
self.selectSyntax.setMinimumWidth(200)
@@ -181,7 +197,8 @@ class GuiConfigEditGeneralTab(QWidget):
self.mainForm.addRow(
"Syntax highlight theme",
self.selectSyntax
self.selectSyntax,
""
)
## Dark Icons
@@ -275,6 +292,7 @@ class GuiConfigEditGeneralTab(QWidget):
guiTheme = self.selectTheme.currentData()
guiSyntax = self.selectSyntax.currentData()
guiIcons = self.selectIcons.currentData()
guiDark = self.preferDarkIcons.isChecked()
showFullPath = self.showFullPath.isChecked()
autoSaveDoc = self.autoSaveDoc.value()
@@ -285,9 +303,11 @@ class GuiConfigEditGeneralTab(QWidget):
# Check if restart is needed
needsRestart |= self.mainConf.guiTheme != guiTheme
needsRestart |= self.mainConf.guiIcons != guiIcons
self.mainConf.guiTheme = guiTheme
self.mainConf.guiSyntax = guiSyntax
self.mainConf.guiIcons = guiIcons
self.mainConf.guiDark = guiDark
self.mainConf.showFullPath = showFullPath
self.mainConf.autoSaveDoc = autoSaveDoc
+1 -2
View File
@@ -60,11 +60,10 @@ class GuiItemEditor(QDialog):
nwLabels.CLASS_ICON[self.theItem.itemClass], (64,64)
)
)
self.setLayout(self.outerBox)
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.outerBox.setSpacing(16)
self.setLayout(self.outerBox)
self.mainGroup = QGroupBox("Item Settings")
self.mainForm = QFormLayout()
+14 -8
View File
@@ -52,12 +52,18 @@ class GuiProjectEditor(QDialog):
self.theParent = theParent
self.theProject = theProject
self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout()
self.setWindowTitle("Project Settings")
self.setLayout(self.outerBox)
self.outerBox = QHBoxLayout()
self.innerBox = QVBoxLayout()
self.guiDeco = self.theParent.theTheme.loadDecoration("settings",(64,64))
self.setWindowTitle("Project Settings")
self.guiDeco = QLabel()
self.guiDeco.setPixmap(
self.theParent.theTheme.getPixmap("cls_novel", (64,64))
)
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.outerBox.setSpacing(16)
self.setLayout(self.outerBox)
self.theProject.countStatus()
self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
@@ -71,9 +77,6 @@ class GuiProjectEditor(QDialog):
self.tabWidget.addTab(self.tabImport, "Importance")
self.tabWidget.addTab(self.tabReplace,"Auto-Replace")
self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop)
self.outerBox.addLayout(self.innerBox)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self._doSave)
self.buttonBox.rejected.connect(self._doClose)
@@ -363,6 +366,9 @@ class GuiProjectEditReplace(QWidget):
self.saveButton = QPushButton(self.theTheme.getIcon("done"),"")
self.addButton = QPushButton(self.theTheme.getIcon("add"),"")
self.delButton = QPushButton(self.theTheme.getIcon("remove"),"")
self.saveButton.setToolTip("Save entry")
self.addButton.setToolTip("Add new entry")
self.delButton.setToolTip("Delete selected entry")
self.editKey.setEnabled(False)
self.editKey.setMaxLength(40)
+47 -5
View File
@@ -29,7 +29,7 @@ import logging
import configparser
import nw
from os import path
from os import path, listdir
from PyQt5.QtCore import QSize
from PyQt5.QtSvg import QSvgWidget
@@ -90,8 +90,11 @@ class GuiIcons:
self.theParent = theParent
# Storage
self.qIcons = {}
self.themeMap = {}
self.qIcons = {}
self.themeMap = {}
self.themeList = []
self.fbackName = "fallback"
self.confName = "icons.conf"
# Icon Theme Path
self.iconPath = None
@@ -121,7 +124,7 @@ class GuiIcons:
if path.isdir(checkPath):
logger.debug("Loading icon theme '%s'" % self.mainConf.guiIcons)
self.iconPath = checkPath
self.confFile = path.join(checkPath, "icons.conf")
self.confFile = path.join(checkPath, self.confName)
else:
return False
@@ -170,7 +173,6 @@ class GuiIcons:
"""Load graphical decoration element based on the decoration
map. This function always returns a QSwgWidget.
"""
if decoKey not in self.DECO_MAP:
logger.error("Decoration with name '%s' does not exist" % decoKey)
return QSvgWidget()
@@ -209,6 +211,37 @@ class GuiIcons:
qIcon = self.getIcon(iconKey)
return qIcon.pixmap(iconSize[0], iconSize[1], QIcon.Normal)
def listThemes(self):
"""Scan the icons themes folder and list all themes.
"""
if self.themeList:
return self.themeList
confParser = configparser.ConfigParser()
for themeDir in listdir(self.mainConf.iconPath):
themePath = path.join(self.mainConf.iconPath, themeDir)
if not path.isdir(themePath) or themeDir == self.fbackName:
continue
themeConf = path.join(themePath, self.confName)
logger.verbose("Checking icon theme config for '%s'" % themeDir)
try:
confParser.read_file(open(themeConf, mode="r", encoding="utf8"))
except Exception as e:
self.theParent.makeAlert(["Could not load theme config file.",str(e)],nwAlert.ERROR)
continue
themeName = ""
if confParser.has_section("Main"):
if confParser.has_option("Main", "name"):
themeName = confParser.get("Main", "name")
logger.verbose("Theme name is '%s'" % themeName)
if themeName != "":
self.themeList.append((themeDir, themeName))
self.themeList = sorted(self.themeList, key=lambda x: x[1])
self.themeList.insert(0, ("default", "System Icons"))
return self.themeList
##
# Internal Functions
##
@@ -238,6 +271,15 @@ class GuiIcons:
logger.verbose("Loading icon '%s' from system theme" % iconKey)
return QIcon().fromTheme(self.ICON_MAP[iconKey][1])
# Finally. we check if we have a fallback icon
if self.mainConf.guiDark:
fbackIcon = path.join(self.mainConf.iconPath, self.fbackName, "%s-dark.svg" % iconKey)
else:
fbackIcon = path.join(self.mainConf.iconPath, self.fbackName, "%s.svg" % iconKey)
if path.isfile(fbackIcon):
logger.verbose("Loading icon '%s' from fallback theme" % iconKey)
return QIcon(fbackIcon)
# Give up and return an empty icon
logger.warning("Did not load an icon for '%s'" % iconKey)
+11 -7
View File
@@ -260,8 +260,9 @@ class GuiTheme:
return True
def listThemes(self):
if len(self.themeList) > 0:
"""Scan the gui themes folder and list all themes.
"""
if self.themeList:
return self.themeList
confParser = configparser.ConfigParser()
@@ -275,8 +276,9 @@ class GuiTheme:
continue
themeName = ""
if confParser.has_section("Main"):
themeName = confParser.get("Main","name")
logger.verbose("Theme name is '%s'" % themeName)
if confParser.has_option("Main", "name"):
themeName = confParser.get("Main", "name")
logger.verbose("Theme name is '%s'" % themeName)
if themeName != "":
self.themeList.append((themeDir, themeName))
@@ -285,8 +287,9 @@ class GuiTheme:
return self.themeList
def listSyntax(self):
if len(self.syntaxList) > 0:
"""Scan the syntax themes folder and list all themes.
"""
if self.syntaxList:
return self.syntaxList
confParser = configparser.ConfigParser()
@@ -303,7 +306,8 @@ class GuiTheme:
return []
syntaxName = ""
if confParser.has_section("Main"):
syntaxName = confParser.get("Main","name")
if confParser.has_option("Main", "name"):
syntaxName = confParser.get("Main", "name")
if len(syntaxFile) > 5 and syntaxName != "":
self.syntaxList.append((syntaxFile[:-5], syntaxName))
logger.verbose("Syntax name is '%s'" % syntaxName)