wallpaper: Exclude current image from shuffle
@@ -124,8 +124,18 @@ def get_image(img):
# Pick a random image from the directory.
elif image.is_dir():
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)
- if img.endswith(file_types)]
+ if img.endswith(file_types) and
+ img != current_img]
rand_img = random.choice(images)
rand_img = pathlib.Path(image / rand_img)
@@ -185,7 +195,7 @@ def get_colors(img):
file.write("%s\n" % (img))
if cache_file.is_file():
- colors = read_colors(cache_file)
+ colors = read_file(cache_file)
else:
print("colors: Generating a colorscheme...")
@@ -476,14 +486,14 @@ def export_colors(colors):
# OTHER FUNCTIONS {{{
-def read_colors(color_file):
+def read_file(input_file):
"""Read colors from a file"""
- with open(color_file) as file:
- colors = file.readlines()
+ with open(input_file) as file:
+ contents = file.readlines()
# Strip newlines from each list element.
- colors = [x.strip() for x in colors]
- return colors
+ contents = [x.strip() for x in contents]
+ return contents
def reload_colors(vte):
