mirror of https://gitlab.com/bashrc2/epicyon
flake8 format
parent
a0930a61b8
commit
02ce4e3d14
119
theme.py
119
theme.py
|
@ -1,87 +1,96 @@
|
||||||
__filename__="theme.py"
|
__filename__ = "theme.py"
|
||||||
__author__="Bob Mottram"
|
__author__ = "Bob Mottram"
|
||||||
__license__="AGPL3+"
|
__license__ = "AGPL3+"
|
||||||
__version__="1.1.0"
|
__version__ = "1.1.0"
|
||||||
__maintainer__="Bob Mottram"
|
__maintainer__ = "Bob Mottram"
|
||||||
__email__="bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__="Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
|
|
||||||
def setThemeInConfig(baseDir: str,name: str) -> bool:
|
|
||||||
configFilename=baseDir+'/config.json'
|
def setThemeInConfig(baseDir: str, name: str) -> bool:
|
||||||
|
configFilename = baseDir + '/config.json'
|
||||||
if not os.path.isfile(configFilename):
|
if not os.path.isfile(configFilename):
|
||||||
return False
|
return False
|
||||||
configJson=loadJson(configFilename,0)
|
configJson = loadJson(configFilename, 0)
|
||||||
if not configJson:
|
if not configJson:
|
||||||
return False
|
return False
|
||||||
configJson['theme']=name
|
configJson['theme'] = name
|
||||||
return saveJson(configJson,configFilename)
|
return saveJson(configJson, configFilename)
|
||||||
|
|
||||||
|
|
||||||
def removeTheme(baseDir: str):
|
def removeTheme(baseDir: str):
|
||||||
themeFiles=('epicyon.css','login.css','follow.css','suspended.css','calendar.css','blog.css')
|
themeFiles = ('epicyon.css', 'login.css', 'follow.css',
|
||||||
|
'suspended.css', 'calendar.css', 'blog.css')
|
||||||
for filename in themeFiles:
|
for filename in themeFiles:
|
||||||
if os.path.isfile(baseDir+'/'+filename):
|
if os.path.isfile(baseDir + '/' + filename):
|
||||||
os.remove(baseDir+'/'+filename)
|
os.remove(baseDir + '/' + filename)
|
||||||
|
|
||||||
|
|
||||||
def setThemeDefault(baseDir: str):
|
def setThemeDefault(baseDir: str):
|
||||||
removeTheme(baseDir)
|
removeTheme(baseDir)
|
||||||
setThemeInConfig(baseDir,'default')
|
setThemeInConfig(baseDir, 'default')
|
||||||
|
|
||||||
def setCSSparam(css: str,param: str,value: str) -> str:
|
|
||||||
|
def setCSSparam(css: str, param: str, value: str) -> str:
|
||||||
"""Sets a CSS parameter to a given value
|
"""Sets a CSS parameter to a given value
|
||||||
"""
|
"""
|
||||||
# is this just a simple string replacement?
|
# is this just a simple string replacement?
|
||||||
if ';' in param:
|
if ';' in param:
|
||||||
return css.replace(param,value)
|
return css.replace(param, value)
|
||||||
# color replacement
|
# color replacement
|
||||||
if param.startswith('rgba('):
|
if param.startswith('rgba('):
|
||||||
return css.replace(param,value)
|
return css.replace(param, value)
|
||||||
# if the parameter begins with * then don't prepend --
|
# if the parameter begins with * then don't prepend --
|
||||||
if param.startswith('*'):
|
if param.startswith('*'):
|
||||||
searchStr=param.replace('*','')+':'
|
searchStr = param.replace('*', '') + ':'
|
||||||
else:
|
else:
|
||||||
searchStr='--'+param+':'
|
searchStr = '--' + param + ':'
|
||||||
if searchStr not in css:
|
if searchStr not in css:
|
||||||
return css
|
return css
|
||||||
s=css.split(searchStr)
|
s = css.split(searchStr)
|
||||||
newcss=''
|
newcss = ''
|
||||||
for sectionStr in s:
|
for sectionStr in s:
|
||||||
if not newcss:
|
if not newcss:
|
||||||
if sectionStr:
|
if sectionStr:
|
||||||
newcss=sectionStr
|
newcss = sectionStr
|
||||||
else:
|
else:
|
||||||
newcss=' '
|
newcss = ' '
|
||||||
else:
|
else:
|
||||||
if ';' in sectionStr:
|
if ';' in sectionStr:
|
||||||
newcss+=searchStr+' '+value+';'+sectionStr.split(';',1)[1]
|
newcss += \
|
||||||
|
searchStr + ' ' + value + ';' + sectionStr.split(';', 1)[1]
|
||||||
else:
|
else:
|
||||||
newcss+=searchStr+' '+sectionStr
|
newcss += searchStr + ' ' + sectionStr
|
||||||
return newcss.strip()
|
return newcss.strip()
|
||||||
|
|
||||||
def setThemeFromDict(baseDir: str,name: str,themeParams: {}):
|
|
||||||
|
def setThemeFromDict(baseDir: str, name: str, themeParams: {}):
|
||||||
"""Uses a dictionary to set a theme
|
"""Uses a dictionary to set a theme
|
||||||
"""
|
"""
|
||||||
setThemeInConfig(baseDir,name)
|
setThemeInConfig(baseDir, name)
|
||||||
themeFiles=('epicyon.css','login.css','follow.css','suspended.css','calendar.css','blog.css')
|
themeFiles = ('epicyon.css', 'login.css', 'follow.css',
|
||||||
|
'suspended.css', 'calendar.css', 'blog.css')
|
||||||
for filename in themeFiles:
|
for filename in themeFiles:
|
||||||
templateFilename=baseDir+'/epicyon-'+filename
|
templateFilename = baseDir + '/epicyon-' + filename
|
||||||
if filename=='epicyon.css':
|
if filename == 'epicyon.css':
|
||||||
templateFilename=baseDir+'/epicyon-profile.css'
|
templateFilename = baseDir + '/epicyon-profile.css'
|
||||||
if not os.path.isfile(templateFilename):
|
if not os.path.isfile(templateFilename):
|
||||||
continue
|
continue
|
||||||
with open(templateFilename, 'r') as cssfile:
|
with open(templateFilename, 'r') as cssfile:
|
||||||
css=cssfile.read()
|
css = cssfile.read()
|
||||||
for paramName,paramValue in themeParams.items():
|
for paramName, paramValue in themeParams.items():
|
||||||
css=setCSSparam(css,paramName,paramValue)
|
css = setCSSparam(css, paramName, paramValue)
|
||||||
filename=baseDir+'/'+filename
|
filename = baseDir + '/' + filename
|
||||||
with open(filename, 'w') as cssfile:
|
with open(filename, 'w') as cssfile:
|
||||||
cssfile.write(css)
|
cssfile.write(css)
|
||||||
|
|
||||||
|
|
||||||
def setThemeHighVis(baseDir: str):
|
def setThemeHighVis(baseDir: str):
|
||||||
themeParams={
|
themeParams = {
|
||||||
"font-size-header": "22px",
|
"font-size-header": "22px",
|
||||||
"font-size": "45px",
|
"font-size": "45px",
|
||||||
"font-size2": "45px",
|
"font-size2": "45px",
|
||||||
|
@ -91,10 +100,11 @@ def setThemeHighVis(baseDir: str):
|
||||||
"gallery-font-size": "35px",
|
"gallery-font-size": "35px",
|
||||||
"gallery-font-size-mobile": "55px"
|
"gallery-font-size-mobile": "55px"
|
||||||
}
|
}
|
||||||
setThemeFromDict(baseDir,'highvis',themeParams)
|
setThemeFromDict(baseDir, 'highvis', themeParams)
|
||||||
|
|
||||||
|
|
||||||
def setThemePurple(baseDir: str):
|
def setThemePurple(baseDir: str):
|
||||||
themeParams={
|
themeParams = {
|
||||||
"main-bg-color": "#1f152d",
|
"main-bg-color": "#1f152d",
|
||||||
"main-bg-color-reply": "#1a142d",
|
"main-bg-color-reply": "#1a142d",
|
||||||
"main-bg-color-report": "#12152d",
|
"main-bg-color-report": "#12152d",
|
||||||
|
@ -103,7 +113,6 @@ def setThemePurple(baseDir: str):
|
||||||
"border-color": "#3f2145",
|
"border-color": "#3f2145",
|
||||||
"main-link-color": "#ff42a0",
|
"main-link-color": "#ff42a0",
|
||||||
"main-visited-color": "#f93bb0",
|
"main-visited-color": "#f93bb0",
|
||||||
"time-color": "#f98bb0",
|
|
||||||
"button-selected": "#c042a0",
|
"button-selected": "#c042a0",
|
||||||
"button-background": "#ff42a0",
|
"button-background": "#ff42a0",
|
||||||
"button-text": "white",
|
"button-text": "white",
|
||||||
|
@ -124,10 +133,11 @@ def setThemePurple(baseDir: str):
|
||||||
"title-background": "#ff42a0",
|
"title-background": "#ff42a0",
|
||||||
"gallery-text-color": "#ccc"
|
"gallery-text-color": "#ccc"
|
||||||
}
|
}
|
||||||
setThemeFromDict(baseDir,'purple',themeParams)
|
setThemeFromDict(baseDir, 'purple', themeParams)
|
||||||
|
|
||||||
|
|
||||||
def setThemeHacker(baseDir: str):
|
def setThemeHacker(baseDir: str):
|
||||||
themeParams={
|
themeParams = {
|
||||||
"main-bg-color": "black",
|
"main-bg-color": "black",
|
||||||
"main-bg-color-reply": "#030202",
|
"main-bg-color-reply": "#030202",
|
||||||
"main-bg-color-report": "#050202",
|
"main-bg-color-report": "#050202",
|
||||||
|
@ -136,7 +146,6 @@ def setThemeHacker(baseDir: str):
|
||||||
"border-color": "darkgreen",
|
"border-color": "darkgreen",
|
||||||
"main-link-color": "#266020",
|
"main-link-color": "#266020",
|
||||||
"main-visited-color": "#3c8234",
|
"main-visited-color": "#3c8234",
|
||||||
"time-color": "green",
|
|
||||||
"button-selected": "#063200",
|
"button-selected": "#063200",
|
||||||
"button-background": "#062200",
|
"button-background": "#062200",
|
||||||
"button-text": "green",
|
"button-text": "green",
|
||||||
|
@ -160,10 +169,11 @@ def setThemeHacker(baseDir: str):
|
||||||
"title-background": "darkgreen",
|
"title-background": "darkgreen",
|
||||||
"gallery-text-color": "green"
|
"gallery-text-color": "green"
|
||||||
}
|
}
|
||||||
setThemeFromDict(baseDir,'hacker',themeParams)
|
setThemeFromDict(baseDir, 'hacker', themeParams)
|
||||||
|
|
||||||
|
|
||||||
def setThemeLight(baseDir: str):
|
def setThemeLight(baseDir: str):
|
||||||
themeParams={
|
themeParams = {
|
||||||
"rgba(0, 0, 0, 0.5)": "rgba(0, 0, 0, 0.0)",
|
"rgba(0, 0, 0, 0.5)": "rgba(0, 0, 0, 0.0)",
|
||||||
"main-bg-color": "#e6ebf0",
|
"main-bg-color": "#e6ebf0",
|
||||||
"main-bg-color-reply": "#e0dbf0",
|
"main-bg-color-reply": "#e0dbf0",
|
||||||
|
@ -173,7 +183,6 @@ def setThemeLight(baseDir: str):
|
||||||
"border-color": "#c0cdd9",
|
"border-color": "#c0cdd9",
|
||||||
"main-link-color": "#2a2c37",
|
"main-link-color": "#2a2c37",
|
||||||
"main-visited-color": "#232c37",
|
"main-visited-color": "#232c37",
|
||||||
"time-color": "#555",
|
|
||||||
"text-entry-foreground": "#111",
|
"text-entry-foreground": "#111",
|
||||||
"text-entry-background": "white",
|
"text-entry-background": "white",
|
||||||
"font-color-header": "black",
|
"font-color-header": "black",
|
||||||
|
@ -185,7 +194,6 @@ def setThemeLight(baseDir: str):
|
||||||
"lines-color": "darkblue",
|
"lines-color": "darkblue",
|
||||||
"day-number": "black",
|
"day-number": "black",
|
||||||
"day-number2": "#282c37",
|
"day-number2": "#282c37",
|
||||||
"time-color": "black",
|
|
||||||
"place-color": "black",
|
"place-color": "black",
|
||||||
"event-color": "#282c37",
|
"event-color": "#282c37",
|
||||||
"today-foreground": "white",
|
"today-foreground": "white",
|
||||||
|
@ -196,22 +204,23 @@ def setThemeLight(baseDir: str):
|
||||||
"title-background": "#ccc",
|
"title-background": "#ccc",
|
||||||
"gallery-text-color": "black"
|
"gallery-text-color": "black"
|
||||||
}
|
}
|
||||||
setThemeFromDict(baseDir,'light',themeParams)
|
setThemeFromDict(baseDir, 'light', themeParams)
|
||||||
|
|
||||||
def setTheme(baseDir: str,name: str) -> bool:
|
|
||||||
if name=='default':
|
def setTheme(baseDir: str, name: str) -> bool:
|
||||||
|
if name == 'default':
|
||||||
setThemeDefault(baseDir)
|
setThemeDefault(baseDir)
|
||||||
return True
|
return True
|
||||||
elif name=='purple':
|
elif name == 'purple':
|
||||||
setThemePurple(baseDir)
|
setThemePurple(baseDir)
|
||||||
return True
|
return True
|
||||||
elif name=='light':
|
elif name == 'light':
|
||||||
setThemeLight(baseDir)
|
setThemeLight(baseDir)
|
||||||
return True
|
return True
|
||||||
elif name=='hacker':
|
elif name == 'hacker':
|
||||||
setThemeHacker(baseDir)
|
setThemeHacker(baseDir)
|
||||||
return True
|
return True
|
||||||
elif name=='highvis':
|
elif name == 'highvis':
|
||||||
setThemeHighVis(baseDir)
|
setThemeHighVis(baseDir)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue