Load all icons via the theme class

This commit is contained in:
Veronica K. B. Olsen
2019-10-06 18:36:19 +02:00
parent 052272938c
commit 10bd5049bc
5 changed files with 49 additions and 16 deletions
+4 -3
View File
@@ -113,6 +113,7 @@ class GuiConfigEditGeneral(QWidget):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theTheme = theParent.theTheme
self.outerBox = QGridLayout() self.outerBox = QGridLayout()
# User Interface # User Interface
@@ -122,7 +123,7 @@ class GuiConfigEditGeneral(QWidget):
self.guiLookTheme = QComboBox() self.guiLookTheme = QComboBox()
self.guiLookTheme.setMinimumWidth(200) self.guiLookTheme.setMinimumWidth(200)
self.theThemes = self.theParent.theTheme.listThemes() self.theThemes = self.theTheme.listThemes()
for themeDir, themeName in self.theThemes: for themeDir, themeName in self.theThemes:
self.guiLookTheme.addItem(themeName, themeDir) self.guiLookTheme.addItem(themeName, themeDir)
themeIdx = self.guiLookTheme.findData(self.mainConf.guiTheme) themeIdx = self.guiLookTheme.findData(self.mainConf.guiTheme)
@@ -131,7 +132,7 @@ class GuiConfigEditGeneral(QWidget):
self.guiLookSyntax = QComboBox() self.guiLookSyntax = QComboBox()
self.guiLookSyntax.setMinimumWidth(200) self.guiLookSyntax.setMinimumWidth(200)
self.theSyntaxes = self.theParent.theTheme.listSyntax() self.theSyntaxes = self.theTheme.listSyntax()
for syntaxFile, syntaxName in self.theSyntaxes: for syntaxFile, syntaxName in self.theSyntaxes:
self.guiLookSyntax.addItem(syntaxName, syntaxFile) self.guiLookSyntax.addItem(syntaxName, syntaxFile)
syntaxIdx = self.guiLookSyntax.findData(self.mainConf.guiSyntax) syntaxIdx = self.guiLookSyntax.findData(self.mainConf.guiSyntax)
@@ -192,7 +193,7 @@ class GuiConfigEditGeneral(QWidget):
if path.isdir(self.mainConf.backupPath): if path.isdir(self.mainConf.backupPath):
self.projBackupPath.setText(self.mainConf.backupPath) self.projBackupPath.setText(self.mainConf.backupPath)
self.projBackupGetPath = QPushButton(QIcon.fromTheme("folder"),"") self.projBackupGetPath = QPushButton(self.theTheme.getIcon("folder"),"")
self.projBackupGetPath.clicked.connect(self._backupFolder) self.projBackupGetPath.clicked.connect(self._backupFolder)
self.projBackupClose = QCheckBox(self) self.projBackupClose = QCheckBox(self)
+6 -5
View File
@@ -37,6 +37,7 @@ class GuiDocTree(QTreeWidget):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.debugGUI = self.mainConf.debugGUI self.debugGUI = self.mainConf.debugGUI
self.theParent = theParent self.theParent = theParent
self.theTheme = theParent.theTheme
self.theProject = theProject self.theProject = theProject
# Tree Settings # Tree Settings
@@ -382,13 +383,13 @@ class GuiDocTree(QTreeWidget):
newItem.setExpanded(nwItem.isExpanded) newItem.setExpanded(nwItem.isExpanded)
if nwItem.itemType == nwItemType.ROOT: if nwItem.itemType == nwItemType.ROOT:
newItem.setIcon(self.C_NAME, QIcon.fromTheme("drive-harddisk")) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("root"))
elif nwItem.itemType == nwItemType.FOLDER: elif nwItem.itemType == nwItemType.FOLDER:
newItem.setIcon(self.C_NAME, QIcon.fromTheme("folder")) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("folder"))
elif nwItem.itemType == nwItemType.FILE: elif nwItem.itemType == nwItemType.FILE:
newItem.setIcon(self.C_NAME, QIcon.fromTheme("x-office-document")) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("document"))
elif nwItem.itemType == nwItemType.TRASH: elif nwItem.itemType == nwItemType.TRASH:
newItem.setIcon(self.C_NAME, QIcon.fromTheme("user-trash")) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("trash"))
return newItem return newItem
@@ -413,7 +414,7 @@ class GuiDocTree(QTreeWidget):
self.addTopLevelItem(newItem) self.addTopLevelItem(newItem)
self.orphRoot = newItem self.orphRoot = newItem
newItem.setExpanded(True) newItem.setExpanded(True)
newItem.setIcon(self.C_NAME, QIcon.fromTheme("dialog-warning")) newItem.setIcon(self.C_NAME, self.theTheme.getIcon("orphan"))
return return
def _cleanOrphanedRoot(self): def _cleanOrphanedRoot(self):
+4 -3
View File
@@ -322,6 +322,7 @@ class GuiProjectEditReplace(QWidget):
QWidget.__init__(self, theParent) QWidget.__init__(self, theParent)
self.theParent = theParent self.theParent = theParent
self.theTheme = theParent.theTheme
self.theProject = theProject self.theProject = theProject
self.arChanged = False self.arChanged = False
@@ -341,9 +342,9 @@ class GuiProjectEditReplace(QWidget):
self.editKey = QLineEdit() self.editKey = QLineEdit()
self.editValue = QLineEdit() self.editValue = QLineEdit()
self.saveButton = QPushButton(QIcon.fromTheme("document-save"),"") self.saveButton = QPushButton(self.theTheme.getIcon("save"),"")
self.addButton = QPushButton(QIcon.fromTheme("list-add"),"") self.addButton = QPushButton(self.theTheme.getIcon("add"),"")
self.delButton = QPushButton(QIcon.fromTheme("list-remove"),"") self.delButton = QPushButton(self.theTheme.getIcon("remove"),"")
self.editKey.setEnabled(False) self.editKey.setEnabled(False)
self.editValue.setEnabled(False) self.editValue.setEnabled(False)
+4 -3
View File
@@ -30,6 +30,7 @@ class GuiSearchBar(QFrame):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.theTheme = theParent.theTheme
self.repVisible = False self.repVisible = False
self.setContentsMargins(0,0,0,0) self.setContentsMargins(0,0,0,0)
@@ -41,9 +42,9 @@ class GuiSearchBar(QFrame):
self.replaceBox = QLineEdit() self.replaceBox = QLineEdit()
self.searchLabel = QLabel("Search") self.searchLabel = QLabel("Search")
self.replaceLabel = QLabel("Replace") self.replaceLabel = QLabel("Replace")
self.closeButton = QPushButton(QIcon.fromTheme("edit-delete"),"") self.closeButton = QPushButton(self.theTheme.getIcon("close"),"")
self.searchButton = QPushButton(QIcon.fromTheme("edit-find"),"") self.searchButton = QPushButton(self.theTheme.getIcon("search"),"")
self.replaceButton = QPushButton(QIcon.fromTheme("edit-find-replace"),"") self.replaceButton = QPushButton(self.theTheme.getIcon("replace"),"")
self.closeButton.clicked.connect(self._doClose) self.closeButton.clicked.connect(self._doClose)
self.searchButton.clicked.connect(self._doSearch) self.searchButton.clicked.connect(self._doSearch)
+31 -2
View File
@@ -17,7 +17,7 @@ import nw
from os import path, listdir from os import path, listdir
from PyQt5.QtWidgets import qApp from PyQt5.QtWidgets import qApp
from PyQt5.QtGui import QPalette, QColor from PyQt5.QtGui import QPalette, QColor, QIcon
from nw.enum import nwAlert from nw.enum import nwAlert
@@ -25,12 +25,27 @@ logger = logging.getLogger(__name__)
class Theme: class Theme:
ICON_MAP = {
"root" : "drive-harddisk",
"folder" : "folder",
"document" : "x-office-document",
"trash" : "user-trash",
"orphan" : "dialog-warning",
"save" : "document-save",
"add" : "list-add",
"remove" : "list-remove",
"close" : "edit-delete",
"search" : "edit-find",
"replace" : "edit-find-replace",
}
def __init__(self, theParent): def __init__(self, theParent):
self.mainConf = nw.CONFIG self.mainConf = nw.CONFIG
self.theParent = theParent self.theParent = theParent
self.guiPalette = QPalette() self.guiPalette = QPalette()
self.guiPath = "gui" self.guiPath = "gui"
self.iconPath = "icons"
self.syntaxPath = "syntax" self.syntaxPath = "syntax"
self.cssName = "style.qss" self.cssName = "style.qss"
self.confName = "theme.conf" self.confName = "theme.conf"
@@ -76,10 +91,16 @@ class Theme:
self.colTagErr = [ 0, 0, 0] self.colTagErr = [ 0, 0, 0]
self.colRepTag = [ 0, 0, 0] self.colRepTag = [ 0, 0, 0]
## Icons
self.themeIcons = {}
# Changeable Settings # Changeable Settings
self.guiTheme = None self.guiTheme = None
self.guiSyntax = None self.guiSyntax = None
self.themeRoot = None self.themeRoot = None
self.themePath = None
self.syntaxFile = None
self.confFile = None
self.cssFile = None self.cssFile = None
self.updateTheme() self.updateTheme()
@@ -95,11 +116,14 @@ class Theme:
self.guiTheme = self.mainConf.guiTheme self.guiTheme = self.mainConf.guiTheme
self.guiSyntax = self.mainConf.guiSyntax self.guiSyntax = self.mainConf.guiSyntax
self.themeRoot = self.mainConf.themeRoot self.themeRoot = self.mainConf.themeRoot
self.themePath = path.join(self.mainConf.themeRoot, self.guiPath, self.guiTheme) self.themePath = path.join(self.mainConf.themeRoot,self.guiPath,self.guiTheme)
self.syntaxFile = path.join(self.themeRoot,self.syntaxPath,self.guiSyntax+".conf") self.syntaxFile = path.join(self.themeRoot,self.syntaxPath,self.guiSyntax+".conf")
self.confFile = path.join(self.themePath,self.confName) self.confFile = path.join(self.themePath,self.confName)
self.cssFile = path.join(self.themePath,self.cssName) self.cssFile = path.join(self.themePath,self.cssName)
for iconName in self.ICON_MAP:
self.themeIcons[iconName] = QIcon.fromTheme(self.ICON_MAP[iconName])
self.loadTheme() self.loadTheme()
self.loadSyntax() self.loadSyntax()
@@ -262,6 +286,11 @@ class Theme:
return self.syntaxList return self.syntaxList
def getIcon(self, iconName, iconSize=None):
if iconName in self.themeIcons:
return self.themeIcons[iconName]
return QIcon()
## ##
# Internal Functions # Internal Functions
## ##