colors: Add light theme support.

This commit is contained in:
Dylan Araps 2018-02-02 19:32:30 +11:00
parent 059eeecfcd
commit 69604342a1
3 changed files with 52 additions and 18 deletions

View File

@ -48,6 +48,9 @@ def get_args(args):
arg.add_argument("-g", action="store_true",
help="Generate an oomox theme.")
arg.add_argument("-l", action="store_true",
help="Generate a light colorscheme.")
arg.add_argument("-n", action="store_true",
help="Skip setting the wallpaper.")
@ -118,7 +121,7 @@ def process_args(args):
if args.i:
image_file = image.get(args.i)
colors_plain = colors.get(image_file, notify=not args.q)
colors_plain = colors.get(image_file, light=args.l, notify=not args.q)
if args.f:
colors_plain = colors.file(args.f)

View File

@ -56,34 +56,54 @@ def gen_colors(img, color_count):
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]]
def create_palette(img, colors):
def create_palette(img, colors, light):
"""Sort the generated colors and store them in a dict that
we will later save in json format."""
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
# Darken the background color slightly.
if raw_colors[0][1] != "0":
raw_colors[0] = util.darken_color(raw_colors[0], 0.25)
if light:
# Manually adjust colors.
raw_colors[7] = raw_colors[0]
raw_colors[0] = util.lighten_color(raw_colors[15], 0.9)
raw_colors[15] = raw_colors[7]
raw_colors[8] = util.lighten_color(raw_colors[7], 0.25)
# Manually adjust colors.
raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE")
raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
"special": {}, "colors": {}}
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[15]
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
"special": {}, "colors": {}}
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[15]
for i, color in enumerate(raw_colors):
color = util.darken_color(color, 0.30)
colors["colors"]["color%s" % i] = util.saturate_color(color, 50)
for i, color in enumerate(raw_colors):
colors["colors"]["color%s" % i] = color
colors["colors"]["color0"] = raw_colors[0]
else:
# Darken the background color slightly.
if raw_colors[0][1] != "0":
raw_colors[0] = util.darken_color(raw_colors[0], 0.25)
# Manually adjust colors.
raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE")
raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
"special": {}, "colors": {}}
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[15]
for i, color in enumerate(raw_colors):
colors["colors"]["color%s" % i] = color
return colors
def get(img, cache_dir=CACHE_DIR,
color_count=COLOR_COUNT, notify=False):
color_count=COLOR_COUNT, light=False, notify=False):
"""Get the colorscheme."""
# home_dylan_img_jpg_1.2.2.json
cache_file = re.sub("[/|\\|.]", "_", img)
@ -99,7 +119,7 @@ def get(img, cache_dir=CACHE_DIR,
util.msg("wal: Generating a colorscheme...", notify)
colors = gen_colors(img, color_count)
colors = create_palette(img, colors)
colors = create_palette(img, colors, light)
util.save_file_json(colors, cache_file)
util.msg("wal: Generation complete.", notify)

View File

@ -121,6 +121,17 @@ def blend_color(color, color2):
return rgb_to_hex((r3, g3, b3))
def saturate_color(color, amount):
"""Saturate a hex color."""
r, g, b = hex_to_rgb(color)
r2 = r + amount
g2 = g + amount
b2 = b + amount
return rgb_to_hex((r2, g2, b2))
def disown(cmd):
"""Call a system command in the background,
disown it and hide it's output."""