forked from indymedia/epicyon
Themes can contain custom fonts
parent
f8706d4bbc
commit
f12b52165a
60
theme.py
60
theme.py
|
@ -27,7 +27,8 @@ def getThemesList(baseDir: str) -> []:
|
|||
themes = []
|
||||
for subdir, dirs, files in os.walk(baseDir + '/theme'):
|
||||
for themeName in dirs:
|
||||
if '~' not in themeName and themeName != 'icons':
|
||||
if '~' not in themeName and \
|
||||
themeName != 'icons' and themeName != 'fonts':
|
||||
themes.append(themeName.title())
|
||||
break
|
||||
print('Themes available: ' + str(themes))
|
||||
|
@ -411,34 +412,46 @@ def setThemeHighVis(baseDir: str):
|
|||
setThemeFromDict(baseDir, name, themeParams, bgParams)
|
||||
|
||||
|
||||
def setThemeFonts(baseDir: str, themeName: str) -> None:
|
||||
"""Adds custom theme fonts
|
||||
"""
|
||||
themeNameLower = themeName.lower()
|
||||
fontsDir = baseDir + '/fonts'
|
||||
themeFontsDir = \
|
||||
baseDir + '/theme/' + themeNameLower + '/fonts'
|
||||
if not os.path.isdir(themeFontsDir):
|
||||
return
|
||||
for subdir, dirs, files in os.walk(themeFontsDir):
|
||||
for filename in files:
|
||||
if filename.endswith('.woff2') or \
|
||||
filename.endswith('.woff') or \
|
||||
filename.endswith('.ttf') or \
|
||||
filename.endswith('.otf'):
|
||||
destFilename = fontsDir + '/' + filename
|
||||
if os.path.isfile(destFilename):
|
||||
# font already exists in the destination location
|
||||
continue
|
||||
copyfile(themeFontsDir + '/' + filename,
|
||||
destFilename)
|
||||
break
|
||||
|
||||
|
||||
def setThemeImages(baseDir: str, name: str) -> None:
|
||||
"""Changes the profile background image
|
||||
and banner to the defaults
|
||||
"""
|
||||
themeNameLower = name.lower()
|
||||
|
||||
if themeNameLower == 'default':
|
||||
profileImageFilename = \
|
||||
baseDir + '/theme/default/image.png'
|
||||
bannerFilename = \
|
||||
baseDir + '/theme/default/banner.png'
|
||||
searchBannerFilename = \
|
||||
baseDir + '/theme/default/search_banner.png'
|
||||
leftColImageFilename = \
|
||||
baseDir + '/theme/default/left_col_image.png'
|
||||
rightColImageFilename = \
|
||||
baseDir + '/theme/default/right_col_image.png'
|
||||
else:
|
||||
profileImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/image.png'
|
||||
bannerFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/banner.png'
|
||||
searchBannerFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/search_banner.png'
|
||||
leftColImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/left_col_image.png'
|
||||
rightColImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/right_col_image.png'
|
||||
profileImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/image.png'
|
||||
bannerFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/banner.png'
|
||||
searchBannerFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/search_banner.png'
|
||||
leftColImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/left_col_image.png'
|
||||
rightColImageFilename = \
|
||||
baseDir + '/theme/' + themeNameLower + '/right_col_image.png'
|
||||
|
||||
backgroundNames = ('login', 'shares', 'delete', 'follow',
|
||||
'options', 'block', 'search', 'calendar')
|
||||
|
@ -572,6 +585,7 @@ def setTheme(baseDir: str, name: str, domain: str) -> bool:
|
|||
# change the banner and profile image
|
||||
# to the default for the theme
|
||||
setThemeImages(baseDir, name)
|
||||
setThemeFonts(baseDir, name)
|
||||
result = True
|
||||
|
||||
if not result:
|
||||
|
|
Loading…
Reference in New Issue