2019-03-24 22:14:58 +01:00
|
|
|
from DesignEntity import DesignEntity
|
2019-04-05 11:37:51 +02:00
|
|
|
from Assets import defaultfontsize, colors
|
2019-03-24 22:14:58 +01:00
|
|
|
from datetime import datetime, date, timedelta
|
2019-03-26 22:30:01 +01:00
|
|
|
from TableTextDesign import TableTextDesign
|
|
|
|
from PIL import ImageDraw
|
2019-04-05 22:07:47 +02:00
|
|
|
from TextFormatter import date_summary_str, event_prefix_str
|
2019-03-26 22:30:01 +01:00
|
|
|
|
|
|
|
line_width = 1
|
2019-03-24 22:14:58 +01:00
|
|
|
|
|
|
|
class AgendaListDesign (DesignEntity):
|
|
|
|
'''Lists upcoming events in chronological order and groups them by days'''
|
2019-03-27 18:26:54 +01:00
|
|
|
def __init__ (self, size, calendar, line_spacing = 3, col_spacing = 6, text_size = defaultfontsize, start_date = date.today()):
|
2019-03-24 22:14:58 +01:00
|
|
|
super(AgendaListDesign, self).__init__(size)
|
|
|
|
self.calendar = calendar
|
|
|
|
self.line_spacing = line_spacing
|
2019-03-27 18:26:54 +01:00
|
|
|
self.col_spacing = col_spacing
|
2019-03-24 22:14:58 +01:00
|
|
|
self.text_size = text_size
|
|
|
|
self.start_dt = datetime(start_date.year, start_date.month, start_date.day)
|
|
|
|
|
|
|
|
def __finish_image__ (self):
|
|
|
|
self.__calculate_parameter__()
|
2019-03-27 18:26:54 +01:00
|
|
|
self.__create_infos_events__()
|
|
|
|
self.__draw_infos__()
|
2019-03-26 22:30:01 +01:00
|
|
|
self.__draw_lines__()
|
2019-03-24 22:14:58 +01:00
|
|
|
|
|
|
|
def __calculate_parameter__ (self):
|
|
|
|
self.__line_height__ = self.line_spacing + int(self.text_size)
|
|
|
|
self.__event_number__ = int(int(self.size[1]) // self.__line_height__)
|
2019-03-26 22:30:01 +01:00
|
|
|
self.__date_fontsize__ = self.text_size
|
|
|
|
self.__date_linespace__ = self.line_spacing
|
2019-03-24 22:14:58 +01:00
|
|
|
|
2019-03-27 18:26:54 +01:00
|
|
|
def __create_infos_events__ (self):
|
|
|
|
self.infos = []
|
|
|
|
last_date = ""
|
2019-03-24 22:14:58 +01:00
|
|
|
fetch_day = self.start_dt
|
2019-03-27 18:26:54 +01:00
|
|
|
while len(self.infos) < self.__event_number__:
|
2019-03-26 22:30:01 +01:00
|
|
|
day_events = self.calendar.get_day_events(fetch_day)
|
2019-03-27 18:26:54 +01:00
|
|
|
fetch_day_added_once = False
|
|
|
|
for event in day_events:
|
|
|
|
row = [ "" ]
|
|
|
|
if fetch_day_added_once is False:
|
|
|
|
row.append(date_summary_str(fetch_day))
|
|
|
|
fetch_day_added_once = True
|
|
|
|
else:
|
|
|
|
row.append("")
|
|
|
|
|
2019-04-05 22:07:47 +02:00
|
|
|
row.append(event_prefix_str(event, fetch_day))
|
2019-03-27 18:26:54 +01:00
|
|
|
row.append(event.title)
|
|
|
|
|
|
|
|
self.infos.append(row)
|
2019-03-24 22:14:58 +01:00
|
|
|
fetch_day = fetch_day + timedelta(1)
|
|
|
|
|
2019-03-27 18:26:54 +01:00
|
|
|
def __draw_infos__ (self):
|
|
|
|
table = TableTextDesign(self.size, self.infos, fontsize = self.__date_fontsize__, line_spacing=self.__date_linespace__, col_spacing = self.col_spacing, truncate_cols = False)
|
2019-03-26 22:30:01 +01:00
|
|
|
self.draw_design(table)
|
|
|
|
|
2019-03-24 22:14:58 +01:00
|
|
|
def __draw_lines__ (self):
|
2019-03-27 18:26:54 +01:00
|
|
|
for i, (_, date, _, _) in enumerate(self.infos[1:]):
|
|
|
|
if date is not "":
|
2019-03-26 22:30:01 +01:00
|
|
|
self.__draw_line__(i + 1)
|
|
|
|
|
2019-03-27 18:26:54 +01:00
|
|
|
def __draw_line__ (self, index):
|
2019-03-26 22:30:01 +01:00
|
|
|
ypos = index * self.__line_height__ - self.line_spacing / 2
|
|
|
|
pos = (0, ypos)
|
2019-03-27 18:26:54 +01:00
|
|
|
positions = [ pos, (self.size[0], ypos) ]
|
2019-03-26 22:30:01 +01:00
|
|
|
|
2019-04-05 11:37:51 +02:00
|
|
|
ImageDraw.Draw(self.__image__).line(positions, fill=colors["fg"], width=line_width)
|