change --nine to --cols16 restore old behaviour

now the default behaviour is 9 colors again, and 16 colors is a flag
This commit is contained in:
eylles 2022-02-20 05:16:09 -06:00
parent 558b7e2796
commit 34e2dd28ab
No known key found for this signature in database
GPG Key ID: 87BB13678A662E19
7 changed files with 43 additions and 45 deletions

View File

@ -53,8 +53,8 @@ def get_args():
"flag is used: Go through the images in order " "flag is used: Go through the images in order "
"instead of shuffled.") "instead of shuffled.")
arg.add_argument("--nine", action="store_true", arg.add_argument("--cols16", action="store_true",
help="Use 9 color output. ") help="Use 16 color output. ")
arg.add_argument("--recursive", action="store_true", arg.add_argument("--recursive", action="store_true",
help="When pywal is given a directory as input and this " help="When pywal is given a directory as input and this "
@ -178,7 +178,7 @@ def parse_args(parser):
if args.i: if args.i:
image_file = image.get(args.i, iterative=args.iterative, image_file = image.get(args.i, iterative=args.iterative,
recursive=args.recursive) recursive=args.recursive)
colors_plain = colors.get(image_file, args.l, args.nine, args.backend, colors_plain = colors.get(image_file, args.l, args.cols16, args.backend,
sat=args.saturate) sat=args.saturate)
if args.theme: if args.theme:
@ -189,7 +189,7 @@ def parse_args(parser):
if args.w: if args.w:
cached_wallpaper = util.read_file(os.path.join(CACHE_DIR, "wal")) cached_wallpaper = util.read_file(os.path.join(CACHE_DIR, "wal"))
colors_plain = colors.get(cached_wallpaper[0], args.l, args.nine, args.backend, colors_plain = colors.get(cached_wallpaper[0], args.l, args.cols16, args.backend,
sat=args.saturate) sat=args.saturate)
if args.b: if args.b:

View File

@ -37,15 +37,15 @@ def gen_colors(img):
return [util.rgb_to_hex(color) for color in raw_colors] return [util.rgb_to_hex(color) for color in raw_colors]
def adjust(cols, light, nine): def adjust(cols, light, cols16):
"""Create palette.""" """Create palette."""
cols.sort(key=util.rgb_to_yiq) cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols] raw_colors = [*cols, *cols]
return colors.generic_adjust(raw_colors, light, nine) return colors.generic_adjust(raw_colors, light, cols16)
def get(img, light=False, nine=False): def get(img, light=False, cols16=False):
"""Get colorscheme.""" """Get colorscheme."""
cols = gen_colors(img) cols = gen_colors(img)
return adjust(cols, light, nine) return adjust(cols, light, cols16)

View File

@ -23,15 +23,15 @@ def gen_colors(img):
return [util.rgb_to_hex([*color[0]]) for color in raw_colors] return [util.rgb_to_hex([*color[0]]) for color in raw_colors]
def adjust(cols, light, nine): def adjust(cols, light, cols16):
"""Create palette.""" """Create palette."""
raw_colors = [cols[0], *cols, "#FFFFFF", raw_colors = [cols[0], *cols, "#FFFFFF",
"#000000", *cols, "#FFFFFF"] "#000000", *cols, "#FFFFFF"]
return colors.generic_adjust(raw_colors, light, nine) return colors.generic_adjust(raw_colors, light, cols16)
def get(img, light=False, nine=False): def get(img, light=False, cols16=False):
"""Get colorscheme.""" """Get colorscheme."""
cols = gen_colors(img) cols = gen_colors(img)
@ -40,4 +40,4 @@ def get(img, light=False, nine=False):
logging.error("Try another backend or another image. (wal --backend)") logging.error("Try another backend or another image. (wal --backend)")
sys.exit(1) sys.exit(1)
return adjust(cols, light, nine) return adjust(cols, light, cols16)

View File

@ -22,16 +22,16 @@ def gen_colors(img):
return [util.rgb_to_hex(col[1]) for col in palette] return [util.rgb_to_hex(col[1]) for col in palette]
def adjust(cols, light, nine): def adjust(cols, light, cols16):
"""Create palette.""" """Create palette."""
cols.sort(key=util.rgb_to_yiq) cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols] raw_colors = [*cols, *cols]
raw_colors[0] = util.lighten_color(cols[0], 0.40) raw_colors[0] = util.lighten_color(cols[0], 0.40)
return colors.generic_adjust(raw_colors, light, nine) return colors.generic_adjust(raw_colors, light, cols16)
def get(img, light=False, nine=False): def get(img, light=False, cols16=False):
"""Get colorscheme.""" """Get colorscheme."""
cols = gen_colors(img) cols = gen_colors(img)
return adjust(cols, light, nine) return adjust(cols, light, cols16)

View File

@ -16,15 +16,15 @@ def gen_colors(img):
return subprocess.check_output([*cmd, img]).splitlines() return subprocess.check_output([*cmd, img]).splitlines()
def adjust(cols, light, nine): def adjust(cols, light, cols16):
"""Create palette.""" """Create palette."""
cols.sort(key=util.rgb_to_yiq) cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols[8:], *cols[8:]] raw_colors = [*cols[8:], *cols[8:]]
return colors.generic_adjust(raw_colors, light, nine) return colors.generic_adjust(raw_colors, light, cols16)
def get(img, light=False, nine=False): def get(img, light=False, cols16=False):
"""Get colorscheme.""" """Get colorscheme."""
if not shutil.which("schemer2"): if not shutil.which("schemer2"):
logging.error("Schemer2 wasn't found on your system.") logging.error("Schemer2 wasn't found on your system.")
@ -32,4 +32,4 @@ def get(img, light=False, nine=False):
sys.exit(1) sys.exit(1)
cols = [col.decode('UTF-8') for col in gen_colors(img)] cols = [col.decode('UTF-8') for col in gen_colors(img)]
return adjust(cols, light, nine) return adjust(cols, light, cols16)

View File

@ -55,15 +55,15 @@ def gen_colors(img):
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]]
def adjust(cols, light, nine): def adjust(cols, light, cols16):
"""Adjust the generated colors and store them in a dict that """Adjust the generated colors and store them in a dict that
we will later save in json format.""" we will later save in json format."""
raw_colors = cols[:1] + cols[8:16] + cols[8:-1] raw_colors = cols[:1] + cols[8:16] + cols[8:-1]
return colors.generic_adjust(raw_colors, light, nine) return colors.generic_adjust(raw_colors, light, cols16)
def get(img, light=False, nine=False): def get(img, light=False, cols16=False):
"""Get colorscheme.""" """Get colorscheme."""
colors = gen_colors(img) colors = gen_colors(img)
return adjust(colors, light, nine) return adjust(colors, light, cols16)

View File

@ -60,21 +60,14 @@ def colors_to_dict(colors, img):
} }
def generic_adjust(colors, light, nine): def generic_adjust(colors, light, cols16):
"""Generic color adjustment for themers.""" """Generic color adjustment for themers."""
if light: if light:
for color in colors: for color in colors:
color = util.saturate_color(color, 0.60) color = util.saturate_color(color, 0.60)
color = util.darken_color(color, 0.5) color = util.darken_color(color, 0.5)
if nine: if cols16:
colors[0] = util.lighten_color(colors[0], 0.95)
colors[7] = util.darken_color(colors[0], 0.75)
colors[8] = util.darken_color(colors[0], 0.25)
colors[15] = colors[7]
else:
colors[0] = util.lighten_color(colors[0], 0.95) colors[0] = util.lighten_color(colors[0], 0.95)
colors[7] = util.darken_color(colors[0], 0.50) colors[7] = util.darken_color(colors[0], 0.50)
colors[8] = util.darken_color(colors[0], 0.25) colors[8] = util.darken_color(colors[0], 0.25)
@ -86,15 +79,14 @@ def generic_adjust(colors, light, nine):
colors[6] = util.darken_color(colors[6], 0.25) colors[6] = util.darken_color(colors[6], 0.25)
colors[15] = util.darken_color(colors[0], 0.75) colors[15] = util.darken_color(colors[0], 0.75)
else: else:
if nine: colors[0] = util.lighten_color(colors[0], 0.95)
colors[0] = util.darken_color(colors[0], 0.80) colors[7] = util.darken_color(colors[0], 0.75)
colors[7] = util.lighten_color(colors[0], 0.75) colors[8] = util.darken_color(colors[0], 0.25)
colors[8] = util.lighten_color(colors[0], 0.25)
colors[15] = colors[7] colors[15] = colors[7]
else: else:
if cols16:
colors[0] = util.darken_color(colors[0], 0.80) colors[0] = util.darken_color(colors[0], 0.80)
colors[7] = util.lighten_color(colors[0], 0.50) colors[7] = util.lighten_color(colors[0], 0.50)
colors[8] = util.lighten_color(colors[0], 0.25) colors[8] = util.lighten_color(colors[0], 0.25)
@ -106,6 +98,12 @@ def generic_adjust(colors, light, nine):
colors[6] = util.darken_color(colors[6], 0.25) colors[6] = util.darken_color(colors[6], 0.25)
colors[15] = util.lighten_color(colors[0], 0.75) colors[15] = util.lighten_color(colors[0], 0.75)
else:
colors[0] = util.darken_color(colors[0], 0.80)
colors[7] = util.lighten_color(colors[0], 0.75)
colors[8] = util.lighten_color(colors[0], 0.25)
colors[15] = colors[7]
return colors return colors
@ -120,10 +118,10 @@ def saturate_colors(colors, amount):
return colors return colors
def cache_fname(img, backend, nine, light, cache_dir, sat=""): def cache_fname(img, backend, cols16, light, cache_dir, sat=""):
"""Create the cache file name.""" """Create the cache file name."""
color_type = "light" if light else "dark" color_type = "light" if light else "dark"
color_num = "9" if nine else "16" color_num = "9" if cols16 else "16"
file_name = re.sub("[/|\\|.]", "_", img) file_name = re.sub("[/|\\|.]", "_", img)
file_size = os.path.getsize(img) file_size = os.path.getsize(img)
@ -156,10 +154,10 @@ def palette():
print("\n") print("\n")
def get(img, light=False, nine=False, backend="wal", cache_dir=CACHE_DIR, sat=""): def get(img, light=False, cols16=False, backend="wal", cache_dir=CACHE_DIR, sat=""):
"""Generate a palette.""" """Generate a palette."""
# home_dylan_img_jpg_backend_1.2.2.json # home_dylan_img_jpg_backend_1.2.2.json
cache_name = cache_fname(img, backend, nine, light, cache_dir, sat) cache_name = cache_fname(img, backend, cols16, light, cache_dir, sat)
cache_file = os.path.join(*cache_name) cache_file = os.path.join(*cache_name)
if os.path.isfile(cache_file): if os.path.isfile(cache_file):
@ -181,7 +179,7 @@ def get(img, light=False, nine=False, backend="wal", cache_dir=CACHE_DIR, sat=""
logging.info("Using %s backend.", backend) logging.info("Using %s backend.", backend)
backend = sys.modules["pywal.backends.%s" % backend] backend = sys.modules["pywal.backends.%s" % backend]
colors = getattr(backend, "get")(img, light, nine) colors = getattr(backend, "get")(img, light, cols16)
colors = colors_to_dict(saturate_colors(colors, sat), img) colors = colors_to_dict(saturate_colors(colors, sat), img)
util.save_file_json(colors, cache_file) util.save_file_json(colors, cache_file)