diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-06-22 22:35:19 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-06-22 22:35:19 +1000 |
| commit | d5b93ac9eec3fd3b9a0e9a072867ad4839cc5221 (patch) | |
| tree | f078ddca91dab1681946c1ebe34178ae9359048c | |
| parent | d01e287719b0c7d81ffd1cbf58c14cf033f4fafb (diff) | |
General: Display a notification to show the user progress.
| -rwxr-xr-x | wal | 37 |
1 files changed, 26 insertions, 11 deletions
@@ -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) @@ -223,7 +231,9 @@ def get_colors(img): # Cache the colorscheme. save_file("\n".join(colors), cache_file) - print("colors: Generated colorscheme") + 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) + + # }}} |
