mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-03-10 13:08:17 +01:00
wallpaper: Exclude current image from shuffle
This commit is contained in:
parent
f6a1a3964a
commit
b684e1604e
24
wal
24
wal
@ -124,8 +124,18 @@ def get_image(img):
|
|||||||
# Pick a random image from the directory.
|
# Pick a random image from the directory.
|
||||||
elif image.is_dir():
|
elif image.is_dir():
|
||||||
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
|
file_types = (".png", ".jpg", ".jpeg", ".jpe", ".gif")
|
||||||
|
|
||||||
|
# Get the filename of the current wallpaper.
|
||||||
|
current_img = pathlib.Path(CACHE_DIR / "wal")
|
||||||
|
|
||||||
|
if current_img.is_file():
|
||||||
|
current_img = read_file(current_img)
|
||||||
|
current_img = os.path.basename(current_img[0])
|
||||||
|
|
||||||
|
# Get a list of images.
|
||||||
images = [img for img in os.listdir(image)
|
images = [img for img in os.listdir(image)
|
||||||
if img.endswith(file_types)]
|
if img.endswith(file_types) and
|
||||||
|
img != current_img]
|
||||||
|
|
||||||
rand_img = random.choice(images)
|
rand_img = random.choice(images)
|
||||||
rand_img = pathlib.Path(image / rand_img)
|
rand_img = pathlib.Path(image / rand_img)
|
||||||
@ -185,7 +195,7 @@ def get_colors(img):
|
|||||||
file.write("%s\n" % (img))
|
file.write("%s\n" % (img))
|
||||||
|
|
||||||
if cache_file.is_file():
|
if cache_file.is_file():
|
||||||
colors = read_colors(cache_file)
|
colors = read_file(cache_file)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("colors: Generating a colorscheme...")
|
print("colors: Generating a colorscheme...")
|
||||||
@ -476,14 +486,14 @@ def export_colors(colors):
|
|||||||
# OTHER FUNCTIONS {{{
|
# OTHER FUNCTIONS {{{
|
||||||
|
|
||||||
|
|
||||||
def read_colors(color_file):
|
def read_file(input_file):
|
||||||
"""Read colors from a file"""
|
"""Read colors from a file"""
|
||||||
with open(color_file) as file:
|
with open(input_file) as file:
|
||||||
colors = file.readlines()
|
contents = file.readlines()
|
||||||
|
|
||||||
# Strip newlines from each list element.
|
# Strip newlines from each list element.
|
||||||
colors = [x.strip() for x in colors]
|
contents = [x.strip() for x in contents]
|
||||||
return colors
|
return contents
|
||||||
|
|
||||||
|
|
||||||
def reload_colors(vte):
|
def reload_colors(vte):
|
||||||
|
Loading…
Reference in New Issue
Block a user