2019-03-17 12:12:58 +01:00
|
|
|
from PanelDesign import PanelDesign
|
|
|
|
from datetime import datetime, timedelta, date
|
2019-03-17 20:55:45 +01:00
|
|
|
from DayHeaderDesign import DayHeaderDesign
|
2019-03-17 22:05:49 +01:00
|
|
|
from HourListDesign import HourListDesign
|
2019-05-18 09:28:29 +02:00
|
|
|
from settings import general_settings
|
2019-04-09 12:40:10 +02:00
|
|
|
from RssPostListDesign import RssPostListDesign
|
|
|
|
from PIL import ImageDraw
|
|
|
|
from Assets import colors
|
|
|
|
from EventListDesign import EventListDesign
|
2019-05-18 09:28:29 +02:00
|
|
|
from CryptoListDesign import CryptoListDesign
|
|
|
|
|
2019-03-17 20:55:45 +01:00
|
|
|
|
|
|
|
header_size = (1, 0.2)
|
2019-03-17 22:05:49 +01:00
|
|
|
hourlist_size = (1, 1 - header_size[1])
|
2019-04-09 12:40:10 +02:00
|
|
|
default_shownhours_count = 12
|
|
|
|
|
|
|
|
infoarea_replaced_hours = 4
|
2019-05-18 09:28:29 +02:00
|
|
|
infoarea_borderline_width = 1
|
2019-04-09 12:40:10 +02:00
|
|
|
infoarea_padding = 5
|
2019-03-17 12:12:58 +01:00
|
|
|
|
|
|
|
class DayViewPanel (PanelDesign):
|
|
|
|
"""Overview that focuses on the current day and
|
|
|
|
shows a timeline split into hours."""
|
|
|
|
def __init__ (self, size):
|
|
|
|
super(DayViewPanel, self).__init__(size)
|
2019-04-09 12:40:10 +02:00
|
|
|
self.shownhours_count = default_shownhours_count
|
|
|
|
if general_settings["info-area"] not in ["", "empty"]:
|
|
|
|
self.shownhours_count -= infoarea_replaced_hours
|
2019-03-17 12:12:58 +01:00
|
|
|
self.__first_render__()
|
|
|
|
|
|
|
|
def __first_render__ (self):
|
2019-03-17 20:55:45 +01:00
|
|
|
self.__init_header__()
|
2019-03-17 22:05:49 +01:00
|
|
|
self.__init_hourlist__()
|
2019-03-17 12:12:58 +01:00
|
|
|
|
|
|
|
def add_weather (self, weather):
|
2019-03-17 20:55:45 +01:00
|
|
|
self.__header__.add_weather(weather)
|
2019-03-17 12:12:58 +01:00
|
|
|
|
|
|
|
def add_calendar (self, calendar):
|
2019-04-08 15:42:55 +02:00
|
|
|
allday_ev, timed_ev = self.__split_events__(calendar.get_today_events())
|
|
|
|
self.__header__.add_events(allday_ev)
|
|
|
|
self.__hourlist__.add_events(timed_ev)
|
2019-03-17 12:12:58 +01:00
|
|
|
|
2019-04-09 12:40:10 +02:00
|
|
|
if general_settings["info-area"] == "events":
|
|
|
|
self.__draw_event_list__(calendar)
|
|
|
|
self.__draw_infoarea_line__()
|
|
|
|
|
2019-03-17 12:12:58 +01:00
|
|
|
def add_rssfeed (self, rss):
|
2019-04-09 12:40:10 +02:00
|
|
|
if general_settings["info-area"] == "rss":
|
|
|
|
self.__draw_rss_feed__(rss)
|
|
|
|
self.__draw_infoarea_line__()
|
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
def add_cryptofeed (self, crypto):
|
|
|
|
if general_settings["info-area"] == "crypto":
|
|
|
|
self.__draw_crypto_feed__(crypto)
|
|
|
|
self.__draw_infoarea_line__()
|
|
|
|
|
2019-04-09 12:40:10 +02:00
|
|
|
def __draw_infoarea_line__(self):
|
|
|
|
height = infoarea_replaced_hours * self.__hourlist__.row_size[1]
|
|
|
|
ypos = self.size[1] - height
|
|
|
|
|
|
|
|
line_start = (0, ypos)
|
|
|
|
line_end = (self.size[0], ypos)
|
|
|
|
ImageDraw.Draw(self.__image__).line([ line_start, line_end ], fill=colors["fg"], width=infoarea_borderline_width)
|
|
|
|
|
|
|
|
def __draw_rss_feed__(self, rss):
|
|
|
|
height = infoarea_replaced_hours * self.__hourlist__.row_size[1] - infoarea_padding
|
|
|
|
size = (self.size[0], height)
|
|
|
|
pos = (0, self.size[1] - size[1])
|
|
|
|
|
|
|
|
rss = RssPostListDesign(size, rss)
|
|
|
|
rss.pos = pos
|
|
|
|
self.draw_design(rss)
|
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
def __draw_crypto_feed__(self, crypto):
|
|
|
|
height = infoarea_replaced_hours * self.__hourlist__.row_size[1] - infoarea_padding
|
|
|
|
size = (self.size[0], height)
|
|
|
|
pos = (0, self.size[1] - size[1])
|
|
|
|
|
|
|
|
crypto = CryptoListDesign(size, crypto)
|
|
|
|
crypto.pos = pos
|
|
|
|
self.draw_design(crypto)
|
|
|
|
|
|
|
|
|
2019-04-09 12:40:10 +02:00
|
|
|
def __draw_event_list__(self, calendar):
|
|
|
|
height = infoarea_replaced_hours * self.__hourlist__.row_size[1] - infoarea_padding
|
|
|
|
size = (self.size[0], height)
|
|
|
|
pos = (0, self.size[1] - size[1])
|
|
|
|
|
|
|
|
events = EventListDesign(size, calendar.get_upcoming_events())
|
|
|
|
events.pos = pos
|
|
|
|
self.draw_design(events)
|
2019-03-17 12:12:58 +01:00
|
|
|
|
|
|
|
def add_taks (self, tasks):
|
|
|
|
pass
|
|
|
|
|
2019-04-08 11:20:33 +02:00
|
|
|
def __finish_panel__ (self):
|
2019-03-17 20:55:45 +01:00
|
|
|
self.draw_design(self.__header__)
|
2019-03-17 22:05:49 +01:00
|
|
|
self.draw_design(self.__hourlist__)
|
2019-03-17 20:55:45 +01:00
|
|
|
|
|
|
|
def __init_header__ (self):
|
|
|
|
self.__header__ = DayHeaderDesign(self.__abs_co__(header_size), date.today())
|
|
|
|
self.__header__.pos = (0, 0)
|
|
|
|
|
2019-03-17 22:05:49 +01:00
|
|
|
def __init_hourlist__ (self):
|
2019-04-09 12:17:12 +02:00
|
|
|
start, end = self.__get_current_hour_range__()
|
2019-04-09 12:40:10 +02:00
|
|
|
size = self.__abs_co__(hourlist_size)
|
|
|
|
size = (size[0], size[1] * self.shownhours_count / default_shownhours_count)
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-04-09 12:40:10 +02:00
|
|
|
self.__hourlist__ = HourListDesign(size, start, end)
|
2019-03-17 22:05:49 +01:00
|
|
|
self.__hourlist__.pos = (0, self.__header__.size[1])
|
|
|
|
|
2019-04-09 12:17:12 +02:00
|
|
|
def __get_current_hour_range__(self):
|
|
|
|
start_hour = datetime.now().hour
|
2019-04-09 13:37:39 +02:00
|
|
|
additional_hours = self.shownhours_count - 1
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-04-09 13:37:39 +02:00
|
|
|
if start_hour + additional_hours > 23:
|
|
|
|
start_hour = 23 - additional_hours
|
2019-04-09 12:17:12 +02:00
|
|
|
|
2019-04-09 13:37:39 +02:00
|
|
|
return start_hour, start_hour + additional_hours
|
2019-04-09 12:17:12 +02:00
|
|
|
|
2019-04-08 15:42:55 +02:00
|
|
|
def __abs_co__ (self, coordinates):
|
|
|
|
return (int(coordinates[0] * self.size[0]),int(coordinates[1] * self.size[1]))
|
2019-03-17 12:12:58 +01:00
|
|
|
|
2019-04-08 15:42:55 +02:00
|
|
|
def __split_events__ (self, events):
|
|
|
|
allday_ev = []
|
|
|
|
timed_ev = []
|
2019-03-17 22:05:49 +01:00
|
|
|
|
2019-04-08 15:42:55 +02:00
|
|
|
for event in events:
|
|
|
|
if event.allday:
|
|
|
|
allday_ev.append(event)
|
|
|
|
elif event.multiday:
|
|
|
|
if self.__is_today__(event.begin_datetime):
|
2019-04-08 16:21:06 +02:00
|
|
|
timed_ev.append(event)
|
2019-04-08 15:42:55 +02:00
|
|
|
elif self.__is_today__(event.end_datetime):
|
2019-04-08 16:21:06 +02:00
|
|
|
timed_ev.append(event)
|
2019-04-08 15:42:55 +02:00
|
|
|
else:
|
|
|
|
allday_ev.append(event)
|
|
|
|
else:
|
|
|
|
timed_ev.append(event)
|
|
|
|
return allday_ev, timed_ev
|
|
|
|
|
|
|
|
def __is_today__ (self, dt):
|
|
|
|
today = date.today()
|
|
|
|
return dt.day == today.day and \
|
|
|
|
dt.month == today.month and \
|
2019-05-18 09:28:29 +02:00
|
|
|
dt.year == today.year
|