2017-06-19 09:46:22 +02:00
|
|
|
|
#!/usr/bin/env python
|
2017-06-17 03:14:32 +02:00
|
|
|
|
"""
|
|
|
|
|
wal - Generate and change colorschemes on the fly.
|
|
|
|
|
Created by Dylan Araps
|
|
|
|
|
"""
|
2017-06-16 16:50:13 +02:00
|
|
|
|
import argparse
|
2017-06-17 03:48:02 +02:00
|
|
|
|
import glob
|
2017-06-16 16:59:55 +02:00
|
|
|
|
import os
|
2017-06-16 17:48:14 +02:00
|
|
|
|
import pathlib
|
2017-06-19 11:24:28 +02:00
|
|
|
|
import random
|
|
|
|
|
import re
|
|
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2017-06-17 03:14:32 +02:00
|
|
|
|
|
2017-06-16 16:59:55 +02:00
|
|
|
|
|
2017-06-19 05:08:22 +02:00
|
|
|
|
# wal files.
|
2017-06-19 09:20:17 +02:00
|
|
|
|
CACHE_DIR = "%s%s" % (os.path.expanduser("~"), "/.cache/wal/")
|
2017-06-19 05:08:22 +02:00
|
|
|
|
SCHEME_DIR = "%s%s" % (CACHE_DIR, "schemes/")
|
|
|
|
|
SEQUENCE_FILE = "%s%s" % (CACHE_DIR, "sequences")
|
|
|
|
|
WAL_FILE = "%s%s" % (CACHE_DIR, "wal")
|
|
|
|
|
PLAIN_FILE = "%s%s" % (CACHE_DIR, "colors")
|
|
|
|
|
XRDB_FILE = "%s%s" % (CACHE_DIR, "xcolors")
|
|
|
|
|
|
2017-06-16 16:59:55 +02:00
|
|
|
|
# Internal variables.
|
2017-06-17 03:14:32 +02:00
|
|
|
|
COLOR_COUNT = 16
|
2017-06-16 16:50:13 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# ARGS {{{
|
|
|
|
|
|
|
|
|
|
|
2017-06-16 16:50:13 +02:00
|
|
|
|
def get_args():
|
2017-06-17 03:14:32 +02:00
|
|
|
|
"""Get the script arguments."""
|
|
|
|
|
description = "wal - Generate colorschemes on the fly"
|
|
|
|
|
arg = argparse.ArgumentParser(description=description)
|
2017-06-16 16:50:27 +02:00
|
|
|
|
|
2017-06-17 03:14:32 +02:00
|
|
|
|
# Add the args.
|
|
|
|
|
arg.add_argument('-c', action='store_true',
|
|
|
|
|
help='Delete all cached colorschemes.')
|
2017-06-16 16:50:13 +02:00
|
|
|
|
|
2017-06-17 09:45:03 +02:00
|
|
|
|
arg.add_argument('-i', metavar='"/path/to/img.jpg"',
|
2017-06-17 03:14:32 +02:00
|
|
|
|
help='Which image or directory to use.')
|
|
|
|
|
|
2017-06-19 10:20:57 +02:00
|
|
|
|
arg.add_argument('-n', action='store_true',
|
|
|
|
|
help='Skip setting the wallpaper.')
|
2017-06-17 03:14:32 +02:00
|
|
|
|
|
2017-06-19 10:19:36 +02:00
|
|
|
|
arg.add_argument('-o', metavar='"script_name"',
|
|
|
|
|
help='External script to run after "wal".')
|
2017-06-17 03:14:32 +02:00
|
|
|
|
|
2017-06-19 11:24:28 +02:00
|
|
|
|
arg.add_argument('-q', action='store_true',
|
|
|
|
|
help='Quiet mode, don\'t print anything.')
|
2017-06-17 03:14:32 +02:00
|
|
|
|
|
|
|
|
|
arg.add_argument('-r', action='store_true',
|
|
|
|
|
help='Reload current colorscheme.')
|
|
|
|
|
|
|
|
|
|
arg.add_argument('-t', action='store_true',
|
|
|
|
|
help='Fix artifacts in VTE Terminals. \
|
|
|
|
|
(Termite, xfce4-terminal)')
|
|
|
|
|
|
|
|
|
|
return arg.parse_args()
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 11:33:36 +02:00
|
|
|
|
def process_args(args):
|
|
|
|
|
"""Process args"""
|
|
|
|
|
# If no args were passed.
|
|
|
|
|
if not len(sys.argv) > 1:
|
|
|
|
|
print("error: wal needs to be given arguments to run.")
|
|
|
|
|
print(" Refer to 'wal -h' for more info.")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
# -q
|
|
|
|
|
if args.q:
|
|
|
|
|
sys.stdout = open('/dev/null', 'w')
|
|
|
|
|
sys.stderr = open('/dev/null', 'w')
|
|
|
|
|
|
|
|
|
|
# -c
|
|
|
|
|
if args.c:
|
|
|
|
|
shutil.rmtree(SCHEME_DIR)
|
|
|
|
|
|
|
|
|
|
# -r
|
|
|
|
|
if args.r:
|
|
|
|
|
reload_colors(args.t)
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# RELOAD COLORS {{{
|
|
|
|
|
|
2017-06-19 04:01:36 +02:00
|
|
|
|
def reload_colors(vte):
|
2017-06-17 09:45:03 +02:00
|
|
|
|
"""Reload colors."""
|
2017-06-19 05:08:22 +02:00
|
|
|
|
with open(SEQUENCE_FILE) as file:
|
2017-06-17 09:45:03 +02:00
|
|
|
|
sequences = file.read()
|
|
|
|
|
|
2017-06-19 04:01:36 +02:00
|
|
|
|
# If vte mode was used, remove the problem sequence.
|
|
|
|
|
if vte:
|
|
|
|
|
sequences = re.sub(r'\]708;\#.{6}', '', sequences)
|
|
|
|
|
|
2017-06-17 09:45:03 +02:00
|
|
|
|
# Decode the string.
|
|
|
|
|
sequences = bytes(sequences, "utf-8").decode("unicode_escape")
|
|
|
|
|
|
|
|
|
|
print(sequences, end='')
|
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# COLORSCHEME GENERATION {{{
|
|
|
|
|
|
|
|
|
|
|
2017-06-17 03:14:32 +02:00
|
|
|
|
def get_image(img):
|
|
|
|
|
"""Validate image input."""
|
2017-06-19 09:20:17 +02:00
|
|
|
|
image = pathlib.Path(img)
|
2017-06-16 16:59:55 +02:00
|
|
|
|
|
2017-06-19 04:17:57 +02:00
|
|
|
|
# Check if the user has Imagemagick installed.
|
|
|
|
|
if not shutil.which("convert"):
|
|
|
|
|
print("error: imagemagick not found, exiting...")
|
|
|
|
|
print("error: wal requires imagemagick to function.")
|
|
|
|
|
exit(1)
|
|
|
|
|
|
2017-06-16 16:59:55 +02:00
|
|
|
|
if image.is_file():
|
2017-06-19 08:15:13 +02:00
|
|
|
|
wal_img = image
|
2017-06-16 17:48:14 +02:00
|
|
|
|
|
2017-06-17 03:14:32 +02:00
|
|
|
|
elif image.is_dir():
|
|
|
|
|
rand = random.choice(os.listdir(image))
|
2017-06-19 05:08:22 +02:00
|
|
|
|
rand_img = "%s/%s" % (str(image), rand)
|
2017-06-19 09:20:17 +02:00
|
|
|
|
rand_img = pathlib.Path(rand_img)
|
2017-06-16 17:48:14 +02:00
|
|
|
|
|
2017-06-17 03:14:32 +02:00
|
|
|
|
if rand_img.is_file():
|
2017-06-19 08:15:13 +02:00
|
|
|
|
wal_img = rand_img
|
|
|
|
|
|
|
|
|
|
print("image: Using image", wal_img)
|
|
|
|
|
return wal_img
|
2017-06-16 17:48:14 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-17 04:22:20 +02:00
|
|
|
|
def magic(color_count, img):
|
|
|
|
|
"""Call Imagemagick to generate a scheme."""
|
2017-06-19 09:20:17 +02:00
|
|
|
|
colors = subprocess.Popen(["convert", img, "+dither", "-colors",
|
|
|
|
|
str(color_count), "-unique-colors", "txt:-"],
|
|
|
|
|
stdout=subprocess.PIPE)
|
2017-06-17 04:22:20 +02:00
|
|
|
|
|
2017-06-19 06:09:09 +02:00
|
|
|
|
return colors.stdout.readlines()
|
2017-06-17 04:22:20 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-17 03:23:19 +02:00
|
|
|
|
def gen_colors(img):
|
|
|
|
|
"""Generate a color palette using imagemagick."""
|
2017-06-17 04:22:20 +02:00
|
|
|
|
# Generate initial scheme.
|
2017-06-19 06:09:09 +02:00
|
|
|
|
magic_output = magic(COLOR_COUNT, img)
|
2017-06-17 04:22:20 +02:00
|
|
|
|
|
|
|
|
|
# If imagemagick finds less than 16 colors, use a larger source number
|
|
|
|
|
# of colors.
|
|
|
|
|
index = 0
|
|
|
|
|
while len(magic_output) - 1 <= 15:
|
|
|
|
|
index += 1
|
2017-06-19 06:09:09 +02:00
|
|
|
|
magic_output = magic(COLOR_COUNT + index, img)
|
2017-06-17 04:22:20 +02:00
|
|
|
|
|
|
|
|
|
print("colors: Imagemagick couldn't generate a", COLOR_COUNT,
|
|
|
|
|
"color palette, trying a larger palette size",
|
|
|
|
|
COLOR_COUNT + index)
|
2017-06-16 17:48:14 +02:00
|
|
|
|
|
2017-06-17 03:14:32 +02:00
|
|
|
|
# Remove the first element, which isn't a color.
|
2017-06-19 09:31:24 +02:00
|
|
|
|
del magic_output[0]
|
2017-06-16 17:48:14 +02:00
|
|
|
|
|
2017-06-19 09:31:24 +02:00
|
|
|
|
# Create a list of hex colors.
|
|
|
|
|
colors = [re.search('#.{6}', str(col)).group(0) for col in magic_output]
|
2017-06-17 03:23:19 +02:00
|
|
|
|
return colors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_colors(img):
|
|
|
|
|
"""Generate a colorscheme using imagemagick."""
|
|
|
|
|
# Cache file.
|
2017-06-19 05:08:22 +02:00
|
|
|
|
cache_file = "%s%s" % (SCHEME_DIR, img.replace('/', '_'))
|
2017-06-19 09:20:17 +02:00
|
|
|
|
cache_file = pathlib.Path(cache_file)
|
2017-06-17 03:23:19 +02:00
|
|
|
|
|
2017-06-19 05:33:56 +02:00
|
|
|
|
# Cache the wallpaper name.
|
|
|
|
|
with open(WAL_FILE, 'w') as file:
|
|
|
|
|
file.write("%s\n" % (img))
|
|
|
|
|
|
2017-06-17 03:48:02 +02:00
|
|
|
|
if cache_file.is_file():
|
|
|
|
|
with open(cache_file) as file:
|
|
|
|
|
colors = file.readlines()
|
|
|
|
|
|
2017-06-19 09:31:24 +02:00
|
|
|
|
# Strip newlines from each list element.
|
2017-06-17 03:48:02 +02:00
|
|
|
|
colors = [x.strip() for x in colors]
|
|
|
|
|
else:
|
2017-06-19 09:31:24 +02:00
|
|
|
|
print("colors: Generating a colorscheme...")
|
|
|
|
|
|
2017-06-17 03:23:19 +02:00
|
|
|
|
# Generate the colors.
|
|
|
|
|
colors = gen_colors(img)
|
|
|
|
|
|
|
|
|
|
# Cache the colorscheme.
|
2017-06-19 05:33:56 +02:00
|
|
|
|
with open(cache_file, 'w') as file:
|
|
|
|
|
file.write("\n".join(colors))
|
2017-06-16 16:59:55 +02:00
|
|
|
|
|
2017-06-17 08:56:12 +02:00
|
|
|
|
print("colors: Generated colorscheme")
|
2017-06-17 03:48:02 +02:00
|
|
|
|
return colors
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# SEND SEQUENCES {{{
|
|
|
|
|
|
|
|
|
|
|
2017-06-17 08:56:12 +02:00
|
|
|
|
def set_special(index, color):
|
|
|
|
|
"""Build the escape sequence for special colors."""
|
2017-06-19 05:08:22 +02:00
|
|
|
|
return "\\033]%s;%s\\007" % (str(index), color)
|
2017-06-17 08:56:12 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-17 03:48:02 +02:00
|
|
|
|
def set_color(index, color):
|
|
|
|
|
"""Build the escape sequence we need for each color."""
|
2017-06-19 05:08:22 +02:00
|
|
|
|
return "\\033]4;%s;%s\\007" % (str(index), color)
|
2017-06-17 03:48:02 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-19 11:01:30 +02:00
|
|
|
|
def get_grey(colors):
|
2017-06-17 09:45:03 +02:00
|
|
|
|
"""Set a grey color based on brightness of color0"""
|
2017-06-19 09:46:22 +02:00
|
|
|
|
return {
|
|
|
|
|
0: "#666666",
|
|
|
|
|
1: "#666666",
|
|
|
|
|
2: "#757575",
|
|
|
|
|
3: "#999999",
|
|
|
|
|
4: "#999999",
|
|
|
|
|
5: "#8a8a8a",
|
|
|
|
|
6: "#a1a1a1",
|
|
|
|
|
7: "#a1a1a1",
|
|
|
|
|
8: "#a1a1a1",
|
|
|
|
|
9: "#a1a1a1",
|
2017-06-19 11:01:30 +02:00
|
|
|
|
}.get(int(colors[0][1]), colors[7])
|
2017-06-17 09:45:03 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-17 08:56:12 +02:00
|
|
|
|
def send_sequences(colors, vte):
|
2017-06-17 03:48:02 +02:00
|
|
|
|
"""Send colors to all open terminals."""
|
2017-06-19 05:08:22 +02:00
|
|
|
|
seq = []
|
|
|
|
|
seq.append(set_special(10, colors[15]))
|
|
|
|
|
seq.append(set_special(11, colors[0]))
|
|
|
|
|
seq.append(set_special(12, colors[15]))
|
|
|
|
|
seq.append(set_special(13, colors[15]))
|
|
|
|
|
seq.append(set_special(14, colors[0]))
|
2017-06-17 08:56:12 +02:00
|
|
|
|
|
|
|
|
|
# This escape sequence doesn't work in VTE terminals.
|
|
|
|
|
if not vte:
|
2017-06-19 05:08:22 +02:00
|
|
|
|
seq.append(set_special(708, colors[0]))
|
|
|
|
|
|
|
|
|
|
seq.append(set_color(0, colors[0]))
|
|
|
|
|
seq.append(set_color(1, colors[9]))
|
|
|
|
|
seq.append(set_color(2, colors[10]))
|
|
|
|
|
seq.append(set_color(3, colors[11]))
|
|
|
|
|
seq.append(set_color(4, colors[12]))
|
|
|
|
|
seq.append(set_color(5, colors[13]))
|
|
|
|
|
seq.append(set_color(6, colors[14]))
|
|
|
|
|
seq.append(set_color(7, colors[15]))
|
2017-06-19 11:01:30 +02:00
|
|
|
|
seq.append(set_color(8, get_grey(colors)))
|
2017-06-19 05:08:22 +02:00
|
|
|
|
seq.append(set_color(9, colors[9]))
|
|
|
|
|
seq.append(set_color(10, colors[10]))
|
|
|
|
|
seq.append(set_color(11, colors[11]))
|
|
|
|
|
seq.append(set_color(12, colors[12]))
|
|
|
|
|
seq.append(set_color(13, colors[13]))
|
|
|
|
|
seq.append(set_color(14, colors[14]))
|
|
|
|
|
seq.append(set_color(15, colors[15]))
|
2017-06-17 03:48:02 +02:00
|
|
|
|
|
|
|
|
|
# Set a blank color that isn't affected by bold highlighting.
|
2017-06-19 05:08:22 +02:00
|
|
|
|
seq.append(set_color(66, colors[0]))
|
|
|
|
|
|
|
|
|
|
# Create the string.
|
|
|
|
|
sequences = ''.join(seq)
|
2017-06-17 03:48:02 +02:00
|
|
|
|
|
|
|
|
|
# Decode the string.
|
|
|
|
|
sequences = bytes(sequences, "utf-8").decode("unicode_escape")
|
|
|
|
|
|
2017-06-17 04:22:20 +02:00
|
|
|
|
# Send the sequences to all open terminals.
|
2017-06-17 03:48:02 +02:00
|
|
|
|
for term in glob.glob("/dev/pts/[0-9]*"):
|
2017-06-19 05:33:56 +02:00
|
|
|
|
with open(term, 'w') as file:
|
|
|
|
|
file.write(sequences)
|
2017-06-17 03:48:02 +02:00
|
|
|
|
|
2017-06-17 10:16:10 +02:00
|
|
|
|
# Cache the sequences.
|
2017-06-19 05:33:56 +02:00
|
|
|
|
with open(SEQUENCE_FILE, 'w') as file:
|
|
|
|
|
file.write(sequences)
|
2017-06-17 10:16:10 +02:00
|
|
|
|
|
2017-06-17 08:56:12 +02:00
|
|
|
|
print("colors: Set terminal colors")
|
|
|
|
|
|
2017-06-16 16:59:55 +02:00
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# WALLPAPER SETTING {{{
|
|
|
|
|
|
|
|
|
|
|
2017-06-17 04:31:53 +02:00
|
|
|
|
def set_wallpaper(img):
|
|
|
|
|
"""Set the wallpaper."""
|
2017-06-19 11:01:30 +02:00
|
|
|
|
uname = os.uname
|
|
|
|
|
|
2017-06-17 04:31:53 +02:00
|
|
|
|
if shutil.which("feh"):
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["feh", "--bg-fill", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
elif shutil.which("nitrogen"):
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["nitrogen", "--set-zoom-fill", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
elif shutil.which("bgs"):
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["bgs", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
elif shutil.which("hsetroot"):
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["hsetroot", "-fill", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
elif shutil.which("habak"):
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["habak", "-mS", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
2017-06-19 11:01:30 +02:00
|
|
|
|
elif uname == "Darwin":
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["osascript", "-e", "'tell application \"Finder\" to set \
|
|
|
|
|
desktop picture to POSIX file\'" + img + "\'"])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
else:
|
2017-06-19 09:20:17 +02:00
|
|
|
|
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.background",
|
|
|
|
|
"picture-uri", img])
|
2017-06-17 04:31:53 +02:00
|
|
|
|
|
|
|
|
|
print("wallpaper: Set the new wallpaper")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# EXPORT COLORS {{{
|
|
|
|
|
|
|
|
|
|
|
2017-06-17 09:02:47 +02:00
|
|
|
|
def export_plain(colors):
|
|
|
|
|
"""Export colors to a plain text file."""
|
2017-06-19 05:33:56 +02:00
|
|
|
|
with open(PLAIN_FILE, 'w') as file:
|
|
|
|
|
file.write('\n'.join(colors))
|
2017-06-17 09:45:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def export_xrdb(colors):
|
|
|
|
|
"""Export colors to xrdb."""
|
2017-06-19 05:08:22 +02:00
|
|
|
|
x_colors = """
|
|
|
|
|
URxvt*foreground: %s
|
|
|
|
|
XTerm*forefround: %s
|
|
|
|
|
URxvt*background: %s
|
|
|
|
|
XTerm*background: %s
|
|
|
|
|
URxvt*cursorColor: %s
|
|
|
|
|
XTerm*cursorColor: %s
|
|
|
|
|
*.color0: %s
|
|
|
|
|
*.color1: %s
|
|
|
|
|
*.color2: %s
|
|
|
|
|
*.color3: %s
|
|
|
|
|
*.color4: %s
|
|
|
|
|
*.color5: %s
|
|
|
|
|
*.color6: %s
|
|
|
|
|
*.color7: %s
|
|
|
|
|
*.color8: %s
|
|
|
|
|
*.color9: %s
|
|
|
|
|
*.color10: %s
|
|
|
|
|
*.color11: %s
|
|
|
|
|
*.color12: %s
|
|
|
|
|
*.color13: %s
|
|
|
|
|
*.color14: %s
|
|
|
|
|
*.color15: %s
|
|
|
|
|
""" % (colors[15],
|
|
|
|
|
colors[15],
|
|
|
|
|
colors[0],
|
|
|
|
|
colors[0],
|
|
|
|
|
colors[15],
|
|
|
|
|
colors[15],
|
|
|
|
|
colors[0],
|
|
|
|
|
colors[9],
|
|
|
|
|
colors[10],
|
|
|
|
|
colors[11],
|
|
|
|
|
colors[12],
|
|
|
|
|
colors[13],
|
|
|
|
|
colors[14],
|
|
|
|
|
colors[15],
|
2017-06-19 11:01:30 +02:00
|
|
|
|
get_grey(colors),
|
2017-06-19 05:08:22 +02:00
|
|
|
|
colors[9],
|
|
|
|
|
colors[10],
|
|
|
|
|
colors[11],
|
|
|
|
|
colors[12],
|
|
|
|
|
colors[13],
|
|
|
|
|
colors[14],
|
|
|
|
|
colors[15])
|
|
|
|
|
|
2017-06-19 05:33:56 +02:00
|
|
|
|
# Write the colors to the file.
|
|
|
|
|
with open(XRDB_FILE, 'w') as file:
|
|
|
|
|
file.write(x_colors)
|
2017-06-17 09:45:03 +02:00
|
|
|
|
|
|
|
|
|
# Merge the colors into the X db so new terminals use them.
|
2017-06-19 09:31:24 +02:00
|
|
|
|
subprocess.Popen(["xrdb", "-merge", XRDB_FILE])
|
2017-06-17 09:45:03 +02:00
|
|
|
|
|
|
|
|
|
print("export: Exported xrdb colors.")
|
2017-06-17 09:02:47 +02:00
|
|
|
|
|
|
|
|
|
|
2017-06-19 04:15:35 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
|
2017-06-16 16:50:13 +02:00
|
|
|
|
def main():
|
2017-06-17 03:14:32 +02:00
|
|
|
|
"""Main script function."""
|
2017-06-19 11:01:30 +02:00
|
|
|
|
# Get the args.
|
2017-06-16 16:50:13 +02:00
|
|
|
|
args = get_args()
|
2017-06-19 11:33:36 +02:00
|
|
|
|
process_args(args)
|
2017-06-19 10:19:36 +02:00
|
|
|
|
|
2017-06-19 11:01:30 +02:00
|
|
|
|
# Create colorscheme dir.
|
|
|
|
|
pathlib.Path(SCHEME_DIR).mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
2017-06-19 10:19:36 +02:00
|
|
|
|
# -i
|
2017-06-19 04:01:36 +02:00
|
|
|
|
if args.i:
|
|
|
|
|
image = str(get_image(args.i))
|
2017-06-17 03:23:19 +02:00
|
|
|
|
|
2017-06-19 04:01:36 +02:00
|
|
|
|
# Get the colors.
|
|
|
|
|
colors = get_colors(image)
|
2017-06-17 09:45:03 +02:00
|
|
|
|
|
2017-06-19 05:08:22 +02:00
|
|
|
|
# Set the wallpaper.
|
2017-06-19 10:20:57 +02:00
|
|
|
|
if not args.n:
|
|
|
|
|
set_wallpaper(image)
|
2017-06-19 05:08:22 +02:00
|
|
|
|
|
2017-06-19 04:01:36 +02:00
|
|
|
|
# Set the colors.
|
|
|
|
|
send_sequences(colors, args.t)
|
|
|
|
|
export_plain(colors)
|
|
|
|
|
export_xrdb(colors)
|
2017-06-17 03:48:02 +02:00
|
|
|
|
|
2017-06-19 10:19:36 +02:00
|
|
|
|
# -o
|
|
|
|
|
if args.o:
|
|
|
|
|
subprocess.Popen(["nohup", args.o],
|
|
|
|
|
stdout=open('/dev/null', 'w'),
|
|
|
|
|
stderr=open('/dev/null', 'w'),
|
|
|
|
|
preexec_fn=os.setpgrp)
|
|
|
|
|
|
2017-06-16 16:50:13 +02:00
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main()
|