E-Paper-Calendar/Calendar/AgendaListPanel.py

91 lines
3 KiB
Python
Raw Permalink Normal View History

2019-03-24 21:30:44 +01:00
from PanelDesign import PanelDesign
2019-03-24 22:14:58 +01:00
from AgendaListDesign import AgendaListDesign
2019-04-07 11:35:26 +02:00
from WeatherHeaderDesign import WeatherHeaderDesign
from settings import general_settings, line_thickness
2019-04-07 11:35:26 +02:00
from PIL import ImageDraw
from Assets import colors
2019-04-07 12:45:21 +02:00
from RssPostListDesign import RssPostListDesign
from CryptoListDesign import CryptoListDesign
2019-03-24 22:14:58 +01:00
agenda_ypadding = 5
2019-04-07 11:35:26 +02:00
weatherheader_height = 0.113
seperator_width = line_thickness
2019-04-07 12:45:21 +02:00
infolist_size = (1, 0.24)
infolist_padding = 0
2019-03-24 21:30:44 +01:00
2019-07-13 08:05:35 +02:00
2019-03-24 21:30:44 +01:00
class AgendaListPanel (PanelDesign):
2019-03-24 22:14:58 +01:00
'''Lists upcoming events in chronological order and groups them by days'''
2019-07-13 08:05:35 +02:00
2019-03-24 22:14:58 +01:00
def __init__(self, size):
super(AgendaListPanel, self).__init__(size)
2019-04-07 11:35:26 +02:00
self.weather_size = (0, 0)
2019-04-07 12:45:21 +02:00
self.info_size = (0, 0)
2019-04-07 11:35:26 +02:00
if general_settings["weather-info"]:
2019-07-13 08:05:35 +02:00
self.weather_size = (
self.size[0], self.size[1] * weatherheader_height)
2019-03-24 22:14:58 +01:00
2019-07-13 08:05:35 +02:00
def add_weather(self, weather):
2019-04-07 11:35:26 +02:00
self.weather = weather
2019-03-24 22:14:58 +01:00
2019-07-13 08:05:35 +02:00
def add_calendar(self, calendar):
2019-04-07 12:45:21 +02:00
self.calendar = calendar
2019-03-24 22:14:58 +01:00
2019-07-13 08:05:35 +02:00
def add_rssfeed(self, rss):
2019-04-07 12:45:21 +02:00
if general_settings["info-area"] != "rss":
return
self.info_size = self.__abs_pos__(infolist_size)
pos = (0, self.size[1] - self.info_size[1] + infolist_padding)
list = RssPostListDesign(self.info_size, rss)
list.pos = pos
self.draw_design(list)
self.__draw_seperator__(1-infolist_size[1], colors["fg"])
2019-03-24 22:14:58 +01:00
2019-07-13 08:05:35 +02:00
def add_tasks(self, tasks):
2019-05-19 22:25:59 +02:00
pass
2019-07-13 08:05:35 +02:00
def add_crypto(self, crypto):
if general_settings["info-area"] != "crypto":
return
self.info_size = self.__abs_pos__(infolist_size)
pos = (0, self.size[1] - self.info_size[1] + infolist_padding)
list = CryptoListDesign(self.info_size, crypto)
height = list.get_estimated_height()
list.pos = (pos[0], pos[1] + (self.info_size[1] - height))
self.draw_design(list)
self.info_size = (self.size[0], height)
self.__draw_seperator__(list.pos[1] / self.size[1], colors["fg"])
2019-04-07 11:35:26 +02:00
def __finish_panel__(self):
2019-04-07 12:45:21 +02:00
self.__draw_calendar__()
if general_settings["weather-info"]:
self.__draw_weather__()
2019-04-07 11:35:26 +02:00
2019-07-13 08:05:35 +02:00
def __draw_seperator__(self, height, color):
ImageDraw.Draw(self.__image__).line([self.__abs_pos__(
(0, height)), self.__abs_pos__((1, height))], fill=color, width=seperator_width)
2019-04-07 11:35:26 +02:00
2019-07-13 08:05:35 +02:00
def __abs_pos__(self, pos, size=None):
2019-04-07 11:35:26 +02:00
if size is None:
size = self.size
2019-04-07 12:45:21 +02:00
return (int(pos[0] * size[0]), int(pos[1] * size[1]))
def __draw_calendar__(self):
2019-07-13 08:05:35 +02:00
size = (self.size[0], self.size[1] - self.weather_size[1] -
self.info_size[1] - agenda_ypadding)
2019-04-07 12:45:21 +02:00
agenda = AgendaListDesign(size, self.calendar)
agenda.pos = (0, agenda_ypadding + self.weather_size[1])
self.draw_design(agenda)
def __draw_weather__(self):
header = WeatherHeaderDesign(self.weather_size, self.weather)
self.draw_design(header)
2019-07-13 08:05:35 +02:00
self.__draw_seperator__(weatherheader_height, colors["hl"])