From 69d3521647a6e3892966f3cefa7e554370ede1a0 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 28 May 2020 22:39:41 +0100 Subject: [PATCH] Tidying --- theme.py | 65 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/theme.py b/theme.py index 6a551e23..3d94e54d 100644 --- a/theme.py +++ b/theme.py @@ -338,6 +338,42 @@ def setThemeLight(baseDir: str): setThemeFromDict(baseDir, 'light', themeParams) +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 + '/img/image.png' + bannerFilename = \ + baseDir + '/img/banner.png' + else: + profileImageFilename = \ + baseDir + '/img/image_' + themeNameLower + '.png' + bannerFilename = \ + baseDir + '/img/banner_' + themeNameLower + '.png' + if os.path.isfile(profileImageFilename) and \ + os.path.isfile(bannerFilename): + for subdir, dirs, files in os.walk(baseDir + + '/accounts'): + for acct in dirs: + if '@' not in acct: + continue + if 'inbox@' in acct: + continue + accountDir = \ + os.path.join(baseDir + '/accounts', acct) + try: + copyfile(profileImageFilename, + accountDir + '/image.png') + copyfile(bannerFilename, + accountDir + '/banner.png') + except BaseException: + pass + + def setTheme(baseDir: str, name: str) -> bool: result = False @@ -352,34 +388,7 @@ def setTheme(baseDir: str, name: str) -> bool: if prevThemeName.lower() != themeNameLower: # change the banner and profile image # to the default for the theme - if themeNameLower == 'default': - profileImageFilename = \ - baseDir + '/img/image.png' - bannerFilename = \ - baseDir + '/img/banner.png' - else: - profileImageFilename = \ - baseDir + '/img/image_' + themeNameLower + '.png' - bannerFilename = \ - baseDir + '/img/banner_' + themeNameLower + '.png' - if os.path.isfile(profileImageFilename) and \ - os.path.isfile(bannerFilename): - for subdir, dirs, files in os.walk(baseDir + - '/accounts'): - for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct: - continue - accountDir = \ - os.path.join(baseDir + '/accounts', acct) - try: - copyfile(profileImageFilename, - accountDir + '/image.png') - copyfile(bannerFilename, - accountDir + '/banner.png') - except BaseException: - pass + setThemeImages(baseDir, name) result = True if not result: