General: Display a notification to show the user progress.
@@ -13,10 +13,8 @@ import subprocess
import sys
-__version__ = "0.1"
-
-
# Internal variables.
+VERSION = "0.1"
COLOR_COUNT = 16
CACHE_DIR = pathlib.Path.home() / ".cache/wal/"
@@ -36,6 +34,12 @@ class ColorType(object):
]
+# pylint: disable=too-few-public-methods
+class Args(object):
+ """Store args."""
+ notify = True
+
+
# ARGS {{{
@@ -58,7 +62,8 @@ def get_args():
help="External script to run after \"wal\".")
arg.add_argument("-q", action="store_true",
- help="Quiet mode, don\"t print anything.")
+ help="Quiet mode, don\"t print anything and \
+ don't display notifications.")
arg.add_argument("-r", action="store_true",
help="Reload current colorscheme.")
@@ -84,6 +89,7 @@ def process_args(args):
# -q
if args.q:
sys.stdout = sys.stderr = open(os.devnull, "w")
+ Args.notify = False
# -c
if args.c:
@@ -96,7 +102,7 @@ def process_args(args):
# -v
if args.v:
- print(f"wal {__version__}")
+ print(f"wal {VERSION}")
exit(0)
# -i
@@ -212,9 +218,11 @@ def get_colors(img):
if cache_file.is_file():
colors = read_file(cache_file)
+ print("colors: Found cached colorscheme.")
else:
print("colors: Generating a colorscheme...")
+ notify("wal: Generating a colorscheme...")
# Generate the colors.
colors = gen_colors(img)
@@ -224,6 +232,8 @@ def get_colors(img):
save_file("\n".join(colors), cache_file)
print("colors: Generated colorscheme")
+ notify("wal: Generation complete.")
+
return colors
@@ -400,11 +410,7 @@ def set_wallpaper(img):
set_desktop_wallpaper(desktop, img)
else:
- if os.uname == "Darwin":
- subprocess.Popen(["osascript", "-e", "\"tell application \"Finder\" to set \
- desktop picture to POSIX file\"" + img + "\""])
-
- elif shutil.which("feh"):
+ if shutil.which("feh"):
subprocess.Popen(["feh", "--bg-fill", img])
elif shutil.which("nitrogen"):
@@ -557,6 +563,15 @@ def fix_escape(string):
return bytes(string, "utf-8").decode("unicode_escape")
+def notify(msg):
+ """Send arguements to notify-send."""
+ if shutil.which("notify-send") and Args.notify:
+ subprocess.Popen(["notify-send", msg],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ preexec_fn=os.setpgrp)
+
+
# }}}
