From 788533e5c20132c727e2f287dce6ada64ebd5872 Mon Sep 17 00:00:00 2001 From: Austin Schey Date: Sun, 3 Mar 2019 11:13:44 -0600 Subject: added features for saving user themes and loading random themes --- pywal/theme.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index fcd1dd1..62695b5 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -33,6 +33,7 @@ def list_out(): print(" - random (select a random dark theme)") print(" - random_dark (select a random dark theme)") print(" - random_light (select a random light theme)") + print(" - random_user (select a random user theme)") def list_themes(dark=True): @@ -88,6 +89,13 @@ def get_random_theme(dark=True): return themes[0] +def get_random_theme_user(): + """Get a random theme file from user theme directories.""" + themes = [theme.path for theme in list_themes_user()] + random.shuffle(themes) + return themes[0] + + def file(input_file, light=False): """Import colorscheme from json file.""" util.create_dir(os.path.join(CONF_DIR, "colorschemes/light/")) @@ -106,6 +114,9 @@ def file(input_file, light=False): elif input_file == "random_light": theme_file = get_random_theme(light) + elif input_file == "random_user": + theme_file = get_random_theme_user() + elif os.path.isfile(user_theme_file): theme_file = user_theme_file @@ -122,3 +133,11 @@ def file(input_file, light=False): logging.error("Try adding '-l' to set light themes.") logging.error("Try removing '-l' to set dark themes.") sys.exit(1) + + +def save(colors, theme_name, light=False): + """Save colors to a theme file.""" + theme_file = theme_name + ".json" + theme_path = os.path.join(CONF_DIR, "colorschemes", + "light" if light else "dark", theme_file) + util.save_file_json(colors, theme_path) -- cgit v1.2.3 From 3bc9f104518c4b480591c16404a4c04ca4801a7a Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 10:37:07 +0200 Subject: Save used theme in CACHE_DIR --- pywal/theme.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index fcd1dd1..423a4c5 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -6,7 +6,7 @@ import os import random import sys -from .settings import CONF_DIR, MODULE_DIR +from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR from . import util @@ -116,6 +116,7 @@ def file(input_file, light=False): if os.path.isfile(theme_file): logging.info("Set theme to \033[1;37m%s\033[0m.", os.path.basename(theme_file)) + util.save_file(os.path.basename(theme_file), os.path.join(CACHE_DIR, "theme")) return parse(theme_file) logging.error("No %s colorscheme file found.", bri) -- cgit v1.2.3 From 3476989e6bd7a0526ff4dc4d592c8327a4c64f50 Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 10:58:39 +0200 Subject: Print (last used) next to last used theme --- pywal/theme.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index 423a4c5..5c973da 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -19,12 +19,16 @@ def list_out(): user_themes = [theme.name.replace(".json", "") for theme in list_themes_user()] + last_used_theme = util.read_file(os.path.join(CACHE_DIR, + "last_used_theme"))[0].replace(".json", "") + if user_themes: print("\033[1;32mUser Themes\033[0m:") print(" -", "\n - ".join(sorted(user_themes))) print("\033[1;32mDark Themes\033[0m:") print(" -", "\n - ".join(sorted(dark_themes))) + print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t for t in sorted(dark_themes))) print("\033[1;32mLight Themes\033[0m:") print(" -", "\n - ".join(sorted(ligh_themes))) @@ -116,7 +120,8 @@ def file(input_file, light=False): if os.path.isfile(theme_file): logging.info("Set theme to \033[1;37m%s\033[0m.", os.path.basename(theme_file)) - util.save_file(os.path.basename(theme_file), os.path.join(CACHE_DIR, "theme")) + util.save_file(os.path.basename(theme_file), os.path.join(CACHE_DIR, + "last_used_theme")) return parse(theme_file) logging.error("No %s colorscheme file found.", bri) -- cgit v1.2.3 From fe700cb77aab6df55de05704082576b19d7652b5 Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 11:00:42 +0200 Subject: Do for all types of themes (dark, light, user) --- pywal/theme.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index 5c973da..04e4b2b 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -24,14 +24,16 @@ def list_out(): if user_themes: print("\033[1;32mUser Themes\033[0m:") - print(" -", "\n - ".join(sorted(user_themes))) + print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t + for t in sorted(user_themes))) print("\033[1;32mDark Themes\033[0m:") - print(" -", "\n - ".join(sorted(dark_themes))) - print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t for t in sorted(dark_themes))) + print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t + for t in sorted(dark_themes))) print("\033[1;32mLight Themes\033[0m:") - print(" -", "\n - ".join(sorted(ligh_themes))) + print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t + for t in sorted(ligh_themes))) print("\033[1;32mExtra\033[0m:") print(" - random (select a random dark theme)") -- cgit v1.2.3 From 0c32f4e9a920938120297a397c33ca3c655f697f Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 11:18:37 +0200 Subject: Fix pylint --- pywal/theme.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index 04e4b2b..c053f18 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -19,21 +19,22 @@ def list_out(): user_themes = [theme.name.replace(".json", "") for theme in list_themes_user()] - last_used_theme = util.read_file(os.path.join(CACHE_DIR, - "last_used_theme"))[0].replace(".json", "") + + last_used_theme = util.read_file(os.path.join( + CACHE_DIR, "last_used_theme"))[0].replace(".json", "") if user_themes: print("\033[1;32mUser Themes\033[0m:") print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t - for t in sorted(user_themes))) + for t in sorted(user_themes))) print("\033[1;32mDark Themes\033[0m:") print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t - for t in sorted(dark_themes))) + for t in sorted(dark_themes))) print("\033[1;32mLight Themes\033[0m:") print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t - for t in sorted(ligh_themes))) + for t in sorted(ligh_themes))) print("\033[1;32mExtra\033[0m:") print(" - random (select a random dark theme)") @@ -122,8 +123,8 @@ def file(input_file, light=False): if os.path.isfile(theme_file): logging.info("Set theme to \033[1;37m%s\033[0m.", os.path.basename(theme_file)) - util.save_file(os.path.basename(theme_file), os.path.join(CACHE_DIR, - "last_used_theme")) + util.save_file(os.path.basename(theme_file), + os.path.join(CACHE_DIR, "last_used_theme")) return parse(theme_file) logging.error("No %s colorscheme file found.", bri) -- cgit v1.2.3 From b6a11f6338daabd33ffbfadc3a4f15e7080214eb Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 11:54:42 +0200 Subject: Fix line length for pylint --- pywal/theme.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index c053f18..2b14600 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -19,14 +19,13 @@ def list_out(): user_themes = [theme.name.replace(".json", "") for theme in list_themes_user()] - last_used_theme = util.read_file(os.path.join( CACHE_DIR, "last_used_theme"))[0].replace(".json", "") if user_themes: print("\033[1;32mUser Themes\033[0m:") - print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t - for t in sorted(user_themes))) + print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme + else t for t in sorted(user_themes))) print("\033[1;32mDark Themes\033[0m:") print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t -- cgit v1.2.3 From 4cc2dda585a6e7f6fa8f801c2be42064204c71d8 Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Tue, 1 Oct 2019 16:54:53 +0200 Subject: Fix FileNotFoundError if theme has never been set --- pywal/theme.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index 2b14600..706ed31 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -19,8 +19,11 @@ def list_out(): user_themes = [theme.name.replace(".json", "") for theme in list_themes_user()] - last_used_theme = util.read_file(os.path.join( - CACHE_DIR, "last_used_theme"))[0].replace(".json", "") + try: + last_used_theme = util.read_file(os.path.join( + CACHE_DIR, "last_used_theme"))[0].replace(".json", "") + except FileNotFoundError: + last_used_theme = "" if user_themes: print("\033[1;32mUser Themes\033[0m:") -- cgit v1.2.3