2019-03-07 21:28:11 +01:00
|
|
|
from PanelDesign import PanelDesign
|
2019-05-01 07:17:40 +02:00
|
|
|
from Assets import colors
|
|
|
|
from settings import general_settings
|
2019-05-18 09:28:29 +02:00
|
|
|
import calendar as callib
|
2019-03-08 21:37:54 +01:00
|
|
|
from datetime import datetime, timedelta, date
|
2019-03-07 21:28:11 +01:00
|
|
|
from PIL import ImageDraw
|
|
|
|
from TextDesign import TextDesign
|
|
|
|
from DayHeaderDesign import DayHeaderDesign
|
2019-03-08 21:37:54 +01:00
|
|
|
from DayRowDesign import DayRowDesign
|
2019-03-13 22:28:25 +01:00
|
|
|
from RssPostListDesign import RssPostListDesign
|
2019-05-18 09:28:29 +02:00
|
|
|
from CryptoListDesign import CryptoListDesign
|
2019-05-17 05:33:35 +02:00
|
|
|
from settings import line_thickness
|
2019-05-21 14:52:38 +02:00
|
|
|
from math import ceil
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
todayheader_pos = (0,0)
|
|
|
|
todayheader_size = (1,0.25)
|
2019-05-17 05:33:35 +02:00
|
|
|
lines_thickness = line_thickness
|
2019-03-13 22:28:25 +01:00
|
|
|
infoarea_replacedrowscount = 3
|
2019-03-07 21:28:11 +01:00
|
|
|
|
2019-03-08 21:37:54 +01:00
|
|
|
dayrowsarea_ypos = todayheader_size[1]
|
|
|
|
dayrowsarea_height = 1 - todayheader_size[1]
|
2019-03-13 22:14:54 +01:00
|
|
|
dayrow_min_format = 50 / 384
|
|
|
|
dayrow_max_format = 70 / 384
|
2019-03-16 18:37:34 +01:00
|
|
|
rss_y_padding = 5
|
2019-05-18 09:28:29 +02:00
|
|
|
crypto_y_padding = 5
|
2019-03-08 21:37:54 +01:00
|
|
|
|
2019-03-07 21:28:11 +01:00
|
|
|
class DayListPanel (PanelDesign):
|
|
|
|
"""Overview that focuses on the current day and
|
|
|
|
lists following days in a list below."""
|
|
|
|
def __init__ (self, size):
|
|
|
|
super(DayListPanel, self).__init__(size)
|
|
|
|
self.__day_rows__ = []
|
2019-03-08 21:37:54 +01:00
|
|
|
self.__calc_dayrow_size__()
|
|
|
|
self.__first_render__()
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
def __first_render__ (self):
|
|
|
|
self.__draw_today_header__()
|
2019-03-08 21:37:54 +01:00
|
|
|
self.__draw_day_rows__()
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
def add_weather (self, weather):
|
2019-03-09 15:23:09 +01:00
|
|
|
for row in self.__day_rows__:
|
|
|
|
row.add_weather(weather)
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
def add_calendar (self, calendar):
|
2019-03-09 15:23:09 +01:00
|
|
|
for row in self.__day_rows__:
|
|
|
|
row.add_calendar(calendar)
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
def add_rssfeed (self, rss):
|
2019-03-09 15:23:09 +01:00
|
|
|
for row in self.__day_rows__:
|
|
|
|
row.add_rssfeed(rss)
|
2019-03-13 22:28:25 +01:00
|
|
|
if general_settings["info-area"] is "rss":
|
2019-05-21 14:52:38 +02:00
|
|
|
self.__day_rows__ = self.__day_rows__[:-infoarea_replacedrowscount]
|
2019-03-13 22:28:25 +01:00
|
|
|
self.__draw_rss_infoarea__(rss)
|
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
def add_crypto (self, crypto):
|
|
|
|
if general_settings["info-area"] is "crypto":
|
|
|
|
self.__draw_crypto_infoarea__(crypto)
|
|
|
|
|
2019-05-19 22:25:59 +02:00
|
|
|
def add_tasks (self, tasks):
|
|
|
|
pass
|
|
|
|
|
2019-03-13 22:28:25 +01:00
|
|
|
def __draw_rss_infoarea__ (self, rss):
|
2019-03-16 18:37:34 +01:00
|
|
|
height = infoarea_replacedrowscount * self.dayrow_size[1] * self.size[1] - rss_y_padding
|
2019-03-13 22:28:25 +01:00
|
|
|
ypos = self.size[1] - height
|
|
|
|
size = (self.size[0], height)
|
|
|
|
pos = (0, ypos)
|
|
|
|
|
2019-03-24 21:27:32 +01:00
|
|
|
design = RssPostListDesign(size, rss)
|
2019-03-13 22:28:25 +01:00
|
|
|
design.pos = pos
|
|
|
|
self.draw_design(design)
|
2019-03-07 21:28:11 +01:00
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
def __draw_crypto_infoarea__ (self, crypto):
|
|
|
|
height = infoarea_replacedrowscount * self.dayrow_size[1] * self.size[1] - crypto_y_padding
|
|
|
|
ypos = self.size[1] - height
|
|
|
|
size = (self.size[0], height)
|
|
|
|
pos = (0, ypos)
|
|
|
|
|
|
|
|
design = CryptoListDesign(size, crypto)
|
2019-05-21 14:52:38 +02:00
|
|
|
acutal_height = design.get_estimated_height()
|
|
|
|
design.pos = (pos[0], pos[1] + (height - acutal_height))
|
2019-05-18 09:28:29 +02:00
|
|
|
self.draw_design(design)
|
2019-05-21 14:52:38 +02:00
|
|
|
|
|
|
|
replaced_rows = ceil(acutal_height / (self.dayrow_size[1] * self.size[1]))
|
|
|
|
self.__day_rows__ = self.__day_rows__[:-replaced_rows]
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-03-08 21:37:54 +01:00
|
|
|
def __draw_day_rows__ (self):
|
|
|
|
following_days = self.__get_following_days__()
|
|
|
|
for i, date in enumerate(following_days):
|
|
|
|
row = DayRowDesign(self.__abs_co__(self.dayrow_size), date)
|
|
|
|
row.pos = self.__get_day_row_pos__(i)
|
|
|
|
self.__day_rows__.append(row)
|
|
|
|
|
|
|
|
def __get_day_row_pos__ (self, i):
|
|
|
|
ypos = self.size[1] * dayrowsarea_ypos
|
|
|
|
down_shift = i * self.dayrow_size[1] * self.size[1]
|
|
|
|
return (0, int(ypos + down_shift))
|
|
|
|
|
|
|
|
def __calc_dayrow_size__ (self):
|
|
|
|
max_area_height = dayrowsarea_height * self.size[1]
|
2019-03-13 22:14:54 +01:00
|
|
|
max_row_number = max_area_height / (dayrow_min_format * self.size[0])
|
|
|
|
min_row_number = max_area_height / (dayrow_max_format * self.size[0])
|
2019-03-08 21:37:54 +01:00
|
|
|
average_row_number = (max_row_number + min_row_number) / 2
|
|
|
|
self.dayrow_count = round(average_row_number)
|
|
|
|
row_height = max_area_height / self.dayrow_count
|
|
|
|
self.dayrow_size = (1, row_height / self.size[1])
|
|
|
|
|
|
|
|
def __get_following_days__(self):
|
|
|
|
following_days = []
|
|
|
|
for i in range(self.dayrow_count):
|
|
|
|
following_days.append(date.today() + timedelta(days=i + 1))
|
|
|
|
return following_days
|
|
|
|
|
2019-03-07 21:28:11 +01:00
|
|
|
def __draw_today_header__ (self):
|
2019-03-08 21:37:54 +01:00
|
|
|
header = DayHeaderDesign(self.__abs_co__(todayheader_size), date.today())
|
2019-03-07 21:28:11 +01:00
|
|
|
header.pos = self.__abs_co__(todayheader_pos)
|
2019-03-08 21:37:54 +01:00
|
|
|
self.__day_rows__.append(header)
|
|
|
|
|
|
|
|
def __draw_lines__(self):
|
|
|
|
positions = []
|
2019-05-21 14:52:38 +02:00
|
|
|
for i in range(len(self.__day_rows__)):
|
2019-03-08 21:37:54 +01:00
|
|
|
positions.append(self.__get_day_row_pos__(i)[1])
|
|
|
|
for ypos in positions:
|
|
|
|
line_start = (0, ypos)
|
|
|
|
line_end = (self.size[0], ypos)
|
2019-04-05 11:37:51 +02:00
|
|
|
ImageDraw.Draw(self.__image__).line([line_start, line_end], fill=colors["fg"], width=lines_thickness)
|
2019-03-07 21:28:11 +01:00
|
|
|
|
2019-04-08 11:20:33 +02:00
|
|
|
def __finish_panel__(self):
|
2019-03-08 21:37:54 +01:00
|
|
|
for design in self.__day_rows__:
|
|
|
|
self.draw_design(design)
|
|
|
|
self.__draw_lines__()
|
2019-03-07 21:28:11 +01:00
|
|
|
|
|
|
|
def __abs_co__(self, coordinates):
|
2019-05-18 09:28:29 +02:00
|
|
|
return (int(coordinates[0] * self.size[0]),int(coordinates[1] * self.size[1]))
|