2019-03-03 14:00:10 +01:00
|
|
|
from DesignEntity import DesignEntity
|
|
|
|
from TableTextDesign import TableTextDesign
|
|
|
|
|
|
|
|
class EventListDesign (DesignEntity):
|
|
|
|
"""Creates a TableTextDesign filled with event
|
|
|
|
begin date and title"""
|
2019-03-23 12:22:55 +01:00
|
|
|
def __init__ (self, size, events, text_size = 16, line_spacing = 2, col_spacing = 10, event_prefix_func = None, font_family = None, general_color = "black", background_color = "white", highlight_color = "red", show_more_info = False):
|
2019-03-03 14:00:10 +01:00
|
|
|
super(EventListDesign, self).__init__(size)
|
2019-03-17 20:55:45 +01:00
|
|
|
self.events = events
|
2019-03-03 14:00:10 +01:00
|
|
|
self.__event_matrix__ = []
|
2019-03-10 19:10:30 +01:00
|
|
|
self.__props_matrix__ = []
|
2019-03-23 12:22:55 +01:00
|
|
|
self.show_more_info = show_more_info
|
2019-03-03 14:00:10 +01:00
|
|
|
self.text_size = text_size
|
2019-03-10 07:21:50 +01:00
|
|
|
self.line_spacing = line_spacing
|
2019-03-10 13:26:31 +01:00
|
|
|
self.col_spacing = col_spacing
|
2019-03-10 15:54:46 +01:00
|
|
|
self.font_family = font_family
|
2019-03-10 19:10:30 +01:00
|
|
|
self.general_color = general_color
|
|
|
|
self.background_color = background_color
|
|
|
|
self.highlight_color = highlight_color
|
2019-03-10 13:26:31 +01:00
|
|
|
self.event_prefix_func = event_prefix_func
|
|
|
|
if self.event_prefix_func is None:
|
|
|
|
self.event_prefix_func = lambda x : self.__remove_leading_zero__(x.begin_datetime.strftime('%d %b'))
|
2019-03-03 14:00:10 +01:00
|
|
|
|
|
|
|
def __finish_image__ (self):
|
2019-03-23 12:22:55 +01:00
|
|
|
self.visible_event_count = int((self.size[1] - self.line_spacing) // (self.line_spacing + self.text_size))
|
2019-03-03 14:00:10 +01:00
|
|
|
self.__fill_event_matrix__()
|
|
|
|
|
2019-03-23 12:22:55 +01:00
|
|
|
col_hori_alignment = [ 'right', 'left' ]
|
2019-03-10 19:10:30 +01:00
|
|
|
table_design = TableTextDesign(self.size, font=self.font_family, line_spacing=self.line_spacing, col_spacing=self.col_spacing, text_matrix=self.__event_matrix__, fontsize = self.text_size, column_horizontal_alignments=col_hori_alignment, mask=False, truncate_cols=False, cell_properties=self.__props_matrix__)
|
2019-03-03 14:00:10 +01:00
|
|
|
self.draw_design(table_design)
|
|
|
|
|
|
|
|
def __get_formatted_event__ (self, event):
|
2019-03-10 13:26:31 +01:00
|
|
|
prefix = self.event_prefix_func(event)
|
|
|
|
return [ prefix, event.title ]
|
2019-03-03 18:13:51 +01:00
|
|
|
|
2019-03-23 12:22:55 +01:00
|
|
|
def __remove_leading_zero__ (self, text):
|
2019-03-03 18:13:51 +01:00
|
|
|
while text[0] is '0':
|
|
|
|
text = text[1:]
|
|
|
|
return text
|
2019-03-03 14:00:10 +01:00
|
|
|
|
|
|
|
def __fill_event_matrix__ (self):
|
2019-03-23 12:22:55 +01:00
|
|
|
visible_events = self.events
|
|
|
|
if self.show_more_info and len(visible_events) > self.visible_event_count:
|
|
|
|
visible_events = visible_events[:self.visible_event_count - 1]
|
|
|
|
for event in visible_events:
|
2019-03-03 14:00:10 +01:00
|
|
|
row = self.__get_formatted_event__(event)
|
2019-03-10 07:21:50 +01:00
|
|
|
self.__event_matrix__.append(row)
|
2019-03-10 19:10:30 +01:00
|
|
|
self.__props_matrix__.append(self.__get_row_props__(event))
|
2019-03-10 07:21:50 +01:00
|
|
|
|
2019-03-23 12:22:55 +01:00
|
|
|
if self.show_more_info is False:
|
|
|
|
return
|
|
|
|
|
|
|
|
additional_events_count = len(self.events) - len(visible_events)
|
|
|
|
if additional_events_count > 0:
|
|
|
|
self.__event_matrix__.append([ "", " + " + str(additional_events_count) + " more" ])
|
|
|
|
self.__props_matrix__.append(self.__get_row_props__(event))
|
|
|
|
|
|
|
|
def __get_row_props__ (self, event=None):
|
2019-03-10 19:10:30 +01:00
|
|
|
color = self.general_color
|
|
|
|
bg_color = self.background_color
|
2019-03-23 12:22:55 +01:00
|
|
|
if event is not None and event.highlight:
|
2019-03-10 19:10:30 +01:00
|
|
|
color = self.highlight_color
|
|
|
|
cell = {
|
|
|
|
"color" : color,
|
|
|
|
"background_color" : bg_color
|
|
|
|
}
|
2019-03-23 12:22:55 +01:00
|
|
|
return [ cell, cell ]
|