mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-17 15:16:38 +02:00
theme: Move theme handling to own file.
This commit is contained in:
parent
20ae5f8d7a
commit
1cff79bcc6
@ -15,6 +15,7 @@ from . import export
|
|||||||
from . import image
|
from . import image
|
||||||
from . import reload
|
from . import reload
|
||||||
from . import sequences
|
from . import sequences
|
||||||
|
from . import theme
|
||||||
from . import wallpaper
|
from . import wallpaper
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -25,5 +26,6 @@ __all__ = [
|
|||||||
"image",
|
"image",
|
||||||
"reload",
|
"reload",
|
||||||
"sequences",
|
"sequences",
|
||||||
|
"theme",
|
||||||
"wallpaper",
|
"wallpaper",
|
||||||
]
|
]
|
||||||
|
@ -14,12 +14,13 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
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 colors
|
||||||
from . import export
|
from . import export
|
||||||
from . import image
|
from . import image
|
||||||
from . import reload
|
from . import reload
|
||||||
from . import sequences
|
from . import sequences
|
||||||
|
from . import theme
|
||||||
from . import util
|
from . import util
|
||||||
from . import wallpaper
|
from . import wallpaper
|
||||||
|
|
||||||
@ -105,11 +106,7 @@ def process_args(args):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.f == "list_themes":
|
if args.f == "list_themes":
|
||||||
themes = os.listdir(os.path.join(CONF_DIR, "colorschemes"))
|
print("Themes:", ", ".join(theme.index()))
|
||||||
themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes"))
|
|
||||||
themes = [theme.replace(".json", "") for theme in themes]
|
|
||||||
|
|
||||||
print("Themes:", ", ".join(themes))
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.q:
|
if args.q:
|
||||||
@ -133,7 +130,7 @@ def process_args(args):
|
|||||||
colors_plain = colors.get(image_file, light=args.l)
|
colors_plain = colors.get(image_file, light=args.l)
|
||||||
|
|
||||||
if args.f:
|
if args.f:
|
||||||
colors_plain = colors.file(args.f)
|
colors_plain = theme.file(args.f)
|
||||||
|
|
||||||
if args.a:
|
if args.a:
|
||||||
util.Color.alpha_num = args.a
|
util.Color.alpha_num = args.a
|
||||||
@ -165,6 +162,9 @@ def process_args(args):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main script function."""
|
"""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:])
|
args = get_args(sys.argv[1:])
|
||||||
process_args(args)
|
process_args(args)
|
||||||
|
|
||||||
|
@ -7,8 +7,9 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .settings import CACHE_DIR, COLOR_COUNT, MODULE_DIR, \
|
from . import theme
|
||||||
CONF_DIR, __cache_version__
|
|
||||||
|
from .settings import CACHE_DIR, COLOR_COUNT, __cache_version__
|
||||||
from . import util
|
from . import util
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ def get(img, cache_dir=CACHE_DIR,
|
|||||||
% (cache_file, color_type, __cache_version__))
|
% (cache_file, color_type, __cache_version__))
|
||||||
|
|
||||||
if os.path.isfile(cache_file):
|
if os.path.isfile(cache_file):
|
||||||
colors = file(cache_file)
|
colors = theme.file(cache_file)
|
||||||
util.Color.alpha_num = colors["alpha"]
|
util.Color.alpha_num = colors["alpha"]
|
||||||
print("colors: Found cached colorscheme.")
|
print("colors: Found cached colorscheme.")
|
||||||
|
|
||||||
@ -128,51 +129,6 @@ def get(img, cache_dir=CACHE_DIR,
|
|||||||
return colors
|
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):
|
def file(input_file):
|
||||||
"""Import colorscheme from json file."""
|
"""Deprecated: symbolic link to --> theme.file"""
|
||||||
theme_file = ".".join((input_file, "json"))
|
return theme.file(input_file)
|
||||||
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)
|
|
||||||
|
@ -53,7 +53,6 @@ def every(colors, output_dir=CACHE_DIR):
|
|||||||
colors = flatten_colors(colors)
|
colors = flatten_colors(colors)
|
||||||
template_dir = os.path.join(MODULE_DIR, "templates")
|
template_dir = os.path.join(MODULE_DIR, "templates")
|
||||||
template_dir_user = os.path.join(CONF_DIR, "templates")
|
template_dir_user = os.path.join(CONF_DIR, "templates")
|
||||||
util.create_dir(template_dir_user)
|
|
||||||
|
|
||||||
join = os.path.join # Minor optimization.
|
join = os.path.join # Minor optimization.
|
||||||
|
|
||||||
|
67
pywal/theme.py
Normal file
67
pywal/theme.py
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user