diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-06-21 21:47:39 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-06-21 21:47:39 +1000 |
| commit | b684e1604e0fe4613b74bcf7f43ac07c6daba9b1 (patch) | |
| tree | 3890a9336a9bd2e58665f5045c0c82dcb301b182 | |
| parent | f6a1a3964ad790a40f97d5656d6e5c302a1ee926 (diff) | |
wallpaper: Exclude current image from shuffle
| -rwxr-xr-x | wal | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -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): |
