mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-01-24 14:58:44 +01:00
Merge pull request #174 from dylanaraps/light
colors: Add light theme support.
This commit is contained in:
commit
4bd1021b67
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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."""
|
||||
|
Loading…
Reference in New Issue
Block a user