mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-14 13:46:57 +02:00
General: Renames settings.py to globals.py
This commit is contained in:
parent
67888e041b
commit
e329f3aea9
@ -7,7 +7,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pywal import settings as s
|
from pywal import globals as g
|
||||||
from pywal import export
|
from pywal import export
|
||||||
from pywal import gen_colors
|
from pywal import gen_colors
|
||||||
from pywal import set_colors
|
from pywal import set_colors
|
||||||
@ -61,12 +61,12 @@ def process_args(args):
|
|||||||
# -q
|
# -q
|
||||||
if args.q:
|
if args.q:
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
s.Args.notify = False
|
g.Args.notify = False
|
||||||
|
|
||||||
# -c
|
# -c
|
||||||
if args.c:
|
if args.c:
|
||||||
shutil.rmtree(s.CACHE_DIR / "schemes")
|
shutil.rmtree(g.CACHE_DIR / "schemes")
|
||||||
util.create_dir(s.CACHE_DIR / "schemes")
|
util.create_dir(g.CACHE_DIR / "schemes")
|
||||||
|
|
||||||
# -r
|
# -r
|
||||||
if args.r:
|
if args.r:
|
||||||
@ -74,21 +74,21 @@ def process_args(args):
|
|||||||
|
|
||||||
# -v
|
# -v
|
||||||
if args.v:
|
if args.v:
|
||||||
print(f"wal {s.__version__}")
|
print(f"wal {g.__version__}")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
# -i
|
# -i
|
||||||
if args.i:
|
if args.i:
|
||||||
image = gen_colors.get_image(args.i)
|
image = gen_colors.get_image(args.i)
|
||||||
s.ColorType.plain = gen_colors.get_colors(image)
|
g.ColorType.plain = gen_colors.get_colors(image)
|
||||||
s.ColorType.plain[8] = set_colors.set_grey(s.ColorType.plain)
|
g.ColorType.plain[8] = set_colors.set_grey(g.ColorType.plain)
|
||||||
|
|
||||||
if not args.n:
|
if not args.n:
|
||||||
wallpaper.set_wallpaper(image)
|
wallpaper.set_wallpaper(image)
|
||||||
|
|
||||||
# Set the colors.
|
# Set the colors.
|
||||||
set_colors.send_sequences(s.ColorType.plain, args.t)
|
set_colors.send_sequences(g.ColorType.plain, args.t)
|
||||||
export.export_colors(s.ColorType.plain)
|
export.export_colors(g.ColorType.plain)
|
||||||
|
|
||||||
# -o
|
# -o
|
||||||
if args.o:
|
if args.o:
|
||||||
@ -97,7 +97,7 @@ def process_args(args):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main script function."""
|
"""Main script function."""
|
||||||
util.create_dir(s.CACHE_DIR / "schemes")
|
util.create_dir(g.CACHE_DIR / "schemes")
|
||||||
args = get_args()
|
args = get_args()
|
||||||
process_args(args)
|
process_args(args)
|
||||||
|
|
||||||
|
@ -4,21 +4,21 @@ Export colors in various formats.
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from pywal import settings as s
|
from pywal import globals as g
|
||||||
from pywal import util
|
from pywal import util
|
||||||
|
|
||||||
|
|
||||||
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 = "\n".join(colors)
|
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}.")
|
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", s.CACHE_DIR / export_file])
|
subprocess.call(["xrdb", "-merge", g.CACHE_DIR / export_file])
|
||||||
|
|
||||||
|
|
||||||
def reload_i3():
|
def reload_i3():
|
||||||
@ -29,42 +29,42 @@ def reload_i3():
|
|||||||
|
|
||||||
def export_rofi(colors):
|
def export_rofi(colors):
|
||||||
"""Append rofi colors to the x_colors list."""
|
"""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]}")
|
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[15]}, {colors[0]}, "
|
||||||
f"{colors[10]}, {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[15]}, {colors[0]}, "
|
||||||
f"{colors[10]}, {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[0]}, "
|
||||||
f"{colors[9]}, {colors[15]}")
|
f"{colors[9]}, {colors[15]}")
|
||||||
|
|
||||||
|
|
||||||
def export_emacs(colors):
|
def export_emacs(colors):
|
||||||
"""Set emacs colors."""
|
"""Set emacs colors."""
|
||||||
s.ColorType.xrdb.append(f"emacs*background: {colors[0]}")
|
g.ColorType.xrdb.append(f"emacs*background: {colors[0]}")
|
||||||
s.ColorType.xrdb.append(f"emacs*foreground: {colors[15]}")
|
g.ColorType.xrdb.append(f"emacs*foreground: {colors[15]}")
|
||||||
|
|
||||||
|
|
||||||
def export_colors(colors):
|
def export_colors(colors):
|
||||||
"""Export colors in various formats."""
|
"""Export colors in various formats."""
|
||||||
save_colors(s.ColorType.plain, "colors", "plain hex colors")
|
save_colors(g.ColorType.plain, "colors", "plain hex colors")
|
||||||
save_colors(s.ColorType.shell, "colors.sh", "shell variables")
|
save_colors(g.ColorType.shell, "colors.sh", "shell variables")
|
||||||
|
|
||||||
# Web based colors.
|
# Web based colors.
|
||||||
s.ColorType.css.append("}")
|
g.ColorType.css.append("}")
|
||||||
save_colors(s.ColorType.css, "colors.css", "css variables")
|
save_colors(g.ColorType.css, "colors.css", "css variables")
|
||||||
save_colors(s.ColorType.scss, "colors.scss", "scss variables")
|
save_colors(g.ColorType.scss, "colors.scss", "scss variables")
|
||||||
|
|
||||||
# Text editor based colors.
|
# 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.
|
# X based colors.
|
||||||
export_rofi(colors)
|
export_rofi(colors)
|
||||||
export_emacs(colors)
|
export_emacs(colors)
|
||||||
save_colors(s.ColorType.xrdb, "xcolors", "xrdb colors")
|
save_colors(g.ColorType.xrdb, "xcolors", "xrdb colors")
|
||||||
|
|
||||||
# i3 colors.
|
# i3 colors.
|
||||||
reload_xrdb("xcolors")
|
reload_xrdb("xcolors")
|
||||||
|
@ -8,13 +8,13 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from pywal import settings as s
|
from pywal import globals as g
|
||||||
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(s.CACHE_DIR / "wal")
|
current_wall = pathlib.Path(g.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(s.COLOR_COUNT, img)
|
raw_colors = imagemagick(g.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 < s.COLOR_COUNT:
|
while len(raw_colors) - 1 < g.COLOR_COUNT:
|
||||||
index += 1
|
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",
|
"color palette, trying a larger palette size",
|
||||||
s.COLOR_COUNT + index)
|
g.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):
|
def get_colors(img):
|
||||||
"""Generate a colorscheme using imagemagick."""
|
"""Generate a colorscheme using imagemagick."""
|
||||||
# Cache the wallpaper name.
|
# 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 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():
|
if cache_file.is_file():
|
||||||
colors = util.read_file(cache_file)
|
colors = util.read_file(cache_file)
|
||||||
@ -98,7 +98,7 @@ def get_colors(img):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
print("colors: Generating a colorscheme...")
|
print("colors: Generating a colorscheme...")
|
||||||
if s.Args.notify:
|
if g.Args.notify:
|
||||||
util.disown("notify-send", "wal: Generating a colorscheme...")
|
util.disown("notify-send", "wal: Generating a colorscheme...")
|
||||||
|
|
||||||
# Generate the colors.
|
# Generate the colors.
|
||||||
@ -109,7 +109,7 @@ def get_colors(img):
|
|||||||
util.save_file("\n".join(colors), cache_file)
|
util.save_file("\n".join(colors), cache_file)
|
||||||
|
|
||||||
print("colors: Generated colorscheme")
|
print("colors: Generated colorscheme")
|
||||||
if s.Args.notify:
|
if g.Args.notify:
|
||||||
util.disown("notify-send", "wal: Generation complete.")
|
util.disown("notify-send", "wal: Generation complete.")
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
@ -5,43 +5,43 @@ import os
|
|||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from pywal import settings as s
|
from pywal import globals as g
|
||||||
from pywal import util
|
from pywal import util
|
||||||
|
|
||||||
|
|
||||||
def set_special(index, color):
|
def set_special(index, color):
|
||||||
"""Build the escape sequence for special colors."""
|
"""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:
|
if index == 10:
|
||||||
s.ColorType.xrdb.append(f"URxvt*foreground: {color}")
|
g.ColorType.xrdb.append(f"URxvt*foreground: {color}")
|
||||||
s.ColorType.xrdb.append(f"XTerm*foreground: {color}")
|
g.ColorType.xrdb.append(f"XTerm*foreground: {color}")
|
||||||
|
|
||||||
elif index == 11:
|
elif index == 11:
|
||||||
s.ColorType.xrdb.append(f"URxvt*background: {color}")
|
g.ColorType.xrdb.append(f"URxvt*background: {color}")
|
||||||
s.ColorType.xrdb.append(f"XTerm*background: {color}")
|
g.ColorType.xrdb.append(f"XTerm*background: {color}")
|
||||||
|
|
||||||
elif index == 12:
|
elif index == 12:
|
||||||
s.ColorType.xrdb.append(f"URxvt*cursorColor: {color}")
|
g.ColorType.xrdb.append(f"URxvt*cursorColor: {color}")
|
||||||
s.ColorType.xrdb.append(f"XTerm*cursorColor: {color}")
|
g.ColorType.xrdb.append(f"XTerm*cursorColor: {color}")
|
||||||
|
|
||||||
elif index == 66:
|
elif index == 66:
|
||||||
s.ColorType.xrdb.append(f"*.color{index}: {color}")
|
g.ColorType.xrdb.append(f"*.color{index}: {color}")
|
||||||
s.ColorType.xrdb.append(f"*color{index}: {color}")
|
g.ColorType.xrdb.append(f"*color{index}: {color}")
|
||||||
s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
|
g.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
|
||||||
|
|
||||||
|
|
||||||
def set_color(index, color):
|
def set_color(index, color):
|
||||||
"""Build the escape sequence we need for each color."""
|
"""Build the escape sequence we need for each color."""
|
||||||
s.ColorType.xrdb.append(f"*.color{index}: {color}")
|
g.ColorType.xrdb.append(f"*.color{index}: {color}")
|
||||||
s.ColorType.xrdb.append(f"*color{index}: {color}")
|
g.ColorType.xrdb.append(f"*color{index}: {color}")
|
||||||
s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
|
g.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
|
||||||
s.ColorType.shell.append(f"color{index}='{color}'")
|
g.ColorType.shell.append(f"color{index}='{color}'")
|
||||||
s.ColorType.css.append(f"\t--color{index}: {color};")
|
g.ColorType.css.append(f"\t--color{index}: {color};")
|
||||||
s.ColorType.scss.append(f"$color{index}: {color};")
|
g.ColorType.scss.append(f"$color{index}: {color};")
|
||||||
|
|
||||||
rgb = util.hex_to_rgb(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):
|
def set_grey(colors):
|
||||||
@ -80,12 +80,12 @@ def send_sequences(colors, vte):
|
|||||||
set_special(66, colors[0])
|
set_special(66, colors[0])
|
||||||
|
|
||||||
# Make the terminal interpret escape sequences.
|
# 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.
|
# 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(s.CACHE_DIR / "sequences")
|
terminals.append(g.CACHE_DIR / "sequences")
|
||||||
|
|
||||||
# Send the sequences to all open terminals.
|
# Send the sequences to all open terminals.
|
||||||
# pylint: disable=W0106
|
# pylint: disable=W0106
|
||||||
@ -96,7 +96,7 @@ def send_sequences(colors, vte):
|
|||||||
|
|
||||||
def reload_colors(vte):
|
def reload_colors(vte):
|
||||||
"""Reload colors."""
|
"""Reload colors."""
|
||||||
sequence_file = pathlib.Path(s.CACHE_DIR / "sequences")
|
sequence_file = pathlib.Path(g.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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user