From b2c2e8871f8a552723b71018e6edead7ec40121f Mon Sep 17 00:00:00 2001 From: andreamah Date: Mon, 20 Apr 2020 15:21:19 -0700 Subject: [PATCH 1/2] slideshow nav fixed --- src/clue/adafruit_slideshow.py | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/clue/adafruit_slideshow.py b/src/clue/adafruit_slideshow.py index 7e5cecd2c..6a891ac1c 100644 --- a/src/clue/adafruit_slideshow.py +++ b/src/clue/adafruit_slideshow.py @@ -5,7 +5,6 @@ from io import BytesIO from base_circuitpython import base_cp_constants as CONSTANTS import time -import collections from random import shuffle import common import board @@ -165,6 +164,7 @@ def __init__( self._order = order self._curr_img = "" + self._current_image_index = -1 # load images into main queue self.__load_images() @@ -219,41 +219,43 @@ def update(self): def __get_next_img(self): - # handle empty queue - if not len(self.pic_queue): - if self.loop: + if self.direction == PlayBackDirection.FORWARD: + self._current_image_index +=1 + + if (self._current_image_index>= len(self.dir_imgs)): self.__load_images() - else: - return "" + self._current_image_index = 0 - if self.direction == PlayBackDirection.FORWARD: - return self.pic_queue.popleft() else: - return self.pic_queue.pop() + self._current_image_index -=1 + + if (self._current_image_index< 0): + self.__load_images() + self._current_image_index = len(self.dir_imgs)-1 + img = self.dir_imgs[self._current_image_index] + return img + def __load_images(self): - dir_imgs = [] + self.dir_imgs = [] for d in self.dirs: try: new_path = os.path.join(self.folder, d) # only add bmp imgs if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING: - dir_imgs.append(new_path) + self.dir_imgs.append(new_path) except Image.UnidentifiedImageError as e: continue - if not len(dir_imgs): + if not len(self.dir_imgs): raise RuntimeError(CONSTANTS.NO_VALID_IMGS_ERR) if self._order == PlayBackOrder.RANDOM: - shuffle(dir_imgs) + shuffle(self.dir_imgs) else: - dir_imgs.sort() - - # convert list to queue - # (must be list beforehand for potential randomization) - self.pic_queue = collections.deque(dir_imgs) + self.dir_imgs.sort() + def __advance_with_fade(self): if board.DISPLAY.active_group != self: From 9cb68669d9cda4b915c1a275779a9349e2d1efc0 Mon Sep 17 00:00:00 2001 From: andreamah Date: Mon, 20 Apr 2020 16:12:14 -0700 Subject: [PATCH 2/2] incorporating looping --- src/clue/adafruit_slideshow.py | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/clue/adafruit_slideshow.py b/src/clue/adafruit_slideshow.py index 6a891ac1c..aa1fb6b65 100644 --- a/src/clue/adafruit_slideshow.py +++ b/src/clue/adafruit_slideshow.py @@ -164,7 +164,7 @@ def __init__( self._order = order self._curr_img = "" - self._current_image_index = -1 + self._current_image_index = None # load images into main queue self.__load_images() @@ -220,22 +220,37 @@ def update(self): def __get_next_img(self): if self.direction == PlayBackDirection.FORWARD: - self._current_image_index +=1 - - if (self._current_image_index>= len(self.dir_imgs)): - self.__load_images() + if self._current_image_index == None: self._current_image_index = 0 + else: + self._current_image_index += 1 + + if self._current_image_index >= len(self.dir_imgs): + + if self.loop: + self._current_image_index = 0 + self.__load_images() + else: + self._current_image_index = len(self.dir_imgs) - 10 + return "" else: - self._current_image_index -=1 - - if (self._current_image_index< 0): - self.__load_images() - self._current_image_index = len(self.dir_imgs)-1 + if self._current_image_index == None: + self._current_image_index = len(self.dir_imgs) - 1 + else: + self._current_image_index -= 1 + + if self._current_image_index < 0: + if self.loop: + self._current_image_index = len(self.dir_imgs) - 1 + self.__load_images() + else: + self._current_image_index = 0 + return "" img = self.dir_imgs[self._current_image_index] return img - + def __load_images(self): self.dir_imgs = [] for d in self.dirs: @@ -243,7 +258,7 @@ def __load_images(self): new_path = os.path.join(self.folder, d) # only add bmp imgs - if os.path.splitext(new_path)[1] == CONSTANTS.BMP_IMG_ENDING: + if os.path.splitext(new_path)[-1] == CONSTANTS.BMP_IMG_ENDING: self.dir_imgs.append(new_path) except Image.UnidentifiedImageError as e: continue @@ -255,7 +270,6 @@ def __load_images(self): shuffle(self.dir_imgs) else: self.dir_imgs.sort() - def __advance_with_fade(self): if board.DISPLAY.active_group != self: @@ -267,6 +281,7 @@ def __advance_with_fade(self): while not advance_sucessful: new_path = self.__get_next_img() if new_path == "": + self._img_start = time.monotonic() return False try: @@ -325,6 +340,7 @@ def __advance_no_fade(self): while not advance_sucessful: new_path = self.__get_next_img() if new_path == "": + self._img_start = time.monotonic() return False try: