From e329f3aea94618bbcd27f154225344428e22163a Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 26 Jun 2017 15:39:39 +1000 Subject: [PATCH] General: Renames settings.py to globals.py --- pywal/__main__.py | 20 +++++++-------- pywal/export.py | 32 +++++++++++------------ pywal/gen_colors.py | 22 ++++++++-------- pywal/{settings.py => globals.py} | 0 pywal/set_colors.py | 42 +++++++++++++++---------------- setup.py | 2 +- 6 files changed, 59 insertions(+), 59 deletions(-) rename pywal/{settings.py => globals.py} (100%) diff --git a/pywal/__main__.py b/pywal/__main__.py index 13e171e..fe6d2cb 100755 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -7,7 +7,7 @@ import os import shutil import sys -from pywal import settings as s +from pywal import globals as g from pywal import export from pywal import gen_colors from pywal import set_colors @@ -61,12 +61,12 @@ def process_args(args): # -q if args.q: sys.stdout = sys.stderr = open(os.devnull, "w") - s.Args.notify = False + g.Args.notify = False # -c if args.c: - shutil.rmtree(s.CACHE_DIR / "schemes") - util.create_dir(s.CACHE_DIR / "schemes") + shutil.rmtree(g.CACHE_DIR / "schemes") + util.create_dir(g.CACHE_DIR / "schemes") # -r if args.r: @@ -74,21 +74,21 @@ def process_args(args): # -v if args.v: - print(f"wal {s.__version__}") + print(f"wal {g.__version__}") exit(0) # -i if args.i: image = gen_colors.get_image(args.i) - s.ColorType.plain = gen_colors.get_colors(image) - s.ColorType.plain[8] = set_colors.set_grey(s.ColorType.plain) + g.ColorType.plain = gen_colors.get_colors(image) + g.ColorType.plain[8] = set_colors.set_grey(g.ColorType.plain) if not args.n: wallpaper.set_wallpaper(image) # Set the colors. - set_colors.send_sequences(s.ColorType.plain, args.t) - export.export_colors(s.ColorType.plain) + set_colors.send_sequences(g.ColorType.plain, args.t) + export.export_colors(g.ColorType.plain) # -o if args.o: @@ -97,7 +97,7 @@ def process_args(args): def main(): """Main script function.""" - util.create_dir(s.CACHE_DIR / "schemes") + util.create_dir(g.CACHE_DIR / "schemes") args = get_args() process_args(args) diff --git a/pywal/export.py b/pywal/export.py index bfe3974..fc2df93 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -4,21 +4,21 @@ Export colors in various formats. import shutil import subprocess -from pywal import settings as s +from pywal import globals as g from pywal import util def save_colors(colors, export_file, message): """Export colors to var format.""" colors = "\n".join(colors) - util.save_file(f"{colors}\n", s.CACHE_DIR / export_file) + util.save_file(f"{colors}\n", g.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", s.CACHE_DIR / export_file]) + subprocess.call(["xrdb", "-merge", g.CACHE_DIR / export_file]) def reload_i3(): @@ -29,42 +29,42 @@ def reload_i3(): def export_rofi(colors): """Append rofi colors to the x_colors list.""" - s.ColorType.xrdb.append(f"rofi.color-window: {colors[0]}, " + g.ColorType.xrdb.append(f"rofi.color-window: {colors[0]}, " f"{colors[0]}, {colors[10]}") - s.ColorType.xrdb.append(f"rofi.color-normal: {colors[0]}, " + g.ColorType.xrdb.append(f"rofi.color-normal: {colors[0]}, " f"{colors[15]}, {colors[0]}, " f"{colors[10]}, {colors[0]}") - s.ColorType.xrdb.append(f"rofi.color-active: {colors[0]}, " + g.ColorType.xrdb.append(f"rofi.color-active: {colors[0]}, " f"{colors[15]}, {colors[0]}, " f"{colors[10]}, {colors[0]}") - s.ColorType.xrdb.append(f"rofi.color-urgent: {colors[0]}, " + g.ColorType.xrdb.append(f"rofi.color-urgent: {colors[0]}, " f"{colors[9]}, {colors[0]}, " f"{colors[9]}, {colors[15]}") def export_emacs(colors): """Set emacs colors.""" - s.ColorType.xrdb.append(f"emacs*background: {colors[0]}") - s.ColorType.xrdb.append(f"emacs*foreground: {colors[15]}") + g.ColorType.xrdb.append(f"emacs*background: {colors[0]}") + g.ColorType.xrdb.append(f"emacs*foreground: {colors[15]}") def export_colors(colors): """Export colors in various formats.""" - save_colors(s.ColorType.plain, "colors", "plain hex colors") - save_colors(s.ColorType.shell, "colors.sh", "shell variables") + save_colors(g.ColorType.plain, "colors", "plain hex colors") + save_colors(g.ColorType.shell, "colors.sh", "shell variables") # Web based colors. - s.ColorType.css.append("}") - save_colors(s.ColorType.css, "colors.css", "css variables") - save_colors(s.ColorType.scss, "colors.scss", "scss variables") + g.ColorType.css.append("}") + save_colors(g.ColorType.css, "colors.css", "css variables") + save_colors(g.ColorType.scss, "colors.scss", "scss variables") # Text editor based colors. - save_colors(s.ColorType.putty, "colors-putty.reg", "putty theme") + save_colors(g.ColorType.putty, "colors-putty.reg", "putty theme") # X based colors. export_rofi(colors) export_emacs(colors) - save_colors(s.ColorType.xrdb, "xcolors", "xrdb colors") + save_colors(g.ColorType.xrdb, "xcolors", "xrdb colors") # i3 colors. reload_xrdb("xcolors") diff --git a/pywal/gen_colors.py b/pywal/gen_colors.py index e65d668..6c3293a 100644 --- a/pywal/gen_colors.py +++ b/pywal/gen_colors.py @@ -8,13 +8,13 @@ import re import shutil import subprocess -from pywal import settings as s +from pywal import globals as g from pywal import util def random_img(img_dir): """Pick a random image file from a directory.""" - current_wall = pathlib.Path(s.CACHE_DIR / "wal") + current_wall = pathlib.Path(g.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(s.COLOR_COUNT, img) + raw_colors = imagemagick(g.COLOR_COUNT, img) # If imagemagick finds less than 16 colors, use a larger source number # of colors. index = 0 - while len(raw_colors) - 1 < s.COLOR_COUNT: + while len(raw_colors) - 1 < g.COLOR_COUNT: index += 1 - raw_colors = imagemagick(s.COLOR_COUNT + index, img) + raw_colors = imagemagick(g.COLOR_COUNT + index, img) - print("colors: Imagemagick couldn't generate a", s.COLOR_COUNT, + print("colors: Imagemagick couldn't generate a", g.COLOR_COUNT, "color palette, trying a larger palette size", - s.COLOR_COUNT + index) + g.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): """Generate a colorscheme using imagemagick.""" # Cache the wallpaper name. - util.save_file(img, s.CACHE_DIR / "wal") + util.save_file(img, g.CACHE_DIR / "wal") # Cache the sequences file. - cache_file = pathlib.Path(s.CACHE_DIR / "schemes" / img.replace("/", "_")) + cache_file = pathlib.Path(g.CACHE_DIR / "schemes" / img.replace("/", "_")) if cache_file.is_file(): colors = util.read_file(cache_file) @@ -98,7 +98,7 @@ def get_colors(img): else: print("colors: Generating a colorscheme...") - if s.Args.notify: + if g.Args.notify: util.disown("notify-send", "wal: Generating a colorscheme...") # Generate the colors. @@ -109,7 +109,7 @@ def get_colors(img): util.save_file("\n".join(colors), cache_file) print("colors: Generated colorscheme") - if s.Args.notify: + if g.Args.notify: util.disown("notify-send", "wal: Generation complete.") return colors diff --git a/pywal/settings.py b/pywal/globals.py similarity index 100% rename from pywal/settings.py rename to pywal/globals.py diff --git a/pywal/set_colors.py b/pywal/set_colors.py index 7f395e9..715cdb4 100644 --- a/pywal/set_colors.py +++ b/pywal/set_colors.py @@ -5,43 +5,43 @@ import os import pathlib import re -from pywal import settings as s +from pywal import globals as g from pywal import util def set_special(index, color): """Build the escape sequence for special colors.""" - s.ColorType.sequences.append(f"\\033]{index};{color}\\007") + g.ColorType.sequences.append(f"\\033]{index};{color}\\007") if index == 10: - s.ColorType.xrdb.append(f"URxvt*foreground: {color}") - s.ColorType.xrdb.append(f"XTerm*foreground: {color}") + g.ColorType.xrdb.append(f"URxvt*foreground: {color}") + g.ColorType.xrdb.append(f"XTerm*foreground: {color}") elif index == 11: - s.ColorType.xrdb.append(f"URxvt*background: {color}") - s.ColorType.xrdb.append(f"XTerm*background: {color}") + g.ColorType.xrdb.append(f"URxvt*background: {color}") + g.ColorType.xrdb.append(f"XTerm*background: {color}") elif index == 12: - s.ColorType.xrdb.append(f"URxvt*cursorColor: {color}") - s.ColorType.xrdb.append(f"XTerm*cursorColor: {color}") + g.ColorType.xrdb.append(f"URxvt*cursorColor: {color}") + g.ColorType.xrdb.append(f"XTerm*cursorColor: {color}") elif index == 66: - s.ColorType.xrdb.append(f"*.color{index}: {color}") - s.ColorType.xrdb.append(f"*color{index}: {color}") - s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007") + g.ColorType.xrdb.append(f"*.color{index}: {color}") + g.ColorType.xrdb.append(f"*color{index}: {color}") + g.ColorType.sequences.append(f"\\033]4;{index};{color}\\007") def set_color(index, color): """Build the escape sequence we need for each color.""" - s.ColorType.xrdb.append(f"*.color{index}: {color}") - s.ColorType.xrdb.append(f"*color{index}: {color}") - s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007") - s.ColorType.shell.append(f"color{index}='{color}'") - s.ColorType.css.append(f"\t--color{index}: {color};") - s.ColorType.scss.append(f"$color{index}: {color};") + g.ColorType.xrdb.append(f"*.color{index}: {color}") + g.ColorType.xrdb.append(f"*color{index}: {color}") + g.ColorType.sequences.append(f"\\033]4;{index};{color}\\007") + g.ColorType.shell.append(f"color{index}='{color}'") + g.ColorType.css.append(f"\t--color{index}: {color};") + g.ColorType.scss.append(f"$color{index}: {color};") rgb = util.hex_to_rgb(color) - s.ColorType.putty.append(f"\"Colour{index}\"=\"{rgb}\"") + g.ColorType.putty.append(f"\"Colour{index}\"=\"{rgb}\"") def set_grey(colors): @@ -80,12 +80,12 @@ def send_sequences(colors, vte): set_special(66, colors[0]) # Make the terminal interpret escape sequences. - sequences = util.fix_escape("".join(s.ColorType.sequences)) + sequences = util.fix_escape("".join(g.ColorType.sequences)) # Get a list of terminals. terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/") if len(term) < 4] - terminals.append(s.CACHE_DIR / "sequences") + terminals.append(g.CACHE_DIR / "sequences") # Send the sequences to all open terminals. # pylint: disable=W0106 @@ -96,7 +96,7 @@ def send_sequences(colors, vte): def reload_colors(vte): """Reload colors.""" - sequence_file = pathlib.Path(s.CACHE_DIR / "sequences") + sequence_file = pathlib.Path(g.CACHE_DIR / "sequences") if sequence_file.is_file(): sequences = "".join(util.read_file(sequence_file)) diff --git a/setup.py b/setup.py index 4fe010f..569f9b3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ """wal - setup.py""" from setuptools import setup -import pywal.settings as pywal +import pywal.globals as pywal DESC = (