mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-11-25 17:33:09 +01:00
api: Use wal file in __main__.py
This commit is contained in:
parent
8917eef29e
commit
88bdd9ab01
@ -19,6 +19,11 @@ def main():
|
||||
# Reload xrdb, i3 and polybar.
|
||||
pywal.reload_env()
|
||||
|
||||
# Export template files.
|
||||
pywal.export_all_templates(colors,
|
||||
"path/to/templates",
|
||||
"path/to/save/files/")
|
||||
|
||||
# Set the wallpaper.
|
||||
pywal.set_wallpaper(image)
|
||||
|
||||
|
@ -5,7 +5,9 @@ Created by Dylan Araps.
|
||||
# flake8: noqa: F401
|
||||
from pywal.settings import __version__
|
||||
from pywal.wal import create_palette
|
||||
from pywal.wal import export_all_templates
|
||||
from pywal.wal import get_image
|
||||
from pywal.wal import reload_colors
|
||||
from pywal.wal import reload_env
|
||||
from pywal.wal import send_sequences
|
||||
from pywal.wal import set_wallpaper
|
||||
|
@ -8,13 +8,8 @@ import shutil
|
||||
import sys
|
||||
|
||||
from pywal.settings import CACHE_DIR, __version__
|
||||
from pywal import export
|
||||
from pywal import image
|
||||
from pywal import magic
|
||||
from pywal import reload
|
||||
from pywal import sequences
|
||||
from pywal import wal
|
||||
from pywal import util
|
||||
from pywal import wallpaper
|
||||
|
||||
|
||||
def get_args():
|
||||
@ -79,7 +74,7 @@ def process_args(args):
|
||||
|
||||
# -r
|
||||
if args.r:
|
||||
sequences.reload_colors(args.t)
|
||||
wal.reload_colors(args.t)
|
||||
|
||||
# -v
|
||||
if args.v:
|
||||
@ -88,8 +83,8 @@ def process_args(args):
|
||||
|
||||
# -i
|
||||
if args.i:
|
||||
image_file = image.get_image(args.i)
|
||||
colors_plain = magic.get_colors(image_file, args.q)
|
||||
image_file = wal.get_image(args.i)
|
||||
colors_plain = wal.create_palette(image_file, args.q)
|
||||
|
||||
# -f
|
||||
elif args.f:
|
||||
@ -97,13 +92,13 @@ def process_args(args):
|
||||
|
||||
# -i or -f
|
||||
if args.i or args.f:
|
||||
sequences.send_sequences(colors_plain, args.t)
|
||||
wal.send_sequences(colors_plain, args.t)
|
||||
|
||||
if not args.n:
|
||||
wallpaper.set_wallpaper(colors_plain["wallpaper"])
|
||||
wal.set_wallpaper(colors_plain["wallpaper"])
|
||||
|
||||
export.export_all_templates(colors_plain)
|
||||
reload.reload_env()
|
||||
wal.export_all_templates(colors_plain)
|
||||
wal.reload_env()
|
||||
|
||||
# -o
|
||||
if args.o:
|
||||
|
@ -3,7 +3,6 @@ Export colors in various formats.
|
||||
"""
|
||||
import os
|
||||
|
||||
from pywal.settings import CACHE_DIR
|
||||
from pywal import util
|
||||
|
||||
|
||||
@ -27,12 +26,16 @@ def template(colors, input_file, output_dir):
|
||||
print(f"export: Exported {template_file}.")
|
||||
|
||||
|
||||
def export_all_templates(colors, template_dir=None, output_dir=CACHE_DIR):
|
||||
def export_all_templates(colors, template_dir=None, output_dir=None):
|
||||
"""Export all template files."""
|
||||
# Add the template dir to module path.
|
||||
template_dir = template_dir or \
|
||||
os.path.join(os.path.dirname(__file__), "templates")
|
||||
|
||||
# Convert path strings into Path types.
|
||||
template_dir = util.str_to_path(template_dir)
|
||||
output_dir = util.str_to_path(output_dir)
|
||||
|
||||
# Merge all colors (specials and normals) into one dict so we can access
|
||||
# their values simpler.
|
||||
all_colors = {"wallpaper": colors["wallpaper"],
|
||||
|
@ -53,7 +53,7 @@ def gen_colors(img):
|
||||
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors]
|
||||
|
||||
|
||||
def get_colors(img, quiet):
|
||||
def get_colors(img, quiet=False):
|
||||
"""Get the colorscheme."""
|
||||
# Cache the wallpaper name.
|
||||
util.save_file(img, CACHE_DIR / "wal")
|
||||
|
@ -53,9 +53,9 @@ def send_sequences(colors, vte):
|
||||
print("colors: Set terminal colors")
|
||||
|
||||
|
||||
def reload_colors(vte):
|
||||
def reload_colors(vte, sequence_file=None):
|
||||
"""Reload the current scheme."""
|
||||
sequence_file = CACHE_DIR / "sequences"
|
||||
sequence_file = sequence_file or CACHE_DIR / "sequences"
|
||||
|
||||
if sequence_file.is_file():
|
||||
sequences = "".join(util.read_file(sequence_file))
|
||||
|
@ -98,3 +98,8 @@ def disown(*cmd):
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
preexec_fn=os.setpgrp)
|
||||
|
||||
|
||||
def str_to_path(str_path):
|
||||
"""Convert a string to a Path type."""
|
||||
return pathlib.Path(str_path)
|
||||
|
19
pywal/wal.py
19
pywal/wal.py
@ -2,6 +2,8 @@
|
||||
wal - Generate and change colorschemes on the fly.
|
||||
Created by Dylan Araps.
|
||||
"""
|
||||
from pywal.settings import CACHE_DIR
|
||||
from pywal import export
|
||||
from pywal import image
|
||||
from pywal import magic
|
||||
from pywal import reload
|
||||
@ -14,11 +16,9 @@ def get_image(img):
|
||||
return image.get_image(img)
|
||||
|
||||
|
||||
def create_palette(img):
|
||||
def create_palette(img, quiet=False):
|
||||
"""Create a palette and return it as a dict."""
|
||||
colors = magic.gen_colors(img)
|
||||
colors = magic.sort_colors(img, colors)
|
||||
return colors
|
||||
return magic.get_colors(img, quiet)
|
||||
|
||||
|
||||
def send_sequences(colors, vte):
|
||||
@ -31,11 +31,16 @@ def reload_env():
|
||||
reload.reload_env()
|
||||
|
||||
|
||||
def export_all_templates(colors, template_dir=None, export_dir=CACHE_DIR):
|
||||
"""Export all templates."""
|
||||
export.export_all_templates(colors, template_dir, export_dir)
|
||||
|
||||
|
||||
def set_wallpaper(img):
|
||||
"""Set the wallpaper."""
|
||||
wallpaper.set_wallpaper(img)
|
||||
|
||||
|
||||
# def reload_colors(vte):
|
||||
# """Reload the colors."""
|
||||
# sequences.reload_colors(vte)
|
||||
def reload_colors(vte, sequence_file=None):
|
||||
"""Reload the colors."""
|
||||
sequences.reload_colors(vte, sequence_file)
|
||||
|
Loading…
Reference in New Issue
Block a user