From f50cac635e3e7cb55bd0898985dea1b048120263 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 19:39:47 +1000 Subject: [PATCH 1/7] OS: Added support for Windows --- .gitignore | 1 + pywal/colors.py | 2 +- pywal/reload.py | 2 +- pywal/settings.py | 2 +- pywal/util.py | 3 +-- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f126d42..caa6570 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ subprocess re build/* .coverage +.vscode/* \ No newline at end of file diff --git a/pywal/colors.py b/pywal/colors.py index fd233c5..dd190e9 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -13,7 +13,7 @@ from . import util def imagemagick(color_count, img): """Call Imagemagick to generate a scheme.""" - colors = subprocess.Popen(["convert", img, "-resize", "25%", + colors = subprocess.Popen(["magick", "convert", img, "-resize", "25%", "+dither", "-colors", str(color_count), "-unique-colors", "txt:-"], stdout=subprocess.PIPE) diff --git a/pywal/reload.py b/pywal/reload.py index b16aec1..41283eb 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -15,7 +15,7 @@ def xrdb(xrdb_file=None): """Merge the colors into the X db so new terminals use them.""" xrdb_file = xrdb_file or os.path.join(CACHE_DIR, "colors.Xresources") - if shutil.which("xrdb") or OS != "Darwin": + if shutil.which("xrdb") and OS != "Darwin": subprocess.Popen(["xrdb", "-merge", xrdb_file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).wait() diff --git a/pywal/settings.py b/pywal/settings.py index ce06347..b4ad3a5 100644 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -16,7 +16,7 @@ import platform __version__ = "0.6.6" -HOME = os.environ["HOME"] +HOME = os.getenv("HOME", os.getenv("USERPROFILE")) CACHE_DIR = os.path.join(HOME, ".cache/wal/") MODULE_DIR = os.path.dirname(__file__) COLOR_COUNT = 16 diff --git a/pywal/util.py b/pywal/util.py index 55be6c2..894c049 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -113,8 +113,7 @@ def disown(cmd): disown it and hide it's output.""" subprocess.Popen(["nohup", *cmd], stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - preexec_fn=os.setpgrp) + stderr=subprocess.DEVNULL) def msg(input_msg, notify): From 2c4e17a19786e392e9ab09a80f6e77799ef59562 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 19:41:02 +1000 Subject: [PATCH 2/7] OS: Added support for Windows --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index caa6570..ec96c46 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ subprocess re build/* .coverage -.vscode/* \ No newline at end of file +.vscode/* From 3c7b0fd8409d41467b4591bd557f14d812f1de16 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 19:48:19 +1000 Subject: [PATCH 3/7] colors: Use separate command on Windows --- pywal/colors.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index dd190e9..f6f77bf 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -7,13 +7,18 @@ import shutil import subprocess import sys -from .settings import CACHE_DIR, COLOR_COUNT +from .settings import CACHE_DIR, COLOR_COUNT, OS from . import util def imagemagick(color_count, img): """Call Imagemagick to generate a scheme.""" - colors = subprocess.Popen(["magick", "convert", img, "-resize", "25%", + if OS == "Windows": + magick_command = ["magick", "convert"] + else: + magick_command = ["convert"] + + colors = subprocess.Popen([*magick_command, img, "-resize", "25%", "+dither", "-colors", str(color_count), "-unique-colors", "txt:-"], stdout=subprocess.PIPE) From 8d0e3d4ed4685d68be501461cf8b687a654996da Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 19:53:55 +1000 Subject: [PATCH 4/7] general: Fix linux specific path --- pywal/colors.py | 2 +- pywal/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pywal/colors.py b/pywal/colors.py index f6f77bf..b5ec418 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -89,7 +89,7 @@ def get(img, cache_dir=CACHE_DIR, color_count=COLOR_COUNT, notify=False): """Get the colorscheme.""" # _home_dylan_img_jpg.json - cache_file = img.replace("/", "_").replace(".", "_") + cache_file = img.replace("/", "_").replace("\\", "_").replace(".", "_") cache_file = os.path.join(cache_dir, "schemes", cache_file + ".json") if os.path.isfile(cache_file): diff --git a/pywal/settings.py b/pywal/settings.py index b4ad3a5..4aec9a7 100644 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -17,7 +17,7 @@ __version__ = "0.6.6" HOME = os.getenv("HOME", os.getenv("USERPROFILE")) -CACHE_DIR = os.path.join(HOME, ".cache/wal/") +CACHE_DIR = os.path.join(HOME, ".cache", "wal") MODULE_DIR = os.path.dirname(__file__) COLOR_COUNT = 16 OS = platform.uname()[0] From 6b5e65fc429ba7173cab7f1862c63c853d80411d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 20:07:09 +1000 Subject: [PATCH 5/7] wallpaper: Added support for Windows. --- pywal/wallpaper.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 06dde63..6d407cd 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -1,4 +1,5 @@ """Set the wallpaper.""" +import ctypes import os import shutil import subprocess @@ -95,6 +96,17 @@ def set_mac_wallpaper(img): subprocess.call(["killall", "Dock"]) +def set_win_wallpaper(img): + """Set the wallpaper on Windows.""" + # There's a different command depending on the architecture + # of Windows. We check the PROGRAMFILES envar since using + # platform is unreliable. + if "x86" in os.environ["PROGRAMFILES"]: + ctypes.windll.user32.SystemParametersInfoW(20, 0, img, 3) + else: + ctypes.windll.user32.SystemParametersInfoA(20, 0, img, 3) + + def change(img): """Set the wallpaper.""" if not os.path.isfile(img): @@ -105,6 +117,9 @@ def change(img): if OS == "Darwin": set_mac_wallpaper(img) + elif OS == "Windows": + set_win_wallpaper(img) + elif desktop: set_desktop_wallpaper(desktop, img) From 9bca288ce9cafae9f902d30d58c6b7ecab14bbb4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 20:12:17 +1000 Subject: [PATCH 6/7] colors: Don't hardcode command to Windows --- pywal/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywal/colors.py b/pywal/colors.py index b5ec418..34500c8 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -13,7 +13,7 @@ from . import util def imagemagick(color_count, img): """Call Imagemagick to generate a scheme.""" - if OS == "Windows": + if shutil.which("magick"): magick_command = ["magick", "convert"] else: magick_command = ["convert"] From b4b3c4ca4c975a93eab2e4da9fb50456b6bed77b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 25 Aug 2017 20:15:47 +1000 Subject: [PATCH 7/7] colors: Remove unused import. --- pywal/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pywal/colors.py b/pywal/colors.py index 34500c8..9984b6e 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -7,7 +7,7 @@ import shutil import subprocess import sys -from .settings import CACHE_DIR, COLOR_COUNT, OS +from .settings import CACHE_DIR, COLOR_COUNT from . import util