From 2e0ab26d7542dec0657c06d431e674de01856228 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 17 Mar 2018 08:51:53 +1100 Subject: [PATCH 01/26] args: Repurpose -t to disable tty switching. --- pywal/__main__.py | 6 +++--- pywal/reload.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 7c0bf06..cb7a750 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -70,8 +70,8 @@ def get_args(args): arg.add_argument("-s", action="store_true", help="Skip changing colors in terminals.") - arg.add_argument("-t", action="store_false", - help="Deprecated: Does nothing and is no longer needed.") + arg.add_argument("-t", action="store_true", + help="Skip changing colors in tty.") arg.add_argument("-v", action="store_true", help="Print \"wal\" version.") @@ -143,7 +143,7 @@ def process_args(args): export.every(colors_plain) if not args.e: - reload.env() + reload.env(tty_reload=not args.t) if args.o: util.disown([args.o]) diff --git a/pywal/reload.py b/pywal/reload.py index 9426cfb..e815d64 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -10,11 +10,11 @@ from .settings import CACHE_DIR, MODULE_DIR, OS from . import util -def tty(): +def tty(tty_reload): """Load colors in tty.""" tty_script = os.path.join(CACHE_DIR, "colors-tty.sh") - if os.path.isfile(tty_script): + if os.path.isfile(tty_script) and tty_reload: subprocess.Popen(["sh", tty_script]) @@ -87,11 +87,11 @@ def colors(cache_dir=CACHE_DIR): print("".join(util.read_file(sequences)), end="") -def env(xrdb_file=None): +def env(xrdb_file=None, tty_reload=True): """Reload environment.""" xrdb(xrdb_file) i3() sway() polybar() print("reload: Reloaded environment.") - tty() + tty(tty_reload) From b9db8c1cc076807759e96b1125fdcf41e6603428 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 18 Mar 2018 16:09:34 +1100 Subject: [PATCH 02/26] setup: Remove pandoc requirement --- setup.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/setup.py b/setup.py index f950220..0471749 100644 --- a/setup.py +++ b/setup.py @@ -7,13 +7,7 @@ except ImportError: print("error: pywal requires Python 3.5 or greater.") quit(1) -try: - import pypandoc - LONG_DESC = pypandoc.convert("README.md", "rst") -except (IOError, ImportError, RuntimeError): - print("warning: pypandoc not found. Not converting markdown to rst.") - LONG_DESC = open('README.md').read() - +LONG_DESC = open('README.md').read() VERSION = pywal.__version__ DOWNLOAD = "https://github.com/dylanaraps/pywal/archive/%s.tar.gz" % VERSION From 6397473a65a8c0a50a4e6631127ea26dcb37fc83 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 18 Mar 2018 16:11:38 +1100 Subject: [PATCH 03/26] setup: Remove pandoc requirement --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 0471749..67b5365 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ setuptools.setup( author="Dylan Araps", author_email="dylan.araps@gmail.com", description="Generate and change colorschemes on the fly", + long_description_content_type="text/markdown", long_description=LONG_DESC, keywords="wal colorscheme terminal-emulators changing-colorschemes", license="MIT", From 49922b77aa6ed2de637cc5d55a3518601b6d6a2c Mon Sep 17 00:00:00 2001 From: Amar1729 Date: Tue, 20 Mar 2018 20:19:27 -0400 Subject: [PATCH 04/26] fixes #207 - save sequences file even with -s --- pywal/__main__.py | 3 +-- pywal/sequences.py | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index cb7a750..a47deb3 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -137,8 +137,7 @@ def process_args(args): if not args.n: wallpaper.change(colors_plain["wallpaper"]) - if not args.s: - sequences.send(colors_plain) + sequences.send(colors_plain, to_send=not args.s) export.every(colors_plain) diff --git a/pywal/sequences.py b/pywal/sequences.py index 1b2fce5..3b32af5 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -73,7 +73,7 @@ def create_sequences(colors): return "".join(sequences) -def send(colors, cache_dir=CACHE_DIR): +def send(colors, cache_dir=CACHE_DIR, to_send=True): """Send colors to all open terminals.""" if OS == "Darwin": tty_pattern = "/dev/ttys00[0-9]*" @@ -84,8 +84,9 @@ def send(colors, cache_dir=CACHE_DIR): sequences = create_sequences(colors) # Writing to "/dev/pts/[0-9] lets you send data to open terminals. - for term in glob.glob(tty_pattern): - util.save_file(sequences, term) + if to_send: + for term in glob.glob(tty_pattern): + util.save_file(sequences, term) util.save_file(sequences, os.path.join(cache_dir, "sequences")) print("colors: Set terminal colors.") From 4066d082f12b0989f06b32efc86e8cff582b9a10 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 30 Mar 2018 12:05:54 +1100 Subject: [PATCH 05/26] backend: initial work to add more backends --- pywal/__main__.py | 2 +- pywal/backends/__init__.py | 16 ++++++ pywal/backends/wal.py | 106 ++++++++++++++++++++++++++++++++++ pywal/colors.py | 114 +++++-------------------------------- 4 files changed, 138 insertions(+), 100 deletions(-) create mode 100644 pywal/backends/__init__.py create mode 100644 pywal/backends/wal.py diff --git a/pywal/__main__.py b/pywal/__main__.py index a47deb3..430cde2 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -120,7 +120,7 @@ def process_args(args): if args.i: image_file = image.get(args.i) - colors_plain = colors.get(image_file, light=args.l) + colors_plain = colors.generate(image_file, light=args.l) if args.f: colors_plain = colors.file(args.f) diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py new file mode 100644 index 0000000..d1fed5d --- /dev/null +++ b/pywal/backends/__init__.py @@ -0,0 +1,16 @@ +""" + '|| +... ... .... ... ... ... ... .... || + ||' || '|. | || || | '' .|| || + || | '|.| ||| ||| .|' || || + ||...' '| | | '|..'|' .||. + || .. | +'''' '' +Created by Dylan Araps. +""" + +from . import wal + +__all__ = [ + "wal", +] diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py new file mode 100644 index 0000000..14c4bff --- /dev/null +++ b/pywal/backends/wal.py @@ -0,0 +1,106 @@ +""" +Generate a colorscheme using imagemagick. +""" +import re +import shutil +import subprocess +import sys + +from .. import util +from ..settings import COLOR_COUNT + + +def imagemagick(color_count, img, magick_command): + """Call Imagemagick to generate a scheme.""" + flags = ["-resize", "25%", "-colors", str(color_count), + "-unique-colors", "txt:-"] + img += "[0]" + + return subprocess.check_output([*magick_command, img, *flags]).splitlines() + + +def has_im(): + """Check to see if the user has im installed.""" + if shutil.which("magick"): + return ["magick", "convert"] + + elif shutil.which("convert"): + return ["convert"] + + print("error: imagemagick not found, exiting...\n" + "error: wal requires imagemagick to function.") + sys.exit(1) + + +def gen_colors(img, color_count): + """Format the output from imagemagick into a list + of hex colors.""" + magick_command = has_im() + + for i in range(0, 20, 1): + raw_colors = imagemagick(color_count + i, img, magick_command) + + if len(raw_colors) > 16: + break + + elif i == 19: + print("colors: Imagemagick couldn't generate a suitable scheme", + "for the image. Exiting...") + sys.exit(1) + + else: + print("colors: Imagemagick couldn't generate a %s color palette, " + "trying a larger palette size %s." + % (color_count, color_count + i)) + + return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] + + +def create_palette(img, colors, light): + """Sort the generated colors and store them in a dict that + we will later save in json format.""" + raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + + if light: + # Manually adjust colors. + raw_colors[7] = raw_colors[0] + raw_colors[0] = util.lighten_color(raw_colors[15], 0.85) + raw_colors[15] = raw_colors[7] + raw_colors[8] = util.lighten_color(raw_colors[7], 0.25) + + else: + # Darken the background color slightly. + if raw_colors[0][1] != "0": + raw_colors[0] = util.darken_color(raw_colors[0], 0.25) + + # Manually adjust colors. + raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE") + raw_colors[8] = util.darken_color(raw_colors[7], 0.30) + raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE") + + colors = {"wallpaper": img, "alpha": util.Color.alpha_num, + "special": {}, "colors": {}} + colors["special"]["background"] = raw_colors[0] + colors["special"]["foreground"] = raw_colors[15] + colors["special"]["cursor"] = raw_colors[15] + + if light: + for i, color in enumerate(raw_colors): + colors["colors"]["color%s" % i] = util.saturate_color(color, 0.5) + + colors["colors"]["color0"] = raw_colors[0] + colors["colors"]["color7"] = raw_colors[15] + colors["colors"]["color8"] = util.darken_color(raw_colors[0], 0.5) + colors["colors"]["color15"] = raw_colors[15] + + else: + for i, color in enumerate(raw_colors): + colors["colors"]["color%s" % i] = color + + return colors + + +def get(img, color_count=COLOR_COUNT, light=False): + """Get colorscheme.""" + colors = gen_colors(img, color_count) + return create_palette(img, colors, light) diff --git a/pywal/colors.py b/pywal/colors.py index f47ac33..b7e274d 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -1,109 +1,25 @@ """ -Generate a colorscheme using imagemagick. +Generate a palette using various backends. """ -import os import re -import shutil -import subprocess -import sys +import os -from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__ +from . import backends from . import util +from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__ -def imagemagick(color_count, img, magick_command): - """Call Imagemagick to generate a scheme.""" - flags = ["-resize", "25%", "-colors", str(color_count), - "-unique-colors", "txt:-"] - img += "[0]" - - return subprocess.check_output([*magick_command, img, *flags]).splitlines() +def get(backend_type="wal"): + """Get backend function name from name.""" + return { + "wal": backends.wal.get, + }.get(backend_type, backend_type) -def has_im(): - """Check to see if the user has im installed.""" - if shutil.which("magick"): - return ["magick", "convert"] - - elif shutil.which("convert"): - return ["convert"] - - print("error: imagemagick not found, exiting...\n" - "error: wal requires imagemagick to function.") - sys.exit(1) - - -def gen_colors(img, color_count): - """Format the output from imagemagick into a list - of hex colors.""" - magick_command = has_im() - - for i in range(0, 20, 1): - raw_colors = imagemagick(color_count + i, img, magick_command) - - if len(raw_colors) > 16: - break - - elif i == 19: - print("colors: Imagemagick couldn't generate a suitable scheme", - "for the image. Exiting...") - sys.exit(1) - - else: - print("colors: Imagemagick couldn't generate a %s color palette, " - "trying a larger palette size %s." - % (color_count, color_count + i)) - - return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] - - -def create_palette(img, colors, light): - """Sort the generated colors and store them in a dict that - we will later save in json format.""" - raw_colors = colors[:1] + colors[8:16] + colors[8:-1] - - if light: - # Manually adjust colors. - raw_colors[7] = raw_colors[0] - raw_colors[0] = util.lighten_color(raw_colors[15], 0.85) - raw_colors[15] = raw_colors[7] - raw_colors[8] = util.lighten_color(raw_colors[7], 0.25) - - else: - # Darken the background color slightly. - if raw_colors[0][1] != "0": - raw_colors[0] = util.darken_color(raw_colors[0], 0.25) - - # Manually adjust colors. - raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE") - raw_colors[8] = util.darken_color(raw_colors[7], 0.30) - raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE") - - colors = {"wallpaper": img, "alpha": util.Color.alpha_num, - "special": {}, "colors": {}} - colors["special"]["background"] = raw_colors[0] - colors["special"]["foreground"] = raw_colors[15] - colors["special"]["cursor"] = raw_colors[15] - - if light: - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = util.saturate_color(color, 0.5) - - colors["colors"]["color0"] = raw_colors[0] - colors["colors"]["color7"] = raw_colors[15] - colors["colors"]["color8"] = util.darken_color(raw_colors[0], 0.5) - colors["colors"]["color15"] = raw_colors[15] - - else: - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = color - - return colors - - -def get(img, cache_dir=CACHE_DIR, - color_count=COLOR_COUNT, light=False): - """Get the colorscheme.""" +def generate(img, cache_dir=CACHE_DIR, + color_count=COLOR_COUNT, light=False, + backend="wal"): + """Generate a palette.""" # home_dylan_img_jpg_1.2.2.json color_type = "light" if light else "dark" cache_file = re.sub("[/|\\|.]", "_", img) @@ -118,8 +34,8 @@ def get(img, cache_dir=CACHE_DIR, else: print("wal: Generating a colorscheme...") - colors = gen_colors(img, color_count) - colors = create_palette(img, colors, light) + backend = get(backend) + colors = backend(img, color_count, light) util.save_file_json(colors, cache_file) print("wal: Generation complete.") From 7d4eb6b075f1a6f080602ca4fadee7d6faf15678 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 09:30:10 +1100 Subject: [PATCH 06/26] backend: Add colorthief.py --- pywal/__main__.py | 7 +++- pywal/backends/__init__.py | 2 ++ pywal/backends/colorthief.py | 64 ++++++++++++++++++++++++++++++++++++ pywal/colors.py | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 pywal/backends/colorthief.py diff --git a/pywal/__main__.py b/pywal/__main__.py index 430cde2..0aaef25 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -36,6 +36,10 @@ def get_args(args): arg.add_argument("-b", metavar="background", help="Custom background color to use.") + arg.add_argument("--backend", metavar="backend", + help="Which color backend to use.", + const="wal", type=str, nargs="?", default="wal") + arg.add_argument("-c", action="store_true", help="Delete all cached colorschemes.") @@ -120,7 +124,8 @@ def process_args(args): if args.i: image_file = image.get(args.i) - colors_plain = colors.generate(image_file, light=args.l) + colors_plain = colors.generate(img=image_file, light=args.l, + backend=args.backend) if args.f: colors_plain = colors.file(args.f) diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index d1fed5d..90cae0c 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -9,8 +9,10 @@ Created by Dylan Araps. """ +from . import colorthief from . import wal __all__ = [ + "colorthief", "wal", ] diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py new file mode 100644 index 0000000..349822c --- /dev/null +++ b/pywal/backends/colorthief.py @@ -0,0 +1,64 @@ +""" +Generate a colorscheme using ColorThief. +""" +import sys + +from colorthief import ColorThief + +from .. import util +from ..settings import COLOR_COUNT + + +def create_palette(img, colors): + """Create palette.""" + raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + + # Modify colors to make a better scheme. + raw_colors[0] = util.darken_color(colors[0], 0.80) + raw_colors[15] = util.lighten_color(colors[15], 0.80) + raw_colors[7] = raw_colors[15] + + colors = {"wallpaper": img, "alpha": util.Color.alpha_num, + "special": {}, "colors": {}} + + for i, color in enumerate(raw_colors): + colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25) + + raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15]) + + colors["colors"]["color0"] = raw_colors[0] + colors["special"]["background"] = raw_colors[0] + colors["special"]["foreground"] = raw_colors[15] + colors["special"]["cursor"] = raw_colors[1] + + return colors + + +def gen_colors(img, color_count): + """Loop until 16 colors are generated.""" + color_thief = ColorThief(img) + color_cmd = color_thief.get_palette + + for i in range(0, 20, 1): + raw_colors = color_cmd(color_count=color_count + i) + + if len(raw_colors) > 16: + break + + elif i == 19: + print("colors: ColorThief couldn't generate a suitable scheme", + "for the image. Exiting...") + sys.exit(1) + + else: + print("colors: ColorThief couldn't generate a %s color palette, " + "trying a larger palette size %s." + % (color_count, color_count + i)) + + return [util.rgb_to_hex(color) for color in raw_colors] + + +def get(img, color_count=COLOR_COUNT, light=False): + """Get colorscheme.""" + colors = gen_colors(img, color_count) + return create_palette(img, colors) diff --git a/pywal/colors.py b/pywal/colors.py index b7e274d..6123690 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -12,6 +12,7 @@ from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__ def get(backend_type="wal"): """Get backend function name from name.""" return { + "colorthief": backends.colorthief.get, "wal": backends.wal.get, }.get(backend_type, backend_type) From 6430724400e698c6971bf605216cbf4a4d203a12 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 09:42:32 +1100 Subject: [PATCH 07/26] backend: Add colorthief.py --- pywal/backends/colorthief.py | 4 ++-- pywal/backends/wal.py | 4 ++-- pywal/colors.py | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 349822c..71877aa 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -9,7 +9,7 @@ from .. import util from ..settings import COLOR_COUNT -def create_palette(img, colors): +def adjust(img, colors): """Create palette.""" raw_colors = colors[:1] + colors[8:16] + colors[8:-1] @@ -61,4 +61,4 @@ def gen_colors(img, color_count): def get(img, color_count=COLOR_COUNT, light=False): """Get colorscheme.""" colors = gen_colors(img, color_count) - return create_palette(img, colors) + return adjust(img, colors) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 14c4bff..814ef20 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -56,7 +56,7 @@ def gen_colors(img, color_count): return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] -def create_palette(img, colors, light): +def adjust(img, colors, light): """Sort the generated colors and store them in a dict that we will later save in json format.""" raw_colors = colors[:1] + colors[8:16] + colors[8:-1] @@ -103,4 +103,4 @@ def create_palette(img, colors, light): def get(img, color_count=COLOR_COUNT, light=False): """Get colorscheme.""" colors = gen_colors(img, color_count) - return create_palette(img, colors, light) + return adjust(img, colors, light) diff --git a/pywal/colors.py b/pywal/colors.py index 6123690..8e75a6d 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -24,8 +24,9 @@ def generate(img, cache_dir=CACHE_DIR, # home_dylan_img_jpg_1.2.2.json color_type = "light" if light else "dark" cache_file = re.sub("[/|\\|.]", "_", img) - cache_file = os.path.join(cache_dir, "schemes", "%s_%s_%s.json" - % (cache_file, color_type, __cache_version__)) + cache_file = os.path.join(cache_dir, "schemes", "%s_%s_%s_%s.json" + % (cache_file, color_type, + backend, __cache_version__)) if os.path.isfile(cache_file): colors = file(cache_file) From 37bc93cc0327e131c2640082a19ed3b18c3a5a21 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 10:30:11 +1100 Subject: [PATCH 08/26] backend: Add Colorz --- pywal/backends/__init__.py | 2 ++ pywal/backends/colorthief.py | 56 +++++++++++++++++++----------------- pywal/backends/colorz.py | 49 +++++++++++++++++++++++++++++++ pywal/backends/wal.py | 9 ++++-- pywal/colors.py | 1 + 5 files changed, 88 insertions(+), 29 deletions(-) create mode 100644 pywal/backends/colorz.py diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index 90cae0c..99ef00d 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -10,9 +10,11 @@ Created by Dylan Araps. """ from . import colorthief +from . import colorz from . import wal __all__ = [ "colorthief", + "colorz", "wal", ] diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 71877aa..78ad928 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -9,31 +9,6 @@ from .. import util from ..settings import COLOR_COUNT -def adjust(img, colors): - """Create palette.""" - raw_colors = colors[:1] + colors[8:16] + colors[8:-1] - - # Modify colors to make a better scheme. - raw_colors[0] = util.darken_color(colors[0], 0.80) - raw_colors[15] = util.lighten_color(colors[15], 0.80) - raw_colors[7] = raw_colors[15] - - colors = {"wallpaper": img, "alpha": util.Color.alpha_num, - "special": {}, "colors": {}} - - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25) - - raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15]) - - colors["colors"]["color0"] = raw_colors[0] - colors["special"]["background"] = raw_colors[0] - colors["special"]["foreground"] = raw_colors[15] - colors["special"]["cursor"] = raw_colors[1] - - return colors - - def gen_colors(img, color_count): """Loop until 16 colors are generated.""" color_thief = ColorThief(img) @@ -58,7 +33,36 @@ def gen_colors(img, color_count): return [util.rgb_to_hex(color) for color in raw_colors] +def adjust(img, colors, light): + """Create palette.""" + if light: + print("colors: Colortheif backend doesn't support light themes.") + + raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + + raw_colors[0] = util.darken_color(colors[0], 0.80) + raw_colors[15] = util.lighten_color(colors[15], 0.80) + raw_colors[7] = raw_colors[15] + + colors = {"wallpaper": img, + "alpha": util.Color.alpha_num, + "special": {}, + "colors": {}} + + for i, color in enumerate(raw_colors): + colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25) + + raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15]) + + colors["colors"]["color0"] = raw_colors[0] + colors["special"]["background"] = raw_colors[0] + colors["special"]["foreground"] = raw_colors[15] + colors["special"]["cursor"] = raw_colors[1] + + return colors + + def get(img, color_count=COLOR_COUNT, light=False): """Get colorscheme.""" colors = gen_colors(img, color_count) - return adjust(img, colors) + return adjust(img, colors, light) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py new file mode 100644 index 0000000..84acf16 --- /dev/null +++ b/pywal/backends/colorz.py @@ -0,0 +1,49 @@ +""" +Generate a colorscheme using Colorz. +""" +import subprocess + +from .. import util +from ..settings import COLOR_COUNT + + +def gen_colors(img, color_count): + """Generate a colorscheme using Colorz.""" + flags = ["-n", "6", "--bold", "0", "--no-preview"] + + return subprocess.check_output(["colorz", *flags, img]).splitlines() + + +def adjust(img, colors, light): + """Create palette.""" + if light: + print("colors: Colorz backend doesn't support light themes.") + + raw_colors = ["#000000", *colors, "#FFFFFF", + "#333333", *colors, "#FFFFFF"] + + raw_colors[0] = util.darken_color(colors[0], 0.75) + raw_colors[8] = util.darken_color(colors[0], 0.25) + raw_colors[7] = util.lighten_color(colors[0], 0.75) + raw_colors[15] = raw_colors[7] + + colors = {"wallpaper": img, + "alpha": util.Color.alpha_num, + "special": {}, + "colors": {}} + + for i, color in enumerate(raw_colors): + colors["colors"]["color%s" % i] = color + + colors["special"]["background"] = raw_colors[0] + colors["special"]["foreground"] = raw_colors[15] + colors["special"]["cursor"] = raw_colors[1] + + return colors + + +def get(img, color_count=COLOR_COUNT, light=False): + """Get colorscheme.""" + colors = gen_colors(img, color_count) + colors = [color.decode('UTF-8').split()[0] for color in colors] + return adjust(img, colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 814ef20..5d18663 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -57,7 +57,7 @@ def gen_colors(img, color_count): def adjust(img, colors, light): - """Sort the generated colors and store them in a dict that + """Adjust the generated colors and store them in a dict that we will later save in json format.""" raw_colors = colors[:1] + colors[8:16] + colors[8:-1] @@ -78,8 +78,11 @@ def adjust(img, colors, light): raw_colors[8] = util.darken_color(raw_colors[7], 0.30) raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE") - colors = {"wallpaper": img, "alpha": util.Color.alpha_num, - "special": {}, "colors": {}} + colors = {"wallpaper": img, + "alpha": util.Color.alpha_num, + "special": {}, + "colors": {}} + colors["special"]["background"] = raw_colors[0] colors["special"]["foreground"] = raw_colors[15] colors["special"]["cursor"] = raw_colors[15] diff --git a/pywal/colors.py b/pywal/colors.py index 8e75a6d..4e46222 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -13,6 +13,7 @@ def get(backend_type="wal"): """Get backend function name from name.""" return { "colorthief": backends.colorthief.get, + "colorz": backends.colorz.get, "wal": backends.wal.get, }.get(backend_type, backend_type) From 958426f167233374191feb64650b2f8aa9165e73 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 10:51:23 +1100 Subject: [PATCH 09/26] backend: cleanup --- pywal/__main__.py | 6 +++++- pywal/backends/colorthief.py | 19 ++++++++----------- pywal/backends/colorz.py | 12 +++++------- pywal/backends/wal.py | 16 +++++++--------- pywal/colors.py | 19 +++++++++++-------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 0aaef25..61dcc25 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -38,7 +38,7 @@ def get_args(args): arg.add_argument("--backend", metavar="backend", help="Which color backend to use.", - const="wal", type=str, nargs="?", default="wal") + const="list_backends", type=str, nargs="?", default="wal") arg.add_argument("-c", action="store_true", help="Delete all cached colorschemes.") @@ -106,6 +106,10 @@ def process_args(args): reload.colors() sys.exit(0) + if args.backend == "list_backends": + print("Available backends:", colors.list_backends()) + sys.exit(0) + if args.q: sys.stdout = sys.stderr = open(os.devnull, "w") diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 78ad928..a35b91e 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -6,29 +6,26 @@ import sys from colorthief import ColorThief from .. import util -from ..settings import COLOR_COUNT -def gen_colors(img, color_count): +def gen_colors(img): """Loop until 16 colors are generated.""" - color_thief = ColorThief(img) - color_cmd = color_thief.get_palette + color_cmd = ColorThief(img).get_palette for i in range(0, 20, 1): - raw_colors = color_cmd(color_count=color_count + i) + raw_colors = color_cmd(color_count=16 + i) if len(raw_colors) > 16: break elif i == 19: - print("colors: ColorThief couldn't generate a suitable scheme", + print("colors: ColorThief couldn't generate a suitable palette", "for the image. Exiting...") sys.exit(1) else: - print("colors: ColorThief couldn't generate a %s color palette, " - "trying a larger palette size %s." - % (color_count, color_count + i)) + print("colors: ColorThief couldn't create a suitable palette, " + "trying a larger palette size", 16 + i) return [util.rgb_to_hex(color) for color in raw_colors] @@ -62,7 +59,7 @@ def adjust(img, colors, light): return colors -def get(img, color_count=COLOR_COUNT, light=False): +def get(img, light=False): """Get colorscheme.""" - colors = gen_colors(img, color_count) + colors = gen_colors(img) return adjust(img, colors, light) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 84acf16..39a0d17 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -4,14 +4,12 @@ Generate a colorscheme using Colorz. import subprocess from .. import util -from ..settings import COLOR_COUNT -def gen_colors(img, color_count): +def gen_colors(img): """Generate a colorscheme using Colorz.""" - flags = ["-n", "6", "--bold", "0", "--no-preview"] - - return subprocess.check_output(["colorz", *flags, img]).splitlines() + colorz = ["colorz", "-n", "6", "--bold", "0", "--no-preview"] + return subprocess.check_output([*colorz, img]).splitlines() def adjust(img, colors, light): @@ -42,8 +40,8 @@ def adjust(img, colors, light): return colors -def get(img, color_count=COLOR_COUNT, light=False): +def get(img, light=False): """Get colorscheme.""" - colors = gen_colors(img, color_count) + colors = gen_colors(img) colors = [color.decode('UTF-8').split()[0] for color in colors] return adjust(img, colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 5d18663..d74ed82 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -7,7 +7,6 @@ import subprocess import sys from .. import util -from ..settings import COLOR_COUNT def imagemagick(color_count, img, magick_command): @@ -32,26 +31,25 @@ def has_im(): sys.exit(1) -def gen_colors(img, color_count): +def gen_colors(img): """Format the output from imagemagick into a list of hex colors.""" magick_command = has_im() for i in range(0, 20, 1): - raw_colors = imagemagick(color_count + i, img, magick_command) + raw_colors = imagemagick(16 + i, img, magick_command) if len(raw_colors) > 16: break elif i == 19: - print("colors: Imagemagick couldn't generate a suitable scheme", + print("colors: Imagemagick couldn't generate a suitable palette", "for the image. Exiting...") sys.exit(1) else: - print("colors: Imagemagick couldn't generate a %s color palette, " - "trying a larger palette size %s." - % (color_count, color_count + i)) + print("colors: Imagemagick couldn't generate a suitable palette, " + "trying a larger palette size", 16 + i) return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] @@ -103,7 +101,7 @@ def adjust(img, colors, light): return colors -def get(img, color_count=COLOR_COUNT, light=False): +def get(img, light=False): """Get colorscheme.""" - colors = gen_colors(img, color_count) + colors = gen_colors(img) return adjust(img, colors, light) diff --git a/pywal/colors.py b/pywal/colors.py index 4e46222..1dcf840 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -6,7 +6,7 @@ import os from . import backends from . import util -from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__ +from .settings import CACHE_DIR, __cache_version__ def get(backend_type="wal"): @@ -15,14 +15,18 @@ def get(backend_type="wal"): "colorthief": backends.colorthief.get, "colorz": backends.colorz.get, "wal": backends.wal.get, - }.get(backend_type, backend_type) + }.get(backend_type, backends.wal.get) -def generate(img, cache_dir=CACHE_DIR, - color_count=COLOR_COUNT, light=False, - backend="wal"): +def list_backends(): + """List color backends.""" + # TODO: Dynamically generate this. + return "colorthief, colorz, wal" + + +def generate(img, cache_dir=CACHE_DIR, light=False, backend="wal"): """Generate a palette.""" - # home_dylan_img_jpg_1.2.2.json + # home_dylan_img_jpg_backend_1.2.2.json color_type = "light" if light else "dark" cache_file = re.sub("[/|\\|.]", "_", img) cache_file = os.path.join(cache_dir, "schemes", "%s_%s_%s_%s.json" @@ -37,8 +41,7 @@ def generate(img, cache_dir=CACHE_DIR, else: print("wal: Generating a colorscheme...") - backend = get(backend) - colors = backend(img, color_count, light) + colors = get(backend)(img, light) util.save_file_json(colors, cache_file) print("wal: Generation complete.") From 5d9a00535f965f3e50d7b3f9e3f20b3e2dc28d3a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 10:52:39 +1100 Subject: [PATCH 10/26] backend: cleanup --- pywal/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pywal/settings.py b/pywal/settings.py index ca82333..fd12105 100644 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -21,5 +21,4 @@ HOME = os.getenv("HOME", os.getenv("USERPROFILE")) CACHE_DIR = os.path.join(HOME, ".cache", "wal") MODULE_DIR = os.path.dirname(__file__) CONF_DIR = os.path.join(HOME, ".config", "wal") -COLOR_COUNT = 16 OS = platform.uname()[0] From 32792a0b98baa6c920ebd8fba74a5fa196ae1fd5 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 10:54:42 +1100 Subject: [PATCH 11/26] backend: cleanup --- pywal/__main__.py | 3 +-- pywal/colors.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 61dcc25..8a7d760 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -128,8 +128,7 @@ def process_args(args): if args.i: image_file = image.get(args.i) - colors_plain = colors.generate(img=image_file, light=args.l, - backend=args.backend) + colors_plain = colors.gen(image_file, args.l, args.backend) if args.f: colors_plain = colors.file(args.f) diff --git a/pywal/colors.py b/pywal/colors.py index 1dcf840..b0c6f49 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -24,7 +24,7 @@ def list_backends(): return "colorthief, colorz, wal" -def generate(img, cache_dir=CACHE_DIR, light=False, backend="wal"): +def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json color_type = "light" if light else "dark" From 520b065a30152fb9639418ce0557d45c6a07d9a5 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 11:28:28 +1100 Subject: [PATCH 12/26] backend: cleanup --- pywal/backends/colorthief.py | 29 ++++++++----------------- pywal/backends/colorz.py | 20 +++++------------ pywal/backends/wal.py | 42 ++++++++++-------------------------- pywal/colors.py | 18 ++++++++++++++++ 4 files changed, 43 insertions(+), 66 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index a35b91e..837fc66 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -30,36 +30,25 @@ def gen_colors(img): return [util.rgb_to_hex(color) for color in raw_colors] -def adjust(img, colors, light): +def adjust(colors, light): """Create palette.""" if light: print("colors: Colortheif backend doesn't support light themes.") raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + for color in raw_colors: + color = util.lighten_color(color, 0.25) + raw_colors[0] = util.darken_color(colors[0], 0.80) - raw_colors[15] = util.lighten_color(colors[15], 0.80) - raw_colors[7] = raw_colors[15] + raw_colors[7] = util.lighten_color(colors[15], 0.60) + raw_colors[8] = util.blend_color(colors[0], colors[15]) + raw_colors[15] = raw_colors[7] - colors = {"wallpaper": img, - "alpha": util.Color.alpha_num, - "special": {}, - "colors": {}} - - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25) - - raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15]) - - colors["colors"]["color0"] = raw_colors[0] - colors["special"]["background"] = raw_colors[0] - colors["special"]["foreground"] = raw_colors[15] - colors["special"]["cursor"] = raw_colors[1] - - return colors + return raw_colors def get(img, light=False): """Get colorscheme.""" colors = gen_colors(img) - return adjust(img, colors, light) + return adjust(colors, light) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 39a0d17..44a07d0 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -12,36 +12,26 @@ def gen_colors(img): return subprocess.check_output([*colorz, img]).splitlines() -def adjust(img, colors, light): +def adjust(colors, light): """Create palette.""" if light: print("colors: Colorz backend doesn't support light themes.") + # Create list with placeholder values. raw_colors = ["#000000", *colors, "#FFFFFF", "#333333", *colors, "#FFFFFF"] + # Update placeholder values. raw_colors[0] = util.darken_color(colors[0], 0.75) raw_colors[8] = util.darken_color(colors[0], 0.25) raw_colors[7] = util.lighten_color(colors[0], 0.75) raw_colors[15] = raw_colors[7] - colors = {"wallpaper": img, - "alpha": util.Color.alpha_num, - "special": {}, - "colors": {}} - - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = color - - colors["special"]["background"] = raw_colors[0] - colors["special"]["foreground"] = raw_colors[15] - colors["special"]["cursor"] = raw_colors[1] - - return colors + return raw_colors def get(img, light=False): """Get colorscheme.""" colors = gen_colors(img) colors = [color.decode('UTF-8').split()[0] for color in colors] - return adjust(img, colors, light) + return adjust(colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index d74ed82..af955a4 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -54,54 +54,34 @@ def gen_colors(img): return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] -def adjust(img, colors, light): +def adjust(colors, light): """Adjust the generated colors and store them in a dict that we will later save in json format.""" raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + # Manually adjust colors. if light: - # Manually adjust colors. - raw_colors[7] = raw_colors[0] - raw_colors[0] = util.lighten_color(raw_colors[15], 0.85) - raw_colors[15] = raw_colors[7] - raw_colors[8] = util.lighten_color(raw_colors[7], 0.25) + for color in raw_colors: + color = util.saturate_color(color, 0.5) + + raw_colors[0] = util.lighten_color(colors[-1], 0.85) + raw_colors[7] = colors[0] + raw_colors[8] = util.darken_color(colors[-1], 0.4) + raw_colors[15] = colors[0] else: # Darken the background color slightly. if raw_colors[0][1] != "0": raw_colors[0] = util.darken_color(raw_colors[0], 0.25) - # Manually adjust colors. raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE") raw_colors[8] = util.darken_color(raw_colors[7], 0.30) raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE") - colors = {"wallpaper": img, - "alpha": util.Color.alpha_num, - "special": {}, - "colors": {}} - - colors["special"]["background"] = raw_colors[0] - colors["special"]["foreground"] = raw_colors[15] - colors["special"]["cursor"] = raw_colors[15] - - if light: - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = util.saturate_color(color, 0.5) - - colors["colors"]["color0"] = raw_colors[0] - colors["colors"]["color7"] = raw_colors[15] - colors["colors"]["color8"] = util.darken_color(raw_colors[0], 0.5) - colors["colors"]["color15"] = raw_colors[15] - - else: - for i, color in enumerate(raw_colors): - colors["colors"]["color%s" % i] = color - - return colors + return raw_colors def get(img, light=False): """Get colorscheme.""" colors = gen_colors(img) - return adjust(img, colors, light) + return adjust(colors, light) diff --git a/pywal/colors.py b/pywal/colors.py index b0c6f49..a03dd26 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -24,6 +24,23 @@ def list_backends(): return "colorthief, colorz, wal" +def colors_to_dict(colors, img): + """Convert list of colors to pywal format.""" + scheme = {"wallpaper": img, + "alpha": util.Color.alpha_num, + "special": {}, + "colors": {}} + + for i, color in enumerate(colors): + scheme["colors"]["color%s" % i] = color + + scheme["special"]["background"] = colors[0] + scheme["special"]["foreground"] = colors[15] + scheme["special"]["cursor"] = colors[1] + + return scheme + + def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json @@ -42,6 +59,7 @@ def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): print("wal: Generating a colorscheme...") colors = get(backend)(img, light) + colors = colors_to_dict(colors, img) util.save_file_json(colors, cache_file) print("wal: Generation complete.") From 26677bb64b426daf0ad4cad433706b28cdf15bc8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 12:33:52 +1100 Subject: [PATCH 13/26] backend: cleanup --- pywal/backends/colorthief.py | 26 +++++++++++++++----------- pywal/backends/colorz.py | 22 +++++++++++++++------- pywal/util.py | 5 +++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 837fc66..d223431 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -12,10 +12,10 @@ def gen_colors(img): """Loop until 16 colors are generated.""" color_cmd = ColorThief(img).get_palette - for i in range(0, 20, 1): - raw_colors = color_cmd(color_count=16 + i) + for i in range(0, 10, 1): + raw_colors = color_cmd(color_count=8 + i) - if len(raw_colors) > 16: + if len(raw_colors) >= 8: break elif i == 19: @@ -25,24 +25,28 @@ def gen_colors(img): else: print("colors: ColorThief couldn't create a suitable palette, " - "trying a larger palette size", 16 + i) + "trying a larger palette size", 8 + i) return [util.rgb_to_hex(color) for color in raw_colors] def adjust(colors, light): """Create palette.""" + colors.sort(key=util.rgb_to_yiq) + raw_colors = [*colors, *colors] + if light: - print("colors: Colortheif backend doesn't support light themes.") + raw_colors[0] = util.lighten_color(colors[0], 0.90) + raw_colors[7] = util.darken_color(colors[0], 0.75) - raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + else: + for color in raw_colors: + color = util.lighten_color(color, 0.40) - for color in raw_colors: - color = util.lighten_color(color, 0.25) + raw_colors[0] = util.darken_color(colors[0], 0.80) + raw_colors[7] = util.lighten_color(colors[0], 0.60) - raw_colors[0] = util.darken_color(colors[0], 0.80) - raw_colors[7] = util.lighten_color(colors[15], 0.60) - raw_colors[8] = util.blend_color(colors[0], colors[15]) + raw_colors[8] = util.lighten_color(colors[0], 0.20) raw_colors[15] = raw_colors[7] return raw_colors diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 44a07d0..e67a8c8 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -14,18 +14,26 @@ def gen_colors(img): def adjust(colors, light): """Create palette.""" - if light: - print("colors: Colorz backend doesn't support light themes.") - # Create list with placeholder values. raw_colors = ["#000000", *colors, "#FFFFFF", "#333333", *colors, "#FFFFFF"] # Update placeholder values. - raw_colors[0] = util.darken_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[7] = util.lighten_color(colors[0], 0.75) - raw_colors[15] = raw_colors[7] + if light: + for color in raw_colors: + color = util.saturate_color(color, 0.50) + color = util.darken_color(color, 0.4) + + raw_colors[0] = util.lighten_color(colors[0], 0.9) + raw_colors[7] = util.darken_color(colors[0], 0.75) + raw_colors[8] = util.darken_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] + + else: + raw_colors[0] = util.darken_color(colors[0], 0.75) + raw_colors[7] = util.lighten_color(colors[0], 0.75) + raw_colors[8] = util.darken_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] return raw_colors diff --git a/pywal/util.py b/pywal/util.py index 43ee3fb..65d4557 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -144,6 +144,11 @@ def saturate_color(color, amount): return rgb_to_hex((int(r), int(g), int(b))) +def rgb_to_yiq(color): + """Sort a list of colors.""" + return colorsys.rgb_to_yiq(*hex_to_rgb(color)) + + def disown(cmd): """Call a system command in the background, disown it and hide it's output.""" From 277edbc5e07ce2b0f5ff6f2193d007501b3da8c0 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 13:15:08 +1100 Subject: [PATCH 14/26] backend: dynamic fo shizle --- pywal/colors.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index a03dd26..7611826 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -1,27 +1,18 @@ """ Generate a palette using various backends. """ -import re import os +import re +import sys from . import backends from . import util from .settings import CACHE_DIR, __cache_version__ -def get(backend_type="wal"): - """Get backend function name from name.""" - return { - "colorthief": backends.colorthief.get, - "colorz": backends.colorz.get, - "wal": backends.wal.get, - }.get(backend_type, backends.wal.get) - - def list_backends(): """List color backends.""" - # TODO: Dynamically generate this. - return "colorthief, colorz, wal" + return [backend for backend in dir(backends) if "__" not in backend] def colors_to_dict(colors, img): @@ -58,8 +49,9 @@ def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): else: print("wal: Generating a colorscheme...") - colors = get(backend)(img, light) - colors = colors_to_dict(colors, img) + # Dynamic shiz. + backend = sys.modules["pywal.backends.%s" % backend] + colors = colors_to_dict(getattr(backend, "get")(img, light), img) util.save_file_json(colors, cache_file) print("wal: Generation complete.") From c10f7e732307f77a7652189abecbae06490cf19a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 13:28:11 +1100 Subject: [PATCH 15/26] backend: Error handling --- pywal/backends/colorthief.py | 8 +++++++- pywal/backends/colorz.py | 7 +++++++ pywal/backends/wal.py | 4 ++-- pywal/colors.py | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index d223431..be8a3f1 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -3,7 +3,13 @@ Generate a colorscheme using ColorThief. """ import sys -from colorthief import ColorThief +try: + from colorthief import ColorThief + +except ImportError: + print("Error: ColorThief wasn't found on your system.", + "Try another backend. (wal --backend)") + sys.exit(1) from .. import util diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index e67a8c8..5884e54 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -1,7 +1,9 @@ """ Generate a colorscheme using Colorz. """ +import shutil import subprocess +import sys from .. import util @@ -40,6 +42,11 @@ def adjust(colors, light): def get(img, light=False): """Get colorscheme.""" + if not shutil.which("colorz"): + print("Error: Colorz wasn't found on your system.", + "Try another backend. (wal --backend)") + sys.exit(1) + colors = gen_colors(img) colors = [color.decode('UTF-8').split()[0] for color in colors] return adjust(colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index af955a4..71cd7e4 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -26,8 +26,8 @@ def has_im(): elif shutil.which("convert"): return ["convert"] - print("error: imagemagick not found, exiting...\n" - "error: wal requires imagemagick to function.") + print("Error: ImageMagick wasn't found on your system.", + "Try another backend. (wal --backend)") sys.exit(1) diff --git a/pywal/colors.py b/pywal/colors.py index 7611826..d169c00 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -3,6 +3,7 @@ Generate a palette using various backends. """ import os import re +import shutil import sys from . import backends From dc09707a87ddab501b29ddd2f15aadb2041c17f7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 14:53:11 +1100 Subject: [PATCH 16/26] backend: Add Schemer2 --- pywal/backends/__init__.py | 2 ++ pywal/backends/colorthief.py | 2 +- pywal/backends/colorz.py | 6 ++--- pywal/backends/schemer2.py | 52 ++++++++++++++++++++++++++++++++++++ pywal/backends/wal.py | 2 +- 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 pywal/backends/schemer2.py diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index 99ef00d..d1eb6e7 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -11,10 +11,12 @@ Created by Dylan Araps. from . import colorthief from . import colorz +from . import schemer2 from . import wal __all__ = [ "colorthief", "colorz", + "schemer2", "wal", ] diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index be8a3f1..7e1eec2 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -7,7 +7,7 @@ try: from colorthief import ColorThief except ImportError: - print("Error: ColorThief wasn't found on your system.", + print("error: ColorThief wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 5884e54..776678e 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -10,8 +10,8 @@ from .. import util def gen_colors(img): """Generate a colorscheme using Colorz.""" - colorz = ["colorz", "-n", "6", "--bold", "0", "--no-preview"] - return subprocess.check_output([*colorz, img]).splitlines() + cmd = ["colorz", "-n", "6", "--bold", "0", "--no-preview"] + return subprocess.check_output([*cmd, img]).splitlines() def adjust(colors, light): @@ -43,7 +43,7 @@ def adjust(colors, light): def get(img, light=False): """Get colorscheme.""" if not shutil.which("colorz"): - print("Error: Colorz wasn't found on your system.", + print("error: Colorz wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py new file mode 100644 index 0000000..9523972 --- /dev/null +++ b/pywal/backends/schemer2.py @@ -0,0 +1,52 @@ +""" +Generate a colorscheme using Schemer2. +""" +import shutil +import subprocess +import sys + +from .. import util + + +def gen_colors(img): + """Generate a colorscheme using Colorz.""" + cmd = ["schemer2", "-format", "img::colors", "-minBright", "75", "-in"] + return subprocess.check_output([*cmd, img]).splitlines() + + +def adjust(colors, light): + """Create palette.""" + # Create list with placeholder values. + colors.sort(key=util.rgb_to_yiq) + raw_colors = [*colors[8:], *colors[8:]] + + # Update placeholder values. + if light: + for color in raw_colors: + color = util.saturate_color(color, 0.50) + color = util.darken_color(color, 0.4) + + raw_colors[0] = util.lighten_color(colors[0], 0.9) + raw_colors[7] = util.darken_color(colors[0], 0.75) + raw_colors[8] = util.darken_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] + + else: + raw_colors[0] = util.darken_color(colors[0], 0.75) + raw_colors[7] = util.lighten_color(colors[0], 0.75) + raw_colors[8] = util.lighten_color(colors[0], 0.25) + raw_colors[15] = raw_colors[7] + + return raw_colors + + +def get(img, light=False): + """Get colorscheme.""" + if not shutil.which("schemer2"): + print("error: Schemer2 wasn't found on your system.", + "Try another backend. (wal --backend)") + sys.exit(1) + + colors = gen_colors(img) + colors = [color.decode('UTF-8') for color in colors] + return adjust(colors, light) diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index 71cd7e4..678c66c 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -26,7 +26,7 @@ def has_im(): elif shutil.which("convert"): return ["convert"] - print("Error: ImageMagick wasn't found on your system.", + print("error: ImageMagick wasn't found on your system.", "Try another backend. (wal --backend)") sys.exit(1) From b514de8e8a79c7524e43284c86be61f97063d3a9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 15:47:11 +1100 Subject: [PATCH 17/26] backend: cleanup --- pywal/backends/colorthief.py | 20 ++++++++++---------- pywal/backends/colorz.py | 32 ++++++++------------------------ pywal/backends/schemer2.py | 31 +++++++------------------------ pywal/colors.py | 22 +++++++++++++++++++++- 4 files changed, 46 insertions(+), 59 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 7e1eec2..180af5f 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -36,23 +36,23 @@ def gen_colors(img): return [util.rgb_to_hex(color) for color in raw_colors] -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" - colors.sort(key=util.rgb_to_yiq) - raw_colors = [*colors, *colors] + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols, *cols] if light: - raw_colors[0] = util.lighten_color(colors[0], 0.90) - raw_colors[7] = util.darken_color(colors[0], 0.75) + raw_colors[0] = util.lighten_color(cols[0], 0.90) + raw_colors[7] = util.darken_color(cols[0], 0.75) else: for color in raw_colors: color = util.lighten_color(color, 0.40) - raw_colors[0] = util.darken_color(colors[0], 0.80) - raw_colors[7] = util.lighten_color(colors[0], 0.60) + raw_colors[0] = util.darken_color(cols[0], 0.80) + raw_colors[7] = util.lighten_color(cols[0], 0.60) - raw_colors[8] = util.lighten_color(colors[0], 0.20) + raw_colors[8] = util.lighten_color(cols[0], 0.20) raw_colors[15] = raw_colors[7] return raw_colors @@ -60,5 +60,5 @@ def adjust(colors, light): def get(img, light=False): """Get colorscheme.""" - colors = gen_colors(img) - return adjust(colors, light) + cols = gen_colors(img) + return adjust(cols, light) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 776678e..44e75cb 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys +from .. import colors from .. import util @@ -14,30 +15,14 @@ def gen_colors(img): return subprocess.check_output([*cmd, img]).splitlines() -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" # Create list with placeholder values. - raw_colors = ["#000000", *colors, "#FFFFFF", - "#333333", *colors, "#FFFFFF"] + bg = util.blend_color("#555555", cols[1]) + raw_colors = [bg, *cols, "#FFFFFF", + "#333333", *cols, "#FFFFFF"] - # Update placeholder values. - if light: - for color in raw_colors: - color = util.saturate_color(color, 0.50) - color = util.darken_color(color, 0.4) - - raw_colors[0] = util.lighten_color(colors[0], 0.9) - raw_colors[7] = util.darken_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - else: - raw_colors[0] = util.darken_color(colors[0], 0.75) - raw_colors[7] = util.lighten_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): @@ -47,6 +32,5 @@ def get(img, light=False): "Try another backend. (wal --backend)") sys.exit(1) - colors = gen_colors(img) - colors = [color.decode('UTF-8').split()[0] for color in colors] - return adjust(colors, light) + cols = [col.decode('UTF-8').split()[0] for col in gen_colors(img)] + return adjust(cols, light) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py index 9523972..c3d81d7 100644 --- a/pywal/backends/schemer2.py +++ b/pywal/backends/schemer2.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys +from .. import colors from .. import util @@ -14,30 +15,13 @@ def gen_colors(img): return subprocess.check_output([*cmd, img]).splitlines() -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" # Create list with placeholder values. - colors.sort(key=util.rgb_to_yiq) - raw_colors = [*colors[8:], *colors[8:]] + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols[8:], *cols[8:]] - # Update placeholder values. - if light: - for color in raw_colors: - color = util.saturate_color(color, 0.50) - color = util.darken_color(color, 0.4) - - raw_colors[0] = util.lighten_color(colors[0], 0.9) - raw_colors[7] = util.darken_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - else: - raw_colors[0] = util.darken_color(colors[0], 0.75) - raw_colors[7] = util.lighten_color(colors[0], 0.75) - raw_colors[8] = util.lighten_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): @@ -47,6 +31,5 @@ def get(img, light=False): "Try another backend. (wal --backend)") sys.exit(1) - colors = gen_colors(img) - colors = [color.decode('UTF-8') for color in colors] - return adjust(colors, light) + cols = [col.decode('UTF-8') for col in gen_colors(img)] + return adjust(cols, light) diff --git a/pywal/colors.py b/pywal/colors.py index d169c00..164f34a 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -3,7 +3,6 @@ Generate a palette using various backends. """ import os import re -import shutil import sys from . import backends @@ -33,6 +32,27 @@ def colors_to_dict(colors, img): return scheme +def generic_adjust(colors, light): + """Generic color adjustment for themers.""" + if light: + for color in colors: + color = util.saturate_color(color, 0.50) + color = util.darken_color(color, 0.4) + + colors[0] = util.lighten_color(colors[0], 0.9) + colors[7] = util.darken_color(colors[0], 0.75) + colors[8] = util.darken_color(colors[0], 0.25) + colors[15] = colors[7] + + else: + colors[0] = util.darken_color(colors[0], 0.75) + colors[7] = util.lighten_color(colors[0], 0.75) + colors[8] = util.lighten_color(colors[0], 0.25) + colors[15] = colors[7] + + return colors + + def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json From 435e4cd2a87d58816f8bb22bf803177c87d29a1e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 16:31:26 +1100 Subject: [PATCH 18/26] backend: Add haishoku --- pywal/backends/__init__.py | 2 ++ pywal/backends/colorz.py | 2 +- pywal/backends/haishoku.py | 36 ++++++++++++++++++++++++++++++++++++ pywal/backends/schemer2.py | 1 - 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 pywal/backends/haishoku.py diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index d1eb6e7..d267a77 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -11,12 +11,14 @@ Created by Dylan Araps. from . import colorthief from . import colorz +from . import haishoku from . import schemer2 from . import wal __all__ = [ "colorthief", "colorz", + "haishoku", "schemer2", "wal", ] diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 44e75cb..0c5148d 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -17,8 +17,8 @@ def gen_colors(img): def adjust(cols, light): """Create palette.""" - # Create list with placeholder values. bg = util.blend_color("#555555", cols[1]) + raw_colors = [bg, *cols, "#FFFFFF", "#333333", *cols, "#FFFFFF"] diff --git a/pywal/backends/haishoku.py b/pywal/backends/haishoku.py new file mode 100644 index 0000000..413c9d7 --- /dev/null +++ b/pywal/backends/haishoku.py @@ -0,0 +1,36 @@ +""" +Generate a colorscheme using Haishoku. +""" +import sys + +try: + from haishoku.haishoku import Haishoku + +except ImportError: + print("error: Haishoku wasn't found on your system.", + "Try another backend. (wal --backend)") + sys.exit(1) + +from .. import colors +from .. import util + + +def gen_colors(img): + """Generate a colorscheme using Colorz.""" + palette = Haishoku.getPalette(img) + return [util.rgb_to_hex(col[1]) for col in palette] + + +def adjust(cols, light): + """Create palette.""" + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols, *cols] + raw_colors[0] = util.lighten_color(cols[0], 0.40) + + return colors.generic_adjust(raw_colors, light) + + +def get(img, light=False): + """Get colorscheme.""" + cols = gen_colors(img) + return adjust(cols, light) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py index c3d81d7..87873ec 100644 --- a/pywal/backends/schemer2.py +++ b/pywal/backends/schemer2.py @@ -17,7 +17,6 @@ def gen_colors(img): def adjust(cols, light): """Create palette.""" - # Create list with placeholder values. cols.sort(key=util.rgb_to_yiq) raw_colors = [*cols[8:], *cols[8:]] From 44d8402e6e9be94fc615c2df1f66417acecff9d5 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 17:04:03 +1100 Subject: [PATCH 19/26] pylint: fixes --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 08f340e..8d4e0ae 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,7 +7,7 @@ good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3,h,s,v # too-many-branches: # Disabled as it's a non-issue and only occurs in the # process_args() function. -disable=inconsistent-return-statements,too-many-branches +disable=inconsistent-return-statements,too-many-branches,too-many-statements [SIMILARITIES] ignore-imports=y From 9efc64f170fa608fd9e0d91b3f13e033af12919c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 17:05:41 +1100 Subject: [PATCH 20/26] pylint: fixes --- pywal/__main__.py | 2 +- pywal/colors.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 8a7d760..05eea99 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -128,7 +128,7 @@ def process_args(args): if args.i: image_file = image.get(args.i) - colors_plain = colors.gen(image_file, args.l, args.backend) + colors_plain = colors.get(image_file, args.l, args.backend) if args.f: colors_plain = colors.file(args.f) diff --git a/pywal/colors.py b/pywal/colors.py index 164f34a..20110da 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -53,7 +53,7 @@ def generic_adjust(colors, light): return colors -def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): +def get(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json color_type = "light" if light else "dark" From 1411ef02f3ce54fac301b49923d270834aada4c8 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 17:06:33 +1100 Subject: [PATCH 21/26] travis: fixes --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a0a043..501b4fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,5 +18,4 @@ install: script: - flake8 pywal tests setup.py - pylint pywal tests setup.py - - pyroma . - python setup.py test From 5a680b8af6f833e19bed654c411229217dd632ed Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 17:33:23 +1100 Subject: [PATCH 22/26] backend: cleanup --- pywal/colors.py | 54 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index 20110da..a40331a 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -17,19 +17,35 @@ def list_backends(): def colors_to_dict(colors, img): """Convert list of colors to pywal format.""" - scheme = {"wallpaper": img, - "alpha": util.Color.alpha_num, - "special": {}, - "colors": {}} + return { + "wallpaper": img, + "alpha": util.Color.alpha_num, - for i, color in enumerate(colors): - scheme["colors"]["color%s" % i] = color + "special": { + "background": colors[0], + "foreground": colors[15], + "cursor": colors[1] + }, - scheme["special"]["background"] = colors[0] - scheme["special"]["foreground"] = colors[15] - scheme["special"]["cursor"] = colors[1] - - return scheme + "colors": { + "color0": colors[0], + "color1": colors[1], + "color2": colors[2], + "color3": colors[3], + "color4": colors[4], + "color5": colors[5], + "color6": colors[6], + "color7": colors[7], + "color8": colors[8], + "color9": colors[9], + "color10": colors[10], + "color11": colors[11], + "color12": colors[12], + "color13": colors[13], + "color14": colors[14], + "color15": colors[15] + } + } def generic_adjust(colors, light): @@ -53,14 +69,20 @@ def generic_adjust(colors, light): return colors +def cache_fname(img, backend, light, cache_dir): + """Create the cache file name.""" + color_type = "light" if light else "dark" + file_name = re.sub("[/|\\|.]", "_", img) + + file_parts = [file_name, color_type, backend, __cache_version__] + return [cache_dir, "schemes", "%s_%s_%s_%s.json" % (*file_parts,)] + + def get(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json - color_type = "light" if light else "dark" - cache_file = re.sub("[/|\\|.]", "_", img) - cache_file = os.path.join(cache_dir, "schemes", "%s_%s_%s_%s.json" - % (cache_file, color_type, - backend, __cache_version__)) + cache_name = cache_fname(img, backend, light, cache_dir) + cache_file = os.path.join(*cache_name) if os.path.isfile(cache_file): colors = file(cache_file) From 83cdbaedb88ca2477af73fba0247b24511ded33d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 1 Apr 2018 08:08:03 +1000 Subject: [PATCH 23/26] travis: fixes --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 501b4fc..4f54fe7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y imagemagick; fi install: - - pip install flake8 pylint pyroma + - pip install flake8 pylint colorthief script: - flake8 pywal tests setup.py From fc5f167d19effe4a8d6a52fa2097cef8daca6ce9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 1 Apr 2018 08:39:32 +1000 Subject: [PATCH 24/26] backends: Dynamically import the backend we want to use. --- pywal/colors.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index a40331a..06863ac 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -5,14 +5,15 @@ import os import re import sys -from . import backends from . import util -from .settings import CACHE_DIR, __cache_version__ +from .settings import CACHE_DIR, MODULE_DIR, __cache_version__ def list_backends(): """List color backends.""" - return [backend for backend in dir(backends) if "__" not in backend] + return [b.name.replace(".py", "") for b in + os.scandir(os.path.join(MODULE_DIR, "backends")) + if "__" not in b.name] def colors_to_dict(colors, img): @@ -92,7 +93,13 @@ def get(img, light=False, backend="wal", cache_dir=CACHE_DIR): else: print("wal: Generating a colorscheme...") - # Dynamic shiz. + # Dynamically import the backend we want to use. + # This keeps the dependencies "optional". + try: + __import__("pywal.backends.%s" % backend) + except ImportError: + backend = "wal" + backend = sys.modules["pywal.backends.%s" % backend] colors = colors_to_dict(getattr(backend, "get")(img, light), img) From 8d8b616b524ce05b18f99691b190e23f7abee595 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 1 Apr 2018 08:41:01 +1000 Subject: [PATCH 25/26] pylint: fixes --- .pylintrc | 3 +++ .travis.yml | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 8d4e0ae..e41fb8c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,6 +7,9 @@ good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3,h,s,v # too-many-branches: # Disabled as it's a non-issue and only occurs in the # process_args() function. +# too-many-statements: +# Disabled as it's a non-issue and only occurs in the +# process_args() function. disable=inconsistent-return-statements,too-many-branches,too-many-statements [SIMILARITIES] diff --git a/.travis.yml b/.travis.yml index 4f54fe7..11a9bfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,13 +7,12 @@ matrix: - os: linux python: 3.6 - before_install: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y imagemagick; fi install: - - pip install flake8 pylint colorthief + - pip install flake8 pylint script: - flake8 pywal tests setup.py From 32806bc60fc57e5bb2152f0e485e736eb4f801a1 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 1 Apr 2018 09:13:17 +1000 Subject: [PATCH 26/26] sorry: not sorry --- pywal/backends/__init__.py | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py index d267a77..9a116e8 100644 --- a/pywal/backends/__init__.py +++ b/pywal/backends/__init__.py @@ -1,24 +1,10 @@ +r""" +Hh ____ +HP "HHF:. `._ :.,-'"" "-. +F F" :::..'"" "-. `. +F , \ \ "BACKENDS" +F j\ / ; `. - sorry +| j `. ` A \ +| | ;_ . 8 \ +J F\_,'| "`-----.\ j `. \ """ - '|| -... ... .... ... ... ... ... .... || - ||' || '|. | || || | '' .|| || - || | '|.| ||| ||| .|' || || - ||...' '| | | '|..'|' .||. - || .. | -'''' '' -Created by Dylan Araps. -""" - -from . import colorthief -from . import colorz -from . import haishoku -from . import schemer2 -from . import wal - -__all__ = [ - "colorthief", - "colorz", - "haishoku", - "schemer2", - "wal", -]