General: Rename globals to settings and import constants we need.

This commit is contained in:
Dylan Araps 2017-06-26 23:36:36 +10:00
parent 0b38d7affc
commit 7a723eb173
6 changed files with 21 additions and 24 deletions

View File

@ -2,7 +2,4 @@
wal - Generate and change colorschemes on the fly.
Created by Dylan Araps.
"""
from pywal import globals as g
__version__ = g.__version__
from pywal.settings import __version__ # noqa: F401

View File

@ -7,7 +7,7 @@ import os
import shutil
import sys
from pywal import globals as g
from pywal.settings import CACHE_DIR, __version__
from pywal import export_colors
from pywal import gen_colors
from pywal import set_colors
@ -64,8 +64,8 @@ def process_args(args):
# -c
if args.c:
shutil.rmtree(g.CACHE_DIR / "schemes")
util.create_dir(g.CACHE_DIR / "schemes")
shutil.rmtree(CACHE_DIR / "schemes")
util.create_dir(CACHE_DIR / "schemes")
# -r
if args.r:
@ -73,7 +73,7 @@ def process_args(args):
# -v
if args.v:
print(f"wal {g.__version__}")
print(f"wal {__version__}")
exit(0)
# -i
@ -98,7 +98,7 @@ def process_args(args):
def main():
"""Main script function."""
util.create_dir(g.CACHE_DIR / "schemes")
util.create_dir(CACHE_DIR / "schemes")
args = get_args()
process_args(args)

View File

@ -4,7 +4,7 @@ Export colors in various formats.
import shutil
import subprocess
from pywal import globals as g
from pywal.settings import CACHE_DIR
from pywal import util
from pywal import format_color
@ -12,14 +12,14 @@ from pywal import format_color
def save_colors(colors, export_file, message):
"""Export colors to var format."""
colors = "".join(colors)
util.save_file(colors, g.CACHE_DIR / export_file)
util.save_file(colors, CACHE_DIR / export_file)
print(f"export: exported {message}.")
def reload_xrdb(export_file):
"""Merge the colors into the X db so new terminals use them."""
if shutil.which("xrdb"):
subprocess.call(["xrdb", "-merge", g.CACHE_DIR / export_file])
subprocess.call(["xrdb", "-merge", CACHE_DIR / export_file])
def reload_i3():

View File

@ -8,13 +8,13 @@ import re
import shutil
import subprocess
from pywal import globals as g
from pywal.settings import CACHE_DIR, COLOR_COUNT
from pywal import util
def random_img(img_dir):
"""Pick a random image file from a directory."""
current_wall = pathlib.Path(g.CACHE_DIR / "wal")
current_wall = pathlib.Path(CACHE_DIR / "wal")
if current_wall.is_file():
current_wall = util.read_file(current_wall)
@ -64,18 +64,18 @@ def gen_colors(img):
exit(1)
# Generate initial scheme.
raw_colors = imagemagick(g.COLOR_COUNT, img)
raw_colors = imagemagick(COLOR_COUNT, img)
# If imagemagick finds less than 16 colors, use a larger source number
# of colors.
index = 0
while len(raw_colors) - 1 < g.COLOR_COUNT:
while len(raw_colors) - 1 < COLOR_COUNT:
index += 1
raw_colors = imagemagick(g.COLOR_COUNT + index, img)
raw_colors = imagemagick(COLOR_COUNT + index, img)
print("colors: Imagemagick couldn't generate a", g.COLOR_COUNT,
print("colors: Imagemagick couldn't generate a", COLOR_COUNT,
"color palette, trying a larger palette size",
g.COLOR_COUNT + index)
COLOR_COUNT + index)
# Remove the first element, which isn't a color.
del raw_colors[0]
@ -87,10 +87,10 @@ def gen_colors(img):
def get_colors(img, quiet):
"""Generate a colorscheme using imagemagick."""
# Cache the wallpaper name.
util.save_file(img, g.CACHE_DIR / "wal")
util.save_file(img, CACHE_DIR / "wal")
# Cache the sequences file.
cache_file = pathlib.Path(g.CACHE_DIR / "schemes" / img.replace("/", "_"))
cache_file = pathlib.Path(CACHE_DIR / "schemes" / img.replace("/", "_"))
if cache_file.is_file():
colors = util.read_file(cache_file)

View File

@ -5,7 +5,7 @@ import os
import pathlib
import re
from pywal import globals as g
from pywal.settings import CACHE_DIR
from pywal import util
@ -54,7 +54,7 @@ def send_sequences(colors, vte):
# Get a list of terminals.
terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
if len(term) < 4]
terminals.append(g.CACHE_DIR / "sequences")
terminals.append(CACHE_DIR / "sequences")
# Send the sequences to all open terminals.
# pylint: disable=W0106
@ -65,7 +65,7 @@ def send_sequences(colors, vte):
def reload_colors(vte):
"""Reload colors."""
sequence_file = pathlib.Path(g.CACHE_DIR / "sequences")
sequence_file = pathlib.Path(CACHE_DIR / "sequences")
if sequence_file.is_file():
sequences = "".join(util.read_file(sequence_file))