diff options
| author | Dylan Araps <dylanaraps@users.noreply.github.com> | 2017-07-10 00:09:11 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-10 00:09:11 +1000 |
| commit | a6f99791ce79f0eed40396e8f3462413ce66554c (patch) | |
| tree | 77bd9cc12991137d6449c7a3cc1e492363c99ffb /pywal | |
| parent | dd95c26b40fc08abe9b9a6b27cbab77ffb00ad28 (diff) | |
| parent | c38c89ece1d41942fa322c555993e50e5c515e41 (diff) | |
Merge pull request #42 from dylanaraps/wallpaper
export: Add wallpaper to export files.
Diffstat (limited to 'pywal')
| -rw-r--r-- | pywal/__main__.py | 9 | ||||
| -rw-r--r-- | pywal/export.py | 4 | ||||
| -rw-r--r-- | pywal/magic.py | 12 | ||||
| -rw-r--r-- | pywal/templates/colors.css | 5 | ||||
| -rw-r--r-- | pywal/templates/colors.json | 2 | ||||
| -rw-r--r-- | pywal/templates/colors.scss | 5 | ||||
| -rw-r--r-- | pywal/templates/colors.sh | 5 | ||||
| -rw-r--r-- | pywal/util.py | 5 | ||||
| -rw-r--r-- | pywal/wallpaper.py | 3 |
9 files changed, 39 insertions, 11 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py index ff86b00..cdd5001 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -89,13 +89,8 @@ def process_args(args): # -i if args.i: image_file = image.get_image(args.i) - - # Create a list of hex colors. colors_plain = magic.get_colors(image_file, args.q) - if not args.n: - wallpaper.set_wallpaper(image_file) - # -f elif args.f: colors_plain = util.read_file_json(args.f) @@ -103,6 +98,10 @@ def process_args(args): # -i or -f if args.i or args.f: sequences.send_sequences(colors_plain, args.t) + + if not args.n: + wallpaper.set_wallpaper(colors_plain["wallpaper"]) + export.export_all_templates(colors_plain) reload.reload_env() diff --git a/pywal/export.py b/pywal/export.py index 5e7f2e6..9eea198 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -35,7 +35,9 @@ def export_all_templates(colors, template_dir=None, output_dir=CACHE_DIR): # Merge all colors (specials and normals) into one dict so we can access # their values simpler. - all_colors = {**colors["special"], **colors["colors"]} + all_colors = {"wallpaper": colors["wallpaper"], + **colors["special"], + **colors["colors"]} # Turn all those colors into util.Color instances for accessing the # .hex and .rgb formats diff --git a/pywal/magic.py b/pywal/magic.py index 3af10ce..0cc868a 100644 --- a/pywal/magic.py +++ b/pywal/magic.py @@ -75,7 +75,7 @@ def get_colors(img, quiet): # Generate the colors. colors = gen_colors(img) - colors = sort_colors(colors) + colors = sort_colors(img, colors) # Cache the colorscheme. util.save_file_json(colors, cache_file) @@ -87,27 +87,29 @@ def get_colors(img, quiet): return colors -def sort_colors(colors): +def sort_colors(img, colors): """Sort the generated colors and store them in a dict that we will later save in json format.""" raw_colors = colors[:1] + colors[9:] + colors[8:] + # Wallpaper. + colors = {"wallpaper": img} + # Special colors. colors_special = {} colors_special.update({"background": raw_colors[0]}) colors_special.update({"foreground": raw_colors[15]}) colors_special.update({"cursor": raw_colors[15]}) - # Colors 0-15 + # Colors 0-15. colors_hex = {} [colors_hex.update({f"color{index}": color}) # pylint: disable=W0106 for index, color in enumerate(raw_colors)] - # Color 8 + # Color 8. colors_hex["color8"] = util.set_grey(raw_colors) # Add the colors to a dict. - colors = {} colors["special"] = colors_special colors["colors"] = colors_hex diff --git a/pywal/templates/colors.css b/pywal/templates/colors.css index 04c2aa9..11e00d3 100644 --- a/pywal/templates/colors.css +++ b/pywal/templates/colors.css @@ -1,9 +1,14 @@ /* CSS variables Generated by 'wal' */ :root {{ + --wallpaper: "{wallpaper}"; + + /* Special */ --background: {background}; --foreground: {foreground}; --cursor: {cursor}; + + /* Colors */ --color0: {color0}; --color1: {color1}; --color2: {color2}; diff --git a/pywal/templates/colors.json b/pywal/templates/colors.json index fdd9828..5c94bc4 100644 --- a/pywal/templates/colors.json +++ b/pywal/templates/colors.json @@ -1,4 +1,6 @@ {{ + "wallpaper": "{wallpaper}", + "special": {{ "background": "{background}", "foreground": "{foreground}", diff --git a/pywal/templates/colors.scss b/pywal/templates/colors.scss index 1a2e183..001be1f 100644 --- a/pywal/templates/colors.scss +++ b/pywal/templates/colors.scss @@ -1,8 +1,13 @@ // SCSS Variables // Generated by 'wal' +$wallpaper: "{wallpaper}"; + +// Special $background: {background}; $foreground: {foreground}; $cursor: {cursor}; + +// Colors $color0: {color0}; $color1: {color1}; $color2: {color2}; diff --git a/pywal/templates/colors.sh b/pywal/templates/colors.sh index 607d19e..19b31c7 100644 --- a/pywal/templates/colors.sh +++ b/pywal/templates/colors.sh @@ -1,8 +1,13 @@ # Shell variables # Generated by 'wal' +wallpaper='{wallpaper}' + +# Special background='{background}' foreground='{foreground}' cursor='{cursor}' + +# Colors color0='{color0}' color1='{color1}' color2='{color2}' diff --git a/pywal/util.py b/pywal/util.py index 2796d8e..6c5b420 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -54,6 +54,11 @@ def read_file_json(input_file): """Read data from a json file.""" with open(input_file) as json_file: data = json.load(json_file) + + # If wallpaper is unset, set it to "None" + if "wallpaper" not in data: + data["wallpaper"] = "None" + return data diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 59f1aeb..5e524a3 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -82,6 +82,9 @@ def set_desktop_wallpaper(desktop, img): def set_wallpaper(img): """Set the wallpaper.""" + if not os.path.isfile(img): + return + desktop = get_desktop_env() if desktop: |
