summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-19 19:48:01 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-19 19:48:01 +1000
commitd81e17945ad98aea0be696deaa44030a7e5937fb (patch)
treed15e18c1c7ecd6d595ce66a4ac3ee62e8b1ce6dd
parent61116b31da9f366456de21f55b5289dcb670e96d (diff)
Args: Added -f
-rwxr-xr-xwal.py64
1 files changed, 50 insertions, 14 deletions
diff --git a/wal.py b/wal.py
index 271c9aa..5412f60 100755
--- a/wal.py
+++ b/wal.py
@@ -41,6 +41,9 @@ def get_args():
arg.add_argument('-i', metavar='"/path/to/img.jpg"',
help='Which image or directory to use.')
+ arg.add_argument('-f', metavar='"/path/to/colors"',
+ help='Load colors directly from a colorscheme file.')
+
arg.add_argument('-n', action='store_true',
help='Skip setting the wallpaper.')
@@ -85,8 +88,49 @@ def process_args(args):
# }}}
+# PROCESS COLORS {{{
+
+
+def process_colors(args):
+ """Process colors."""
+ # -i
+ if args.i:
+ image = str(get_image(args.i))
+
+ # Get the colors.
+ colors = get_colors(image)
+
+ # Set the wallpaper.
+ if not args.n:
+ set_wallpaper(image)
+ # -f
+ elif args.f:
+ cache_file = pathlib.Path(args.f)
+
+ # Import the colorscheme from file.
+ if cache_file.is_file():
+ with open(cache_file) as file:
+ colors = file.readlines()
+
+ # Strip newlines from each list element.
+ colors = [x.strip() for x in colors]
+
+ if len(colors) < 16:
+ print("error: Invalid colorscheme file chosen.")
+ exit(1)
+ else:
+ print("error: Colorscheme file not found.")
+ exit(1)
+
+ return colors
+
+
+# }}}
+
+
# RELOAD COLORS {{{
+
def reload_colors(vte):
"""Reload colors."""
with open(SEQUENCE_FILE) as file:
@@ -399,21 +443,13 @@ def main():
# Create colorscheme dir.
pathlib.Path(SCHEME_DIR).mkdir(parents=True, exist_ok=True)
- # -i
- if args.i:
- image = str(get_image(args.i))
-
- # Get the colors.
- colors = get_colors(image)
-
- # Set the wallpaper.
- if not args.n:
- set_wallpaper(image)
+ # Get the colors.
+ colors = process_colors(args)
- # Set the colors.
- send_sequences(colors, args.t)
- export_plain(colors)
- export_xrdb(colors)
+ # Set the colors.
+ send_sequences(colors, args.t)
+ export_plain(colors)
+ export_xrdb(colors)
# -o
if args.o: