backend: cleanup

This commit is contained in:
Dylan Araps 2018-03-31 11:28:28 +11:00
parent 32792a0b98
commit 520b065a30
4 changed files with 43 additions and 66 deletions

View File

@ -30,36 +30,25 @@ def gen_colors(img):
return [util.rgb_to_hex(color) for color in raw_colors]
def adjust(img, colors, light):
def adjust(colors, light):
"""Create palette."""
if light:
print("colors: Colortheif backend doesn't support light themes.")
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
for color in raw_colors:
color = util.lighten_color(color, 0.25)
raw_colors[0] = util.darken_color(colors[0], 0.80)
raw_colors[15] = util.lighten_color(colors[15], 0.80)
raw_colors[7] = raw_colors[15]
raw_colors[7] = util.lighten_color(colors[15], 0.60)
raw_colors[8] = util.blend_color(colors[0], colors[15])
raw_colors[15] = raw_colors[7]
colors = {"wallpaper": img,
"alpha": util.Color.alpha_num,
"special": {},
"colors": {}}
for i, color in enumerate(raw_colors):
colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25)
raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15])
colors["colors"]["color0"] = raw_colors[0]
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[1]
return colors
return raw_colors
def get(img, light=False):
"""Get colorscheme."""
colors = gen_colors(img)
return adjust(img, colors, light)
return adjust(colors, light)

View File

@ -12,36 +12,26 @@ def gen_colors(img):
return subprocess.check_output([*colorz, img]).splitlines()
def adjust(img, colors, light):
def adjust(colors, light):
"""Create palette."""
if light:
print("colors: Colorz backend doesn't support light themes.")
# Create list with placeholder values.
raw_colors = ["#000000", *colors, "#FFFFFF",
"#333333", *colors, "#FFFFFF"]
# Update placeholder values.
raw_colors[0] = util.darken_color(colors[0], 0.75)
raw_colors[8] = util.darken_color(colors[0], 0.25)
raw_colors[7] = util.lighten_color(colors[0], 0.75)
raw_colors[15] = raw_colors[7]
colors = {"wallpaper": img,
"alpha": util.Color.alpha_num,
"special": {},
"colors": {}}
for i, color in enumerate(raw_colors):
colors["colors"]["color%s" % i] = color
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[1]
return colors
return raw_colors
def get(img, light=False):
"""Get colorscheme."""
colors = gen_colors(img)
colors = [color.decode('UTF-8').split()[0] for color in colors]
return adjust(img, colors, light)
return adjust(colors, light)

View File

@ -54,54 +54,34 @@ def gen_colors(img):
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]]
def adjust(img, colors, light):
def adjust(colors, light):
"""Adjust 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]
# Manually adjust colors.
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)
for color in raw_colors:
color = util.saturate_color(color, 0.5)
raw_colors[0] = util.lighten_color(colors[-1], 0.85)
raw_colors[7] = colors[0]
raw_colors[8] = util.darken_color(colors[-1], 0.4)
raw_colors[15] = 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]
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
return raw_colors
def get(img, light=False):
"""Get colorscheme."""
colors = gen_colors(img)
return adjust(img, colors, light)
return adjust(colors, light)

View File

@ -24,6 +24,23 @@ def list_backends():
return "colorthief, colorz, wal"
def colors_to_dict(colors, img):
"""Convert list of colors to pywal format."""
scheme = {"wallpaper": img,
"alpha": util.Color.alpha_num,
"special": {},
"colors": {}}
for i, color in enumerate(colors):
scheme["colors"]["color%s" % i] = color
scheme["special"]["background"] = colors[0]
scheme["special"]["foreground"] = colors[15]
scheme["special"]["cursor"] = colors[1]
return scheme
def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR):
"""Generate a palette."""
# home_dylan_img_jpg_backend_1.2.2.json
@ -42,6 +59,7 @@ def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR):
print("wal: Generating a colorscheme...")
colors = get(backend)(img, light)
colors = colors_to_dict(colors, img)
util.save_file_json(colors, cache_file)
print("wal: Generation complete.")