Exemple #1
0
def get_colors(img, quiet):
    """Get the colorscheme."""
    # Cache the wallpaper name.
    util.save_file(img, CACHE_DIR / "wal")

    # Cache the sequences file.
    # _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:
        print("colors: Generating a colorscheme...")
        if not quiet:
            util.disown("notify-send", "wal: Generating a colorscheme...")

        # Generate the colors.
        colors = gen_colors(img)
        colors = sort_colors(img, colors)

        # Cache the colorscheme.
        util.save_file_json(colors, cache_file)

        print("colors: Generated colorscheme")
        if not quiet:
            util.disown("notify-send", "wal: Generation complete.")

    return colors
Exemple #2
0
def process_args(args):
    """Process args."""
    # If no args were passed.
    if not len(sys.argv) > 1:
        print("error: wal needs to be given arguments to run.\n"
              "       Refer to \"wal -h\" for more info.")
        exit(1)

    if args.i and args.f:
        print("error: Conflicting arguments -i and -f.\n"
              "       Refer to \"wal -h\" for more info.")
        exit(1)

    # -q
    if args.q:
        sys.stdout = sys.stderr = open(os.devnull, "w")

    # -c
    if args.c:
        shutil.rmtree(CACHE_DIR / "schemes")
        util.create_dir(CACHE_DIR / "schemes")

    # -r
    if args.r:
        sequences.reload_colors(args.t)

    # -v
    if args.v:
        print(f"wal {__version__}")
        exit(0)

    # -i
    if args.i:
        image_file = image.get_image(args.i)

        # Create a list of hex colors.
        colors_plain = magic.get_colors(image_file, args.q)

        if not args.n:
            wallpaper.set_wallpaper(image_file)

    # -f
    elif args.f:
        colors_plain = util.read_file_json(args.f)

    # -i or -f
    if args.i or args.f:
        sequences.send_sequences(colors_plain, args.t)
        export.export_all_templates(colors_plain)
        reload.reload_env()

    # -o
    if args.o:
        util.disown(args.o)
Exemple #3
0
"""Test sequence functions."""
import unittest
import platform

from pywal import sequences
from pywal import util

# Import colors.
COLORS = util.read_file_json("tests/test_files/test_file.json")


class Testsequences(unittest.TestCase):
    """Test the sequence functions."""

    def test_set_special(self):
        """> Create special escape sequence."""
        util.Color.alpha_num = 100
        result = sequences.set_special(11, COLORS["special"]["background"])

        if platform.uname()[0] == "Darwin":
            self.assertEqual(result, "\033]Ph1F211E\033\\")
        else:
            self.assertEqual(result, "\033]11;#1F211E\007")

    def test_set_special_alpha(self):
        """> Create special escape sequence with alpha."""
        util.Color.alpha_num = 99
        result = sequences.set_special(11, COLORS["special"]["background"])

        if platform.uname()[0] == "Darwin":
            self.assertEqual(result, "\033]Ph1F211E\033\\")
Exemple #4
0
 def test_read_wallpaper(self):
     """> Read wallpaper from json file."""
     result = util.read_file_json("tests/test_files/test_file.json")
     self.assertEqual(result["wallpaper"], "5.png")
Exemple #5
0
 def test_read_file_end(self):
     """> Read colors from a file."""
     result = util.read_file_json("tests/test_files/test_file.json")
     self.assertEqual(result["colors"]["color15"], "#F5F1F4")
Exemple #6
0
 def test_read_file_start(self):
     """> Read colors from a file."""
     result = util.read_file_json("tests/test_files/test_file.json")
     self.assertEqual(result["colors"]["color0"], "#1F211E")