E-Paper-Calendar/Calendar/ImageFramePanel.py

62 lines
2 KiB
Python
Raw Normal View History

2019-07-12 13:46:50 +02:00
from PanelDesign import PanelDesign
from settings import general_settings
from Assets import supported_img_formats, path as application_path
from os import listdir
from os.path import isfile, join
from ImageDesign import ImageDesign
from random import choice
class ImageFramePanel (PanelDesign):
"""Converts the display into a digital frame and
shows a slide show of images, iterating on each update"""
2019-07-13 08:05:35 +02:00
def __init__(self, size):
2019-07-12 13:46:50 +02:00
super(ImageFramePanel, self).__init__(size)
2019-07-13 08:05:35 +02:00
self.overlay_path = self.__complete_path__(
general_settings["overlay-image"])
self.image_folder_path = self.__complete_path__(
general_settings["image-folder"])
2019-07-12 13:46:50 +02:00
self.images = self.__extract_valid_img_paths__()
self.__first_render__()
2019-07-13 08:05:35 +02:00
def __extract_valid_img_paths__(self):
2019-07-12 13:46:50 +02:00
images = []
for file in listdir(self.image_folder_path):
file_path = join(self.image_folder_path, file).replace('\\', '/')
if isfile(file_path) and self.overlay_path != file_path:
if file.split('.')[-1].upper() in supported_img_formats:
images.append(file_path)
return images
def __complete_path__(self, path):
path = path.replace('\\', '/')
if path[0] != '/' and ':' not in path[0:3]:
path = join(application_path, path)
return path
def __first_render__(self):
current_image = choice(self.images)
img = ImageDesign(self.size, current_image, fill="scale", color="1")
self.draw_design(img)
if self.overlay_path != "":
overlay = ImageDesign(self.size, self.overlay_path)
overlay.__finish_image__()
self.__image__.alpha_composite(overlay.__image__)
2019-07-13 08:05:35 +02:00
def add_weather(self, weather):
2019-07-12 13:46:50 +02:00
pass
2019-07-13 08:05:35 +02:00
def add_calendar(self, calendar):
2019-07-12 13:46:50 +02:00
pass
2019-07-13 08:05:35 +02:00
def add_rssfeed(self, rss):
2019-07-12 13:46:50 +02:00
pass
2019-07-13 08:05:35 +02:00
def add_crypto(self, crypto):
2019-07-12 13:46:50 +02:00
pass
2019-07-13 08:05:35 +02:00
def add_tasks(self, tasks):
2019-07-12 13:46:50 +02:00
pass