Have a unified list of themes

main
Bob Mottram 2020-05-28 10:11:21 +01:00
parent 559ce0262d
commit fa6905d850
2 changed files with 25 additions and 23 deletions

View File

@ -11,6 +11,15 @@ from utils import loadJson
from utils import saveJson from utils import saveJson
def getThemesList() -> []:
"""Returns the list of available themes
Note that these should be capitalized, since they're
also used to create the web interface dropdown list
and to lookup function names
"""
return ('Default', 'Light', 'Purple', 'Hacker', 'HighVis')
def setThemeInConfig(baseDir: str, name: str) -> bool: def setThemeInConfig(baseDir: str, name: str) -> bool:
configFilename = baseDir + '/config.json' configFilename = baseDir + '/config.json'
if not os.path.isfile(configFilename): if not os.path.isfile(configFilename):
@ -263,21 +272,18 @@ def setThemeLight(baseDir: str):
def setTheme(baseDir: str, name: str) -> bool: def setTheme(baseDir: str, name: str) -> bool:
result = False result = False
if name == 'purple':
setThemePurple(baseDir) themes = getThemesList()
for themeName in themes:
if name == themeName.lower():
themeFunctionName = setTheme + themeName
themeFunctionName(baseDir)
result = True result = True
elif name == 'light':
setThemeLight(baseDir) if not result:
result = True
elif name == 'hacker':
setThemeHacker(baseDir)
result = True
elif name == 'highvis':
setThemeHighVis(baseDir)
result = True
else:
# default # default
setThemeDefault(baseDir) setThemeDefault(baseDir)
result = True result = True
setCustomFont(baseDir) setCustomFont(baseDir)
return result return result

View File

@ -70,6 +70,7 @@ from happening import thisWeeksEventsCheck
from happening import getCalendarEvents from happening import getCalendarEvents
from happening import getTodaysEvents from happening import getTodaysEvents
from git import isGitPatch from git import isGitPatch
from theme import getThemesList
def getBlogAddress(actorJson: {}) -> str: def getBlogAddress(actorJson: {}) -> str:
@ -1151,20 +1152,15 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
'..." style="height:200px">' + moderators + '</textarea>' '..." style="height:200px">' + moderators + '</textarea>'
moderatorsStr += '</div>' moderatorsStr += '</div>'
themes = getThemesList()
themesDropdown = '<div class="container">' themesDropdown = '<div class="container">'
themesDropdown += ' <b>' + translate['Theme'] + '</b><br>' themesDropdown += ' <b>' + translate['Theme'] + '</b><br>'
themesDropdown += ' <select id="themeDropdown" ' + \ themesDropdown += ' <select id="themeDropdown" ' + \
'name="themeDropdown" class="theme">' 'name="themeDropdown" class="theme">'
themesDropdown += ' <option value="default">' + \ for themeName in themes:
translate['Default'] + '</option>' themesDropdown += ' <option value="' + \
themesDropdown += ' <option value="light">' + \ themeName.lower() + '">' + \
translate['Light'] + '</option>' translate[themeName] + '</option>'
themesDropdown += ' <option value="purple">' + \
translate['Purple'] + '</option>'
themesDropdown += ' <option value="hacker">' + \
translate['Hacker'] + '</option>'
themesDropdown += ' <option value="highvis">' + \
translate['HighVis'] + '</option>'
themesDropdown += ' </select><br>' themesDropdown += ' </select><br>'
if os.path.isfile(baseDir + '/fonts/custom.woff') or \ if os.path.isfile(baseDir + '/fonts/custom.woff') or \
os.path.isfile(baseDir + '/fonts/custom.woff2') or \ os.path.isfile(baseDir + '/fonts/custom.woff2') or \