summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pywal/__init__.py2
-rw-r--r--pywal/__main__.py14
-rw-r--r--pywal/colors.py56
-rw-r--r--pywal/export.py1
-rw-r--r--pywal/theme.py67
5 files changed, 82 insertions, 58 deletions
diff --git a/pywal/__init__.py b/pywal/__init__.py
index 98d9a08..8a00b5a 100644
--- a/pywal/__init__.py
+++ b/pywal/__init__.py
@@ -15,6 +15,7 @@ from . import export
from . import image
from . import reload
from . import sequences
+from . import theme
from . import wallpaper
__all__ = [
@@ -25,5 +26,6 @@ __all__ = [
"image",
"reload",
"sequences",
+ "theme",
"wallpaper",
]
diff --git a/pywal/__main__.py b/pywal/__main__.py
index 43f4465..8086e39 100644
--- a/pywal/__main__.py
+++ b/pywal/__main__.py
@@ -14,12 +14,13 @@ import os
import shutil
import sys
-from .settings import __version__, CACHE_DIR, MODULE_DIR, CONF_DIR
+from .settings import __version__, CACHE_DIR, CONF_DIR
from . import colors
from . import export
from . import image
from . import reload
from . import sequences
+from . import theme
from . import util
from . import wallpaper
@@ -105,11 +106,7 @@ def process_args(args):
sys.exit(0)
if args.f == "list_themes":
- themes = os.listdir(os.path.join(CONF_DIR, "colorschemes"))
- themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes"))
- themes = [theme.replace(".json", "") for theme in themes]
-
- print("Themes:", ", ".join(themes))
+ print("Themes:", ", ".join(theme.index()))
sys.exit(0)
if args.q:
@@ -133,7 +130,7 @@ def process_args(args):
colors_plain = colors.get(image_file, light=args.l)
if args.f:
- colors_plain = colors.file(args.f)
+ colors_plain = theme.file(args.f)
if args.a:
util.Color.alpha_num = args.a
@@ -165,6 +162,9 @@ def process_args(args):
def main():
"""Main script function."""
+ util.create_dir(os.path.join(CONF_DIR, "colorschemes"))
+ util.create_dir(os.path.join(CONF_DIR, "templates"))
+
args = get_args(sys.argv[1:])
process_args(args)
diff --git a/pywal/colors.py b/pywal/colors.py
index 6ce3443..90f7ba2 100644
--- a/pywal/colors.py
+++ b/pywal/colors.py
@@ -7,8 +7,9 @@ import shutil
import subprocess
import sys
-from .settings import CACHE_DIR, COLOR_COUNT, MODULE_DIR, \
- CONF_DIR, __cache_version__
+from . import theme
+
+from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__
from . import util
@@ -112,7 +113,7 @@ def get(img, cache_dir=CACHE_DIR,
% (cache_file, color_type, __cache_version__))
if os.path.isfile(cache_file):
- colors = file(cache_file)
+ colors = theme.file(cache_file)
util.Color.alpha_num = colors["alpha"]
print("colors: Found cached colorscheme.")
@@ -128,51 +129,6 @@ def get(img, cache_dir=CACHE_DIR,
return colors
-def terminal_sexy_to_wal(data):
- """Convert terminal.sexy json schema to wal."""
- data["colors"] = {}
- data["special"] = {
- "foreground": data["foreground"],
- "background": data["background"],
- "cursor": data["color"][9]
- }
-
- for i, color in enumerate(data["color"]):
- data["colors"]["color%s" % i] = color
-
- return data
-
-
def file(input_file):
- """Import colorscheme from json file."""
- theme_file = ".".join((input_file, "json"))
- user_theme_dir = os.path.join(CONF_DIR, "colorschemes")
- user_theme_file = os.path.join(user_theme_dir, theme_file)
- theme_file = os.path.join(MODULE_DIR, "colorschemes", theme_file)
-
- util.create_dir(user_theme_dir)
-
- if os.path.isfile(user_theme_file):
- input_file = user_theme_file
-
- elif os.path.isfile(theme_file):
- input_file = theme_file
-
- if os.path.isfile(input_file):
- data = util.read_file_json(input_file)
-
- if "wallpaper" not in data:
- data["wallpaper"] = "None"
-
- if "alpha" not in data:
- data["alpha"] = "100"
-
- # Terminal.sexy format.
- if "color" in data:
- data = terminal_sexy_to_wal(data)
-
- return data
-
- else:
- print("No colorscheme file found, exiting...")
- sys.exit(1)
+ """Deprecated: symbolic link to --> theme.file"""
+ return theme.file(input_file)
diff --git a/pywal/export.py b/pywal/export.py
index 120150d..87185f6 100644
--- a/pywal/export.py
+++ b/pywal/export.py
@@ -53,7 +53,6 @@ def every(colors, output_dir=CACHE_DIR):
colors = flatten_colors(colors)
template_dir = os.path.join(MODULE_DIR, "templates")
template_dir_user = os.path.join(CONF_DIR, "templates")
- util.create_dir(template_dir_user)
join = os.path.join # Minor optimization.
diff --git a/pywal/theme.py b/pywal/theme.py
new file mode 100644
index 0000000..8023d73
--- /dev/null
+++ b/pywal/theme.py
@@ -0,0 +1,67 @@
+"""
+Theme file handling.
+"""
+import os
+import sys
+
+from .settings import CONF_DIR, MODULE_DIR
+from . import util
+
+
+def index():
+ """List all installed theme files."""
+ themes = os.listdir(os.path.join(CONF_DIR, "colorschemes"))
+ themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes"))
+ return [theme.replace(".json", "") for theme in themes]
+
+
+def terminal_sexy_to_wal(data):
+ """Convert terminal.sexy json schema to wal."""
+ data["colors"] = {}
+ data["special"] = {
+ "foreground": data["foreground"],
+ "background": data["background"],
+ "cursor": data["color"][9]
+ }
+
+ for i, color in enumerate(data["color"]):
+ data["colors"]["color%s" % i] = color
+
+ return data
+
+
+def file(input_file):
+ """Import colorscheme from json file."""
+ theme_name = ".".join((input_file, "json"))
+ user_theme_file = os.path.join(CONF_DIR, "colorschemes", theme_name)
+ theme_file = os.path.join(MODULE_DIR, "colorschemes", theme_name)
+
+ # Find the theme file.
+ if os.path.isfile(input_file):
+ theme_file = input_file
+
+ elif os.path.isfile(user_theme_file):
+ theme_file = user_theme_file
+
+ elif os.path.isfile(theme_file):
+ theme_file = theme_file
+
+ # Parse the theme file.
+ if os.path.isfile(theme_file):
+ data = util.read_file_json(theme_file)
+
+ if "wallpaper" not in data:
+ data["wallpaper"] = "None"
+
+ if "alpha" not in data:
+ data["alpha"] = "100"
+
+ # Terminal.sexy format.
+ if "color" in data:
+ data = terminal_sexy_to_wal(data)
+
+ return data
+
+ else:
+ print("No colorscheme file found, exiting...")
+ sys.exit(1)