Merge pull request #174 from dylanaraps/light

colors: Add light theme support.
This commit is contained in:
Dylan Araps 2018-02-03 11:09:09 +11:00 committed by GitHub
commit 4bd1021b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 16 deletions

View File

@ -1,5 +1,5 @@
[BASIC]
good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3
good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3,h,s,v
[MESSAGES CONTROL]
# inconsistent-return-statements:

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,19 +56,26 @@ 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.85)
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")
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[15] = util.blend_color(raw_colors[15], "#EEEEEE")
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
"special": {}, "colors": {}}
@ -76,19 +83,30 @@ def create_palette(img, colors):
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
if light:
for i, color in enumerate(raw_colors):
colors["colors"]["color%s" % i] = util.saturate_color(color, 0.5)
colors["colors"]["color0"] = raw_colors[0]
colors["colors"]["color7"] = raw_colors[15]
colors["colors"]["color8"] = util.darken_color(raw_colors[0], 0.5)
colors["colors"]["color15"] = raw_colors[15]
else:
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
color_type = "light" if light else "dark"
cache_file = re.sub("[/|\\|.]", "_", img)
cache_file = os.path.join(cache_dir, "schemes", cache_file + "_" +
__version__ + ".json")
cache_file = os.path.join(cache_dir, "schemes", "%s_%s_%s.json"
% (cache_file, color_type, __version__))
if os.path.isfile(cache_file):
colors = file(cache_file)
@ -99,7 +117,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

@ -1,6 +1,7 @@
"""
Misc helper functions.
"""
import colorsys
import json
import os
import shutil
@ -121,6 +122,19 @@ 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)
r, g, b = [x/255.0 for x in (r, g, b)]
h, s, v = colorsys.rgb_to_hsv(r, g, b)
s = amount
v = 0.2
r, g, b = colorsys.hls_to_rgb(h, s, v)
r, g, b = [x*255.0 for x in (r, g, b)]
return rgb_to_hex((int(r), int(g), int(b)))
def disown(cmd):
"""Call a system command in the background,
disown it and hide it's output."""