mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-26 04:21:22 +02:00
general: rebase
This commit is contained in:
commit
60aaf55430
@ -13,7 +13,7 @@ For more info, check out the [Wiki](https://github.com/dylanaraps/pywal/wiki).
|
|||||||
|
|
||||||
[Screenshot Examples (Reddit)](https://www.reddit.com/r/unixporn/search?q=wal&restrict_sr=on&sort=relevance&t=all)
|
[Screenshot Examples (Reddit)](https://www.reddit.com/r/unixporn/search?q=wal&restrict_sr=on&sort=relevance&t=all)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Donate
|
## Donate
|
||||||
|
@ -10,6 +10,7 @@ Created by Dylan Araps.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
@ -25,7 +26,7 @@ from . import util
|
|||||||
from . import wallpaper
|
from . import wallpaper
|
||||||
|
|
||||||
|
|
||||||
def get_args(args):
|
def get_args():
|
||||||
"""Get the script arguments."""
|
"""Get the script arguments."""
|
||||||
description = "wal - Generate colorschemes on the fly"
|
description = "wal - Generate colorschemes on the fly"
|
||||||
arg = argparse.ArgumentParser(description=description)
|
arg = argparse.ArgumentParser(description=description)
|
||||||
@ -40,10 +41,9 @@ def get_args(args):
|
|||||||
arg.add_argument("--backend", metavar="backend",
|
arg.add_argument("--backend", metavar="backend",
|
||||||
help="Which color backend to use. \
|
help="Which color backend to use. \
|
||||||
Use 'wal --backend' to list backends.",
|
Use 'wal --backend' to list backends.",
|
||||||
const="list_backends", type=str,
|
const="list_backends", type=str, nargs="?")
|
||||||
nargs="?", default="default")
|
|
||||||
|
|
||||||
arg.add_argument("--theme", metavar="/path/to/file or theme_name",
|
arg.add_argument("--theme", "-f", metavar="/path/to/file or theme_name",
|
||||||
help="Which colorscheme file to use. \
|
help="Which colorscheme file to use. \
|
||||||
Use 'wal --theme' to list builtin themes.",
|
Use 'wal --theme' to list builtin themes.",
|
||||||
const="list_themes", nargs="?")
|
const="list_themes", nargs="?")
|
||||||
@ -88,24 +88,28 @@ def get_args(args):
|
|||||||
arg.add_argument("-e", action="store_true",
|
arg.add_argument("-e", action="store_true",
|
||||||
help="Skip reloading gtk/xrdb/i3/sway/polybar")
|
help="Skip reloading gtk/xrdb/i3/sway/polybar")
|
||||||
|
|
||||||
return arg.parse_args(args)
|
return arg
|
||||||
|
|
||||||
|
|
||||||
def process_args(args):
|
def parse_args_exit(parser):
|
||||||
"""Process args."""
|
"""Process args that exit."""
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not len(sys.argv) > 1:
|
if not len(sys.argv) > 1:
|
||||||
print("error: wal needs to be given arguments to run.\n"
|
parser.error("wal needs to be given arguments to run.")
|
||||||
" Refer to \"wal -h\" for more info.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if args.i and args.theme:
|
|
||||||
print("error: Conflicting arguments -i and -f.\n"
|
|
||||||
" Refer to \"wal -h\" for more info.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if args.v:
|
if args.v:
|
||||||
print("wal", __version__)
|
parser.exit(0, "wal %s\n" % __version__)
|
||||||
sys.exit(0)
|
|
||||||
|
if args.i and args.theme:
|
||||||
|
parser.error("Conflicting arguments -i and -f.")
|
||||||
|
|
||||||
|
if not args.i and \
|
||||||
|
not args.theme and \
|
||||||
|
not args.R and \
|
||||||
|
not args.backend:
|
||||||
|
parser.error("No input specified.\n"
|
||||||
|
"--backend, --theme, -i or -R are required.")
|
||||||
|
|
||||||
if args.r:
|
if args.r:
|
||||||
reload.colors()
|
reload.colors()
|
||||||
@ -122,22 +126,19 @@ def process_args(args):
|
|||||||
print("Backends:", colors.list_backends())
|
print("Backends:", colors.list_backends())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args(parser):
|
||||||
|
"""Process args."""
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.q:
|
if args.q:
|
||||||
|
logging.getLogger().disabled = True
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
|
||||||
if args.c:
|
if args.c:
|
||||||
scheme_dir = os.path.join(CACHE_DIR, "schemes")
|
scheme_dir = os.path.join(CACHE_DIR, "schemes")
|
||||||
shutil.rmtree(scheme_dir, ignore_errors=True)
|
shutil.rmtree(scheme_dir, ignore_errors=True)
|
||||||
|
|
||||||
if args.R:
|
|
||||||
image_file = os.path.join(CACHE_DIR, "wal")
|
|
||||||
|
|
||||||
if os.path.isfile(image_file):
|
|
||||||
args.i = util.read_file(image_file)[0]
|
|
||||||
else:
|
|
||||||
print("image: No colorscheme to restore, try 'wal -i' first.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if args.i:
|
if args.i:
|
||||||
image_file = image.get(args.i)
|
image_file = image.get(args.i)
|
||||||
colors_plain = colors.get(image_file, args.l, args.backend)
|
colors_plain = colors.get(image_file, args.l, args.backend)
|
||||||
@ -145,6 +146,9 @@ def process_args(args):
|
|||||||
if args.theme:
|
if args.theme:
|
||||||
colors_plain = theme.file(args.theme)
|
colors_plain = theme.file(args.theme)
|
||||||
|
|
||||||
|
if args.R:
|
||||||
|
colors_plain = theme.file(os.path.join(CACHE_DIR, "colors.json"))
|
||||||
|
|
||||||
if args.a:
|
if args.a:
|
||||||
util.Color.alpha_num = args.a
|
util.Color.alpha_num = args.a
|
||||||
|
|
||||||
@ -153,15 +157,18 @@ def process_args(args):
|
|||||||
colors_plain["special"]["background"] = args.b
|
colors_plain["special"]["background"] = args.b
|
||||||
colors_plain["colors"]["color0"] = args.b
|
colors_plain["colors"]["color0"] = args.b
|
||||||
|
|
||||||
if args.i or args.theme:
|
if not args.n:
|
||||||
if not args.n:
|
wallpaper.change(colors_plain["wallpaper"])
|
||||||
wallpaper.change(colors_plain["wallpaper"])
|
|
||||||
|
|
||||||
sequences.send(colors_plain, to_send=not args.s)
|
sequences.send(colors_plain, to_send=not args.s)
|
||||||
export.every(colors_plain)
|
|
||||||
|
|
||||||
if not args.e:
|
if sys.stdout.isatty():
|
||||||
reload.env(tty_reload=not args.t)
|
colors.palette()
|
||||||
|
|
||||||
|
export.every(colors_plain)
|
||||||
|
|
||||||
|
if not args.e:
|
||||||
|
reload.env(tty_reload=not args.t)
|
||||||
|
|
||||||
reload.external_script(args.o)
|
reload.external_script(args.o)
|
||||||
|
|
||||||
@ -173,8 +180,10 @@ def process_args(args):
|
|||||||
def main():
|
def main():
|
||||||
"""Main script function."""
|
"""Main script function."""
|
||||||
util.setup_logging()
|
util.setup_logging()
|
||||||
args = get_args(sys.argv[1:])
|
parser = get_args()
|
||||||
process_args(args)
|
|
||||||
|
parse_args_exit(parser)
|
||||||
|
parse_args(parser)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -3,7 +3,7 @@ Hh ____
|
|||||||
HP "HHF:. `._ :.,-'"" "-.
|
HP "HHF:. `._ :.,-'"" "-.
|
||||||
F F" :::..'"" "-. `.
|
F F" :::..'"" "-. `.
|
||||||
F , \ \ "BACKENDS"
|
F , \ \ "BACKENDS"
|
||||||
F j\ / ; `. - sorry
|
F j\ / ; `.
|
||||||
| j `. ` A \
|
| j `. ` A \
|
||||||
| | ;_ . 8 \
|
| | ;_ . 8 \
|
||||||
J F\_,'| "`-----.\ j `. \
|
J F\_,'| "`-----.\ j `. \
|
||||||
|
@ -25,7 +25,7 @@ def gen_colors(img):
|
|||||||
if len(raw_colors) >= 8:
|
if len(raw_colors) >= 8:
|
||||||
break
|
break
|
||||||
|
|
||||||
elif i == 19:
|
elif i == 10:
|
||||||
logging.error("ColorThief couldn't generate a suitable palette.")
|
logging.error("ColorThief couldn't generate a suitable palette.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -98,6 +98,22 @@ def get_backend(backend):
|
|||||||
return backend
|
return backend
|
||||||
|
|
||||||
|
|
||||||
|
def palette():
|
||||||
|
"""Generate a palette from the colors."""
|
||||||
|
col_width = " " * (os.get_terminal_size().columns // 8)
|
||||||
|
|
||||||
|
for i in range(0, 16):
|
||||||
|
if i % 8 == 0:
|
||||||
|
print()
|
||||||
|
|
||||||
|
if i > 7:
|
||||||
|
i = "8;5;%s" % i
|
||||||
|
|
||||||
|
print("\033[4%sm%s\033[0m" % (i, col_width), end="")
|
||||||
|
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
def get(img, light=False, backend="default", cache_dir=CACHE_DIR):
|
def get(img, light=False, backend="default", cache_dir=CACHE_DIR):
|
||||||
"""Generate a palette."""
|
"""Generate a palette."""
|
||||||
backend = get_backend(backend)
|
backend = get_backend(backend)
|
||||||
@ -112,14 +128,15 @@ def get(img, light=False, backend="default", cache_dir=CACHE_DIR):
|
|||||||
logging.info("Found cached colorscheme.")
|
logging.info("Found cached colorscheme.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.info("Generating a colorscheme...")
|
logging.info("Generating a colorscheme.")
|
||||||
|
backend = get_backend(backend)
|
||||||
|
|
||||||
# Dynamically import the backend we want to use.
|
# Dynamically import the backend we want to use.
|
||||||
# This keeps the dependencies "optional".
|
# This keeps the dependencies "optional".
|
||||||
try:
|
try:
|
||||||
util.variable_import("pywal.backends.%s" % backend)
|
__import__("pywal.backends.%s" % backend)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
util.variable_import("pywal.backends.wal")
|
__import__("pywal.backends.wal")
|
||||||
backend = "wal"
|
backend = "wal"
|
||||||
|
|
||||||
logging.info("Using %s backend.", backend)
|
logging.info("Using %s backend.", backend)
|
||||||
|
@ -5,7 +5,7 @@ cmd_hook =
|
|||||||
[colors]
|
[colors]
|
||||||
# Color backend to use.
|
# Color backend to use.
|
||||||
# Possible values, see: wal --backend
|
# Possible values, see: wal --backend
|
||||||
backend = random
|
backend =
|
||||||
|
|
||||||
[wallpaper]
|
[wallpaper]
|
||||||
# Which wallpaper setter to use.
|
# Which wallpaper setter to use.
|
||||||
|
@ -57,13 +57,9 @@ def every(colors, output_dir=CACHE_DIR):
|
|||||||
util.create_dir(template_dir_user)
|
util.create_dir(template_dir_user)
|
||||||
|
|
||||||
join = os.path.join # Minor optimization.
|
join = os.path.join # Minor optimization.
|
||||||
|
for file in [*os.scandir(template_dir),
|
||||||
for file in os.scandir(template_dir):
|
*os.scandir(template_dir_user)]:
|
||||||
if file.name != '.DS_Store':
|
if file.name != ".DS_Store":
|
||||||
template(colors, file.path, join(output_dir, file.name))
|
|
||||||
|
|
||||||
for file in os.scandir(template_dir_user):
|
|
||||||
if file.name != '.DS_Store':
|
|
||||||
template(colors, file.path, join(output_dir, file.name))
|
template(colors, file.path, join(output_dir, file.name))
|
||||||
|
|
||||||
logging.info("Exported all files.")
|
logging.info("Exported all files.")
|
||||||
|
@ -33,12 +33,12 @@ def oomox(gen_theme):
|
|||||||
"""Call oomox to generate a theme."""
|
"""Call oomox to generate a theme."""
|
||||||
if gen_theme:
|
if gen_theme:
|
||||||
if not shutil.which("oomox-cli"):
|
if not shutil.which("oomox-cli"):
|
||||||
logging.warning("Oomox not found, skipping...")
|
logging.warning("Oomox not found, skipping.")
|
||||||
return
|
return
|
||||||
|
|
||||||
oomox_file = os.path.join(CACHE_DIR, "colors-oomox")
|
oomox_file = os.path.join(CACHE_DIR, "colors-oomox")
|
||||||
|
|
||||||
logging.info("Waiting for oomox...")
|
logging.info("Waiting for Oomox.")
|
||||||
subprocess.run(["oomox-cli", "-o", "wal", oomox_file],
|
subprocess.run(["oomox-cli", "-o", "wal", oomox_file],
|
||||||
stdout=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ import shutil
|
|||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
|
|
||||||
__version__ = "1.3.3"
|
__version__ = "2.0.3"
|
||||||
__cache_version__ = "1.0.0"
|
__cache_version__ = "1.1.0"
|
||||||
|
|
||||||
|
|
||||||
HOME = os.getenv("HOME", os.getenv("USERPROFILE"))
|
HOME = os.getenv("HOME", os.getenv("USERPROFILE"))
|
||||||
|
@ -31,7 +31,7 @@ def terminal_sexy_to_wal(data):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def parse_theme(theme_file):
|
def parse(theme_file):
|
||||||
"""Parse the theme file."""
|
"""Parse the theme file."""
|
||||||
data = util.read_file_json(theme_file)
|
data = util.read_file_json(theme_file)
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ def file(input_file):
|
|||||||
|
|
||||||
# Parse the theme file.
|
# Parse the theme file.
|
||||||
if os.path.isfile(theme_file):
|
if os.path.isfile(theme_file):
|
||||||
return parse_theme(theme_file)
|
return parse(theme_file)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.error("No colorscheme file found, exiting...")
|
logging.error("No colorscheme file found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -6,6 +6,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class Color:
|
class Color:
|
||||||
@ -92,17 +93,13 @@ def create_dir(directory):
|
|||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def variable_import(module):
|
|
||||||
"""Import a module dynamically."""
|
|
||||||
__import__(module)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logging():
|
def setup_logging():
|
||||||
"""Logging config."""
|
"""Logging config."""
|
||||||
logging.basicConfig(format=("[%(levelname)s\033[0m] "
|
logging.basicConfig(format=("[%(levelname)s\033[0m] "
|
||||||
"\033[1;31m%(module)s\033[0m: "
|
"\033[1;31m%(module)s\033[0m: "
|
||||||
"%(message)s"),
|
"%(message)s"),
|
||||||
level=logging.INFO)
|
level=logging.INFO,
|
||||||
|
stream=sys.stdout)
|
||||||
logging.addLevelName(logging.ERROR, '\033[1;31mE')
|
logging.addLevelName(logging.ERROR, '\033[1;31mE')
|
||||||
logging.addLevelName(logging.INFO, '\033[1;32mI')
|
logging.addLevelName(logging.INFO, '\033[1;32mI')
|
||||||
logging.addLevelName(logging.WARNING, '\033[1;33mW')
|
logging.addLevelName(logging.WARNING, '\033[1;33mW')
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
"""Test __main__ functions."""
|
|
||||||
import unittest
|
|
||||||
import unittest.mock
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from pywal import __main__
|
|
||||||
from pywal import reload
|
|
||||||
from pywal import wallpaper
|
|
||||||
from pywal import util
|
|
||||||
from pywal.settings import CACHE_DIR
|
|
||||||
|
|
||||||
|
|
||||||
class TestMain(unittest.TestCase):
|
|
||||||
"""Test the gen_colors functions."""
|
|
||||||
|
|
||||||
def test_args_a(self):
|
|
||||||
"""> Test arg parsing (-a)."""
|
|
||||||
args = __main__.get_args(["-a", "50"])
|
|
||||||
__main__.process_args(args)
|
|
||||||
self.assertEqual(util.Color.alpha_num, "50")
|
|
||||||
|
|
||||||
def test_args_c(self):
|
|
||||||
"""> Test arg parsing (-c)."""
|
|
||||||
args = __main__.get_args(["-c"])
|
|
||||||
__main__.process_args(args)
|
|
||||||
scheme_dir = os.path.join(CACHE_DIR, "schemes")
|
|
||||||
self.assertFalse(os.path.isdir(scheme_dir))
|
|
||||||
|
|
||||||
def test_args_e(self):
|
|
||||||
"""> Test arg parsing (-e)."""
|
|
||||||
reload.env = unittest.mock.MagicMock()
|
|
||||||
args = __main__.get_args(["-e"])
|
|
||||||
__main__.process_args(args)
|
|
||||||
self.assertFalse(reload.env.called)
|
|
||||||
|
|
||||||
def test_args_n(self):
|
|
||||||
"""> Test arg parsing (-n)."""
|
|
||||||
wallpaper.change = unittest.mock.MagicMock()
|
|
||||||
args = __main__.get_args(["-n"])
|
|
||||||
__main__.process_args(args)
|
|
||||||
self.assertFalse(wallpaper.change.called)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
Loading…
x
Reference in New Issue
Block a user