diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-07-22 22:26:49 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-07-22 22:26:49 +1000 |
| commit | de47c1beaaa77ee6f50235daba735ccc98ad608c (patch) | |
| tree | 03fca45aead0204d0b8619d775077f1046230ba0 /pywal | |
| parent | a4ea6a4f7addc3ada3c466a763331d793190a342 (diff) | |
api: Remove wal.py
Diffstat (limited to 'pywal')
| -rw-r--r-- | pywal/__init__.py | 25 | ||||
| -rw-r--r-- | pywal/__main__.py | 39 | ||||
| -rw-r--r-- | pywal/colors.py (renamed from pywal/magic.py) | 50 | ||||
| -rw-r--r-- | pywal/image.py | 5 | ||||
| -rw-r--r-- | pywal/reload.py | 22 | ||||
| -rw-r--r-- | pywal/sequences.py | 26 | ||||
| -rw-r--r-- | pywal/settings.py | 16 | ||||
| -rw-r--r-- | pywal/template.py | 5 | ||||
| -rw-r--r-- | pywal/wal.py | 55 | ||||
| -rw-r--r-- | pywal/wallpaper.py | 2 |
10 files changed, 116 insertions, 129 deletions
diff --git a/pywal/__init__.py b/pywal/__init__.py index 52cedff..ec61c5c 100644 --- a/pywal/__init__.py +++ b/pywal/__init__.py @@ -1,15 +1,22 @@ """ -wal - Generate and change colorschemes on the fly. + '|| +... ... .... ... ... ... ... .... || + ||' || '|. | || || | '' .|| || + || | '|.| ||| ||| .|' || || + ||...' '| | | '|..'|' .||. + || .. | +'''' '' Created by Dylan Araps. """ -from pywal.wal 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 + +from .settings import __version__ +from .colors import get as create_palette +from .image import get as get_image +from .reload import colors as reload_colors +from .reload import env as reload_env +from .sequences import send as send_sequences +from .template import export_all as export_all_templates +from .wallpaper import change as set_wallpaper __all__ = [ "__version__", diff --git a/pywal/__main__.py b/pywal/__main__.py index bc772ec..626292f 100644 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -1,14 +1,27 @@ """ -wal - Generate and change colorschemes on the fly. + '|| +... ... .... ... ... ... ... .... || + ||' || '|. | || || | '' .|| || + || | '|.| ||| ||| .|' || || + ||...' '| | | '|..'|' .||. + || .. | +'''' '' Created by Dylan Araps. """ + import argparse import os import shutil import sys -from pywal import wal -from pywal import util +from .settings import __version__, __cache_dir__ +from . import colors +from . import image +from . import reload +from . import sequences +from . import template +from . import util +from . import wallpaper def get_args(): @@ -61,33 +74,33 @@ def process_args(args): exit(1) if args.v: - print(f"wal {wal.__version__}") + print(f"wal {__version__}") exit(0) if args.q: sys.stdout = sys.stderr = open(os.devnull, "w") if args.c: - shutil.rmtree(wal.CACHE_DIR / "schemes", ignore_errors=True) + shutil.rmtree(__cache_dir__ / "schemes", ignore_errors=True) if args.r: - wal.reload_colors(args.t) + reload.colors(args.t) if args.i: - image_file = wal.get_image(args.i) - colors_plain = wal.create_palette(img=image_file, notify=not args.q) + image_file = image.get(args.i) + colors_plain = colors.get(image_file, notify=not args.q) - elif args.f: + if args.f: colors_plain = util.read_file_json(args.f) if args.i or args.f: - wal.send_sequences(colors_plain, args.t) + sequences.send(colors_plain, args.t) if not args.n: - wal.set_wallpaper(colors_plain["wallpaper"]) + wallpaper.change(colors_plain["wallpaper"]) - wal.export_all_templates(colors_plain) - wal.reload_env() + template.export_all(colors_plain) + reload.env() if args.o: util.disown(args.o) diff --git a/pywal/magic.py b/pywal/colors.py index 757fdce..08490a4 100644 --- a/pywal/magic.py +++ b/pywal/colors.py @@ -5,7 +5,8 @@ import re import shutil import subprocess -from pywal import util +from .settings import __cache_dir__, __color_count__ +from . import util def imagemagick(color_count, img): @@ -47,29 +48,6 @@ def gen_colors(img, color_count): return [re.search("#.{6}", str(col)).group(0) for col in raw_colors] -def get_colors(img, cache_dir, color_count, quiet): - """Get the colorscheme.""" - # _home_dylan_img_jpg.json - cache_file = cache_dir / "schemes" / \ - img.replace("/", "_").replace(".", "_") - cache_file = cache_file.with_suffix(".json") - - if cache_file.is_file(): - colors = util.read_file_json(cache_file) - print("colors: Found cached colorscheme.") - - else: - util.msg("wal: Generating a colorscheme...", quiet) - - colors = gen_colors(img, color_count) - colors = sort_colors(img, colors) - - util.save_file_json(colors, cache_file) - util.msg("wal: Generation complete.", quiet) - - return colors - - def sort_colors(img, colors): """Sort the generated colors and store them in a dict that we will later save in json format.""" @@ -91,3 +69,27 @@ def sort_colors(img, colors): colors["colors"] = colors_hex return colors + + +def get(img, cache_dir=__cache_dir__, + color_count=__color_count__, notify=False): + """Get the colorscheme.""" + # _home_dylan_img_jpg.json + cache_file = cache_dir / "schemes" / \ + img.replace("/", "_").replace(".", "_") + cache_file = cache_file.with_suffix(".json") + + if cache_file.is_file(): + colors = util.read_file_json(cache_file) + print("colors: Found cached colorscheme.") + + else: + util.msg("wal: Generating a colorscheme...", notify) + + colors = gen_colors(img, color_count) + colors = sort_colors(img, colors) + + util.save_file_json(colors, cache_file) + util.msg("wal: Generation complete.", notify) + + return colors diff --git a/pywal/image.py b/pywal/image.py index 421943e..44b82f2 100644 --- a/pywal/image.py +++ b/pywal/image.py @@ -5,7 +5,8 @@ import os import pathlib import random -from pywal import util +from .settings import __cache_dir__ +from . import util def get_random_image(img_dir, cache_dir): @@ -27,7 +28,7 @@ def get_random_image(img_dir, cache_dir): return str(img_dir / random.choice(images).name) -def get_image(img, cache_dir): +def get(img, cache_dir=__cache_dir__): """Validate image input.""" image = pathlib.Path(img) diff --git a/pywal/reload.py b/pywal/reload.py index 66fdea9..da09fe0 100644 --- a/pywal/reload.py +++ b/pywal/reload.py @@ -1,10 +1,12 @@ """ Reload programs. """ +import re import shutil import subprocess -from pywal import util +from .settings import __cache_dir__ +from . import util def reload_xrdb(cache_dir): @@ -27,9 +29,25 @@ def reload_polybar(): util.disown("pkill", "-USR1", "polybar") -def reload_env(cache_dir): +def env(cache_dir=__cache_dir__): """Reload environment.""" reload_xrdb(cache_dir) reload_i3() reload_polybar() print("reload: Reloaded environment.") + + +def colors(vte, cache_dir=__cache_dir__): + """Reload the current scheme.""" + sequence_file = cache_dir / "sequences" + + if sequence_file.is_file(): + sequences = "".join(util.read_file(sequence_file)) + + # If vte mode was used, remove the unsupported sequence. + if vte: + sequences = re.sub(r"\]708;\#.{6}", "", sequences) + + print(sequences, end="") + + exit(0) diff --git a/pywal/sequences.py b/pywal/sequences.py index c1a7bdd..77eace3 100644 --- a/pywal/sequences.py +++ b/pywal/sequences.py @@ -2,9 +2,9 @@ Send sequences to all open terminals. """ import os -import re -from pywal import util +from .settings import __cache_dir__ +from . import util def set_special(index, color): @@ -17,14 +17,14 @@ def set_color(index, color): return f"\033]4;{index};{color}\007" -def send_sequences(colors, vte, cache_dir): +def send(colors, vte, cache_dir=__cache_dir__): """Send colors to all open terminals.""" # Colors 0-15. sequences = [set_color(num, color) for num, color in enumerate(colors["colors"].values())] # Special colors. - # http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.7.pod#XTerm_Operating_System_Commands + # Source: https://goo.gl/KcoQgP # 10 = foreground, 11 = background, 12 = cursor foregound # 13 = mouse foreground sequences.append(set_special(10, colors["special"]["foreground"])) @@ -32,7 +32,7 @@ def send_sequences(colors, vte, cache_dir): sequences.append(set_special(12, colors["special"]["cursor"])) sequences.append(set_special(13, colors["special"]["cursor"])) - # Set a blank color that isn"t affected by bold highlighting. + # Set a blank color that isn't affected by bold highlighting. # Used in wal.vim's airline theme. sequences.append(set_color(66, colors["special"]["background"])) @@ -49,19 +49,3 @@ def send_sequences(colors, vte, cache_dir): util.save_file("".join(sequences), term) print("colors: Set terminal colors") - - -def reload_colors(vte, cache_dir): - """Reload the current scheme.""" - sequence_file = cache_dir / "sequences" - - if sequence_file.is_file(): - sequences = "".join(util.read_file(sequence_file)) - - # If vte mode was used, remove the unsupported sequence. - if vte: - sequences = re.sub(r"\]708;\#.{6}", "", sequences) - - print(sequences, end="") - - exit(0) diff --git a/pywal/settings.py b/pywal/settings.py new file mode 100644 index 0000000..acfc625 --- /dev/null +++ b/pywal/settings.py @@ -0,0 +1,16 @@ +""" + '|| +... ... .... ... ... ... ... .... || + ||' || '|. | || || | '' .|| || + || | '|.| ||| ||| .|' || || + ||...' '| | | '|..'|' .||. + || .. | +'''' '' +Created by Dylan Araps. +""" + +import pathlib + +__version__ = "0.4.0" +__cache_dir__ = pathlib.Path.home() / ".cache/wal/" +__color_count__ = 16 diff --git a/pywal/template.py b/pywal/template.py index 210e45e..1cb4197 100644 --- a/pywal/template.py +++ b/pywal/template.py @@ -3,7 +3,8 @@ Export colors in various formats. """ import os -from pywal import util +from .settings import __cache_dir__ +from . import util def template(colors, input_file, output_dir): @@ -16,7 +17,7 @@ def template(colors, input_file, output_dir): print(f"export: Exported {template_name}.") -def export_all_templates(colors, output_dir, template_dir=None): +def export_all(colors, output_dir=__cache_dir__, template_dir=None): """Export all template files.""" template_dir = template_dir or \ os.path.join(os.path.dirname(__file__), "templates") diff --git a/pywal/wal.py b/pywal/wal.py deleted file mode 100644 index e9e3e85..0000000 --- a/pywal/wal.py +++ /dev/null @@ -1,55 +0,0 @@ -""" -wal - Generate and change colorschemes on the fly. -Created by Dylan Araps. -""" -import pathlib - -from pywal import image -from pywal import magic -from pywal import reload -from pywal import sequences -from pywal import template -from pywal import wallpaper - - -__version__ = "0.4.0" - - -COLOR_COUNT = 16 -CACHE_DIR = pathlib.Path.home() / ".cache/wal/" - - -def get_image(img, cache_dir=CACHE_DIR): - """Validate image input.""" - return image.get_image(img, cache_dir) - - -def create_palette(img, cache_dir=CACHE_DIR, - color_count=COLOR_COUNT, notify=False): - """Create a palette and return it as a dict.""" - return magic.get_colors(img, cache_dir, color_count, notify) - - -def send_sequences(colors, vte, cache_dir=CACHE_DIR): - """Send the sequences.""" - sequences.send_sequences(colors, vte, cache_dir) - - -def reload_env(cache_dir=CACHE_DIR): - """Reload the environment.""" - reload.reload_env(cache_dir) - - -def export_all_templates(colors, output_dir=CACHE_DIR, template_dir=None): - """Export all templates.""" - template.export_all_templates(colors, output_dir, template_dir) - - -def set_wallpaper(img): - """Set the wallpaper.""" - wallpaper.set_wallpaper(img) - - -def reload_colors(vte, cache_dir=CACHE_DIR): - """Reload the colors.""" - sequences.reload_colors(vte, cache_dir) diff --git a/pywal/wallpaper.py b/pywal/wallpaper.py index 5e524a3..99b978e 100644 --- a/pywal/wallpaper.py +++ b/pywal/wallpaper.py @@ -80,7 +80,7 @@ def set_desktop_wallpaper(desktop, img): set_wm_wallpaper(img) -def set_wallpaper(img): +def change(img): """Set the wallpaper.""" if not os.path.isfile(img): return |
