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. wal - Generate and change colorschemes on the fly.
Created by Dylan Araps. Created by Dylan Araps.
""" """
from pywal import globals as g from pywal.settings import __version__ # noqa: F401
__version__ = g.__version__

View File

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

View File

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

View File

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

View File

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