mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-01-24 06:48:41 +01:00
backend: dynamic fo shizle
This commit is contained in:
parent
26677bb64b
commit
277edbc5e0
@ -1,27 +1,18 @@
|
||||
"""
|
||||
Generate a palette using various backends.
|
||||
"""
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from . import backends
|
||||
from . import util
|
||||
from .settings import CACHE_DIR, __cache_version__
|
||||
|
||||
|
||||
def get(backend_type="wal"):
|
||||
"""Get backend function name from name."""
|
||||
return {
|
||||
"colorthief": backends.colorthief.get,
|
||||
"colorz": backends.colorz.get,
|
||||
"wal": backends.wal.get,
|
||||
}.get(backend_type, backends.wal.get)
|
||||
|
||||
|
||||
def list_backends():
|
||||
"""List color backends."""
|
||||
# TODO: Dynamically generate this.
|
||||
return "colorthief, colorz, wal"
|
||||
return [backend for backend in dir(backends) if "__" not in backend]
|
||||
|
||||
|
||||
def colors_to_dict(colors, img):
|
||||
@ -58,8 +49,9 @@ def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR):
|
||||
else:
|
||||
print("wal: Generating a colorscheme...")
|
||||
|
||||
colors = get(backend)(img, light)
|
||||
colors = colors_to_dict(colors, img)
|
||||
# Dynamic shiz.
|
||||
backend = sys.modules["pywal.backends.%s" % backend]
|
||||
colors = colors_to_dict(getattr(backend, "get")(img, light), img)
|
||||
|
||||
util.save_file_json(colors, cache_file)
|
||||
print("wal: Generation complete.")
|
||||
|
Loading…
Reference in New Issue
Block a user