themes: Allow local themes

This commit is contained in:
Dylan Araps 2018-03-16 08:47:53 +11:00
parent e76887915f
commit 7db89a3907
2 changed files with 15 additions and 6 deletions

View File

@ -14,7 +14,7 @@ import os
import shutil import shutil
import sys import sys
from .settings import __version__, CACHE_DIR, MODULE_DIR from .settings import __version__, CACHE_DIR, MODULE_DIR, CONF_DIR
from . import colors from . import colors
from . import export from . import export
from . import image from . import image
@ -125,7 +125,8 @@ 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 == "list_themes": if args.f == "list_themes":
themes = os.listdir(os.path.join(MODULE_DIR, "colorschemes")) themes = os.listdir(os.path.join(CONF_DIR, "colorschemes"))
themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes"))
print("Themes:", print("Themes:",
", ".join([theme.replace(".json", "") for theme in themes])) ", ".join([theme.replace(".json", "") for theme in themes]))

View File

@ -7,7 +7,8 @@ import shutil
import subprocess import subprocess
import sys import sys
from .settings import CACHE_DIR, COLOR_COUNT, MODULE_DIR, __cache_version__ from .settings import CACHE_DIR, COLOR_COUNT, MODULE_DIR, \
CONF_DIR, __cache_version__
from . import util from . import util
@ -144,10 +145,17 @@ def terminal_sexy_to_wal(data):
def file(input_file): def file(input_file):
"""Import colorscheme from json file.""" """Import colorscheme from json file."""
theme_file = os.path.join(MODULE_DIR, "colorschemes", theme_file = ".".join((input_file, "json"))
".".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)
if os.path.isfile(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 input_file = theme_file
if os.path.isfile(input_file): if os.path.isfile(input_file):