Added dark tomorrow theme and separated gui theme from syntax

This commit is contained in:
Veronica K. B. Olsen
2019-06-15 15:24:29 +02:00
parent 4cb42339ce
commit 583e10adec
15 changed files with 239 additions and 91 deletions
+93 -35
View File
@@ -24,39 +24,48 @@ class Theme:
def __init__(self, theParent):
self.mainConf = nw.CONFIG
self.theParent = theParent
self.cssName = "styles.css"
self.confName = "theme.conf"
self.themeList = []
self.mainConf = nw.CONFIG
self.theParent = theParent
self.guiPath = "gui"
self.syntaxPath = "syntax"
self.cssName = "styles.css"
self.confName = "theme.conf"
self.themeList = []
self.syntaxList = []
# Loaded Theme Settings
## Main
self.themeName = "No Name"
self.themeName = "No Name"
## Syntax
self.colText = [0,0,0]
self.colLink = [0,0,0]
self.colHead = [0,0,0]
self.colHeadH = [0,0,0]
self.colEmph = [0,0,0]
self.colDialN = [0,0,0]
self.colDialD = [0,0,0]
self.colDialS = [0,0,0]
self.colComm = [0,0,0]
self.colKey = [0,0,0]
self.colVal = [0,0,0]
self.colSpell = [0,0,0]
self.colTagErr = [0,0,0]
self.colRepTag = [0,0,0]
self.colText = [ 0, 0, 0]
self.colLink = [ 0, 0, 0]
self.colHead = [ 0, 0, 0]
self.colHeadH = [ 0, 0, 0]
self.colEmph = [ 0, 0, 0]
self.colDialN = [ 0, 0, 0]
self.colDialD = [ 0, 0, 0]
self.colDialS = [ 0, 0, 0]
self.colComm = [ 0, 0, 0]
self.colKey = [ 0, 0, 0]
self.colVal = [ 0, 0, 0]
self.colSpell = [ 0, 0, 0]
self.colTagErr = [ 0, 0, 0]
self.colRepTag = [ 0, 0, 0]
## GUI
self.treeWCount = [ 0, 0, 0]
self.statNone = [120,120,120]
self.statUnsaved = [120,120, 40]
self.statSaved = [ 40,120, 0]
# Changeable Settings
self.guiTheme = None
self.themePath = None
self.confFile = None
self.cssFile = None
self.cssData = ""
self.guiTheme = None
self.guiSyntax = None
self.themeRoot = None
self.cssFile = None
self.cssData = ""
self.updateTheme()
@@ -67,10 +76,20 @@ class Theme:
##
def updateTheme(self):
self.guiTheme = self.mainConf.guiTheme
self.themePath = path.join(self.mainConf.themePath, self.guiTheme)
self.confFile = path.join(self.themePath,self.confName)
self.cssFile = path.join(self.themePath,self.cssName)
self.guiTheme = self.mainConf.guiTheme
self.guiSyntax = self.mainConf.guiSyntax
self.themeRoot = self.mainConf.themeRoot
self.themePath = path.join(self.mainConf.themeRoot, self.guiPath, self.guiTheme)
self.syntaxFile = path.join(self.themeRoot,self.syntaxPath,self.guiSyntax+".conf")
self.confFile = path.join(self.themePath,self.confName)
self.cssFile = path.join(self.themePath,self.cssName)
print(self.guiSyntax)
self.loadTheme()
self.loadSyntax()
return True
def loadTheme(self):
@@ -86,12 +105,15 @@ class Theme:
logger.error("Could not load theme css file")
return False
# Color Config
return True
def loadSyntax(self):
confParser = configparser.ConfigParser()
try:
confParser.read_file(open(self.confFile))
confParser.read_file(open(self.syntaxFile))
except Exception as e:
logger.error("Could not load theme config file")
logger.error("Could not load syntax colours from: %s" % self.syntaxFile)
return False
## Main
@@ -117,6 +139,16 @@ class Theme:
self.colTagErr = self._loadColour(confParser,cnfSec,"tagerror")
self.colRepTag = self._loadColour(confParser,cnfSec,"replacetag")
## GUI
cnfSec = "GUI"
if confParser.has_section(cnfSec):
self.treeWCount = self._loadColour(confParser,cnfSec,"treewordcount")
self.statNone = self._loadColour(confParser,cnfSec,"statusnone")
self.statUnsaved = self._loadColour(confParser,cnfSec,"statusunsaved")
self.statSaved = self._loadColour(confParser,cnfSec,"statussaved")
logger.info("Loaded syntax colour theme '%s'" % self.guiSyntax)
return True
def listThemes(self):
@@ -125,14 +157,14 @@ class Theme:
return self.themeList
confParser = configparser.ConfigParser()
for themeDir in listdir(self.mainConf.themeRoot):
themeConf = path.join(self.mainConf.themeRoot, themeDir, self.confName)
for themeDir in listdir(path.join(self.mainConf.themeRoot, self.guiPath)):
themeConf = path.join(self.mainConf.themeRoot, self.guiPath, themeDir, self.confName)
logger.verbose("Checking theme config for '%s'" % themeDir)
try:
confParser.read_file(open(themeConf))
except Exception as e:
self.theParent.makeAlert(["Could not load theme config file",str(e)],nwAlert.ERROR)
return []
continue
themeName = ""
if confParser.has_section("Main"):
themeName = confParser.get("Main","name")
@@ -142,6 +174,32 @@ class Theme:
return self.themeList
def listSyntax(self):
if len(self.syntaxList) > 0:
return self.syntaxList
confParser = configparser.ConfigParser()
syntaxDir = path.join(self.mainConf.themeRoot, self.syntaxPath)
for syntaxFile in listdir(syntaxDir):
syntaxPath = path.join(syntaxDir, syntaxFile)
if not path.isfile(syntaxPath):
continue
logger.verbose("Checking theme syntax for '%s'" % syntaxFile)
try:
confParser.read_file(open(syntaxPath))
except Exception as e:
self.theParent.makeAlert(["Could not load syntax file",str(e)],nwAlert.ERROR)
return []
syntaxName = ""
if confParser.has_section("Main"):
syntaxName = confParser.get("Main","name")
if len(syntaxFile) > 5 and syntaxName != "":
self.syntaxList.append((syntaxFile[:-5], syntaxName))
logger.verbose("Syntax name is '%s'" % syntaxName)
return self.syntaxList
##
# Internal Functions
##