checkpoint
This commit is contained in:
@@ -8,13 +8,13 @@ from inkycal.custom import *
|
||||
# PIL has a class named Image, use alias for Inkyimage -> Images
|
||||
from inkycal.modules.inky_image import Inkyimage as Images, image_to_palette
|
||||
from inkycal.modules.template import inkycal_module
|
||||
from inkycal.utils.json_cache import JSONCache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Slideshow(inkycal_module):
|
||||
"""Cycles through images in a local image folder
|
||||
"""
|
||||
"""Cycles through images in a local image folder"""
|
||||
name = "Slideshow - cycle through images from a local folder"
|
||||
|
||||
requires = {
|
||||
@@ -53,7 +53,7 @@ class Slideshow(inkycal_module):
|
||||
|
||||
# required parameters
|
||||
for param in self.requires:
|
||||
if not param in config:
|
||||
if param not in config:
|
||||
raise Exception(f'config is missing {param}')
|
||||
|
||||
# optional parameters
|
||||
@@ -64,14 +64,15 @@ class Slideshow(inkycal_module):
|
||||
|
||||
# Get the full path of all png/jpg/jpeg images in the given folder
|
||||
all_files = glob.glob(f'{self.path}/*')
|
||||
self.images = [i for i in all_files
|
||||
if i.split('.')[-1].lower() in ('jpg', 'jpeg', 'png')]
|
||||
self.images = [i for i in all_files if i.split('.')[-1].lower() in ('jpg', 'jpeg', 'png')]
|
||||
|
||||
if not self.images:
|
||||
logger.error('No images found in the given folder, please '
|
||||
'double check your path!')
|
||||
logger.error('No images found in the given folder, please double check your path!')
|
||||
raise Exception('No images found in the given folder path :/')
|
||||
|
||||
self.cache = JSONCache('inkycal_slideshow')
|
||||
self.cache_data = self.cache.read()
|
||||
|
||||
# set a 'first run' signal
|
||||
self._first_run = True
|
||||
|
||||
@@ -89,14 +90,16 @@ class Slideshow(inkycal_module):
|
||||
logger.info(f'Image size: {im_size}')
|
||||
|
||||
# rotates list items by 1 index
|
||||
def rotate(somelist):
|
||||
return somelist[1:] + somelist[:1]
|
||||
def rotate(list: list):
|
||||
return list[1:] + list[:1]
|
||||
|
||||
# Switch to the next image if this is not the first run
|
||||
if self._first_run:
|
||||
self._first_run = False
|
||||
self.cache_data["current_index"] = 0
|
||||
else:
|
||||
self.images = rotate(self.images)
|
||||
self.cache_data["current_index"] = (self.cache_data["current_index"] + 1) % len(self.images)
|
||||
|
||||
# initialize custom image class
|
||||
im = Images()
|
||||
@@ -110,7 +113,7 @@ class Slideshow(inkycal_module):
|
||||
# Remove background if present
|
||||
im.remove_alpha()
|
||||
|
||||
# if autoflip was enabled, flip the image
|
||||
# if auto-flip was enabled, flip the image
|
||||
if self.autoflip:
|
||||
im.autoflip(self.orientation)
|
||||
|
||||
@@ -123,6 +126,8 @@ class Slideshow(inkycal_module):
|
||||
# with the images now send, clear the current image
|
||||
im.clear()
|
||||
|
||||
self.cache.write(self.cache_data)
|
||||
|
||||
# return images
|
||||
return im_black, im_colour
|
||||
|
||||
|
Reference in New Issue
Block a user