Added support for date-relative event prefixes
This commit is contained in:
parent
9e67af6adc
commit
22242d894f
2 changed files with 12 additions and 10 deletions
|
@ -7,7 +7,7 @@ from TextFormatter import date_str
|
|||
class EventListDesign (DesignEntity):
|
||||
"""Creates a TableTextDesign filled with event
|
||||
begin date and title"""
|
||||
def __init__ (self, size, events, text_size = defaultfontsize, line_spacing = 2, col_spacing = 10, event_prefix_func = None, font_family = None, general_color = colors["fg"], background_color = colors["bg"], highlight_color = colors["hl"], show_more_info = False):
|
||||
def __init__ (self, size, events, text_size = defaultfontsize, line_spacing = 2, col_spacing = 10, event_prefix_rel_dates = [], event_prefix_func = None, font_family = None, general_color = colors["fg"], background_color = colors["bg"], highlight_color = colors["hl"], show_more_info = False):
|
||||
super(EventListDesign, self).__init__(size)
|
||||
self.events = events
|
||||
self.__event_matrix__ = []
|
||||
|
@ -21,8 +21,9 @@ class EventListDesign (DesignEntity):
|
|||
self.background_color = background_color
|
||||
self.highlight_color = highlight_color
|
||||
self.event_prefix_func = event_prefix_func
|
||||
self.event_prefix_rel_dates = event_prefix_rel_dates
|
||||
if self.event_prefix_func is None:
|
||||
self.event_prefix_func = lambda x : date_str(x.begin_datetime)
|
||||
self.event_prefix_func = lambda x, y : date_str(x.begin_datetime)
|
||||
|
||||
def __finish_image__ (self):
|
||||
self.visible_event_count = int(int(self.size[1] + self.line_spacing) // (self.line_spacing + int(self.text_size)))
|
||||
|
@ -32,16 +33,17 @@ class EventListDesign (DesignEntity):
|
|||
table_design = TableTextDesign(self.size, background_color = self.background_color, 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__)
|
||||
self.draw_design(table_design)
|
||||
|
||||
def __get_formatted_event__ (self, event):
|
||||
prefix = self.event_prefix_func(event)
|
||||
def __get_formatted_event__ (self, event, index):
|
||||
rel_date = None if index < 0 or index >= len(self.event_prefix_rel_dates) else self.event_prefix_rel_dates[index]
|
||||
prefix = self.event_prefix_func(event, rel_date)
|
||||
return [ prefix, event.title ]
|
||||
|
||||
def __fill_event_matrix__ (self):
|
||||
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:
|
||||
row = self.__get_formatted_event__(event)
|
||||
for i, event in enumerate(visible_events):
|
||||
row = self.__get_formatted_event__(event, i)
|
||||
self.__event_matrix__.append(row)
|
||||
self.__props_matrix__.append(self.__get_row_props__(event))
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
from EventListDesign import EventListDesign
|
||||
from settings import hours
|
||||
from Assets import fonts, defaultfontsize, colors
|
||||
from TextFormatter import event_time_summary
|
||||
from TextFormatter import event_prefix_str
|
||||
|
||||
font = fonts["regular"]
|
||||
|
||||
class SingelDayEventListDesign (EventListDesign):
|
||||
"""Specialized event list for day list design."""
|
||||
def __init__ (self, size, events, font_size = defaultfontsize, line_spacing=2, col_spacing=5, general_color=colors["fg"], background_color=colors["bg"], highlight_color=colors["hl"]):
|
||||
prefix_func = lambda x : self.__get_event_prefix__(x)
|
||||
super().__init__(size, events, text_size=font_size, line_spacing=line_spacing, col_spacing=col_spacing, event_prefix_func=event_time_summary, font_family=font, show_more_info=True, general_color=general_color, background_color=background_color, highlight_color = highlight_color)
|
||||
def __init__ (self, size, events, font_size = defaultfontsize, line_spacing=2, event_prefix_rel_dates = [], col_spacing=5, general_color=colors["fg"], background_color=colors["bg"], highlight_color=colors["hl"]):
|
||||
prefix_func = lambda x, rel_date : event_prefix_str(x, rel_date)
|
||||
super().__init__(size, events, text_size=font_size, line_spacing=line_spacing, col_spacing=col_spacing, event_prefix_rel_dates = event_prefix_rel_dates, event_prefix_func=prefix_func, font_family=font, show_more_info=True, general_color=general_color, background_color=background_color, highlight_color = highlight_color)
|
Loading…
Reference in a new issue