Merge pull request #93 from dylanaraps/windows

OS: Added support for Windows
This commit is contained in:
Dylan Araps 2017-08-26 09:15:58 +10:00 committed by GitHub
commit 7b86945775
6 changed files with 27 additions and 7 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ subprocess
re
build/*
.coverage
.vscode/*

View File

@ -13,7 +13,12 @@ from . import util
def imagemagick(color_count, img):
"""Call Imagemagick to generate a scheme."""
colors = subprocess.Popen(["convert", img, "-resize", "25%",
if shutil.which("magick"):
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)
@ -84,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):

View File

@ -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()

View File

@ -16,8 +16,8 @@ import platform
__version__ = "0.6.6"
HOME = os.environ["HOME"]
CACHE_DIR = os.path.join(HOME, ".cache/wal/")
HOME = os.getenv("HOME", os.getenv("USERPROFILE"))
CACHE_DIR = os.path.join(HOME, ".cache", "wal")
MODULE_DIR = os.path.dirname(__file__)
COLOR_COUNT = 16
OS = platform.uname()[0]

View File

@ -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):

View File

@ -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)