From 2d79ac26fdf3ba0110a6b5d9934559d32c8f9363 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 9 Apr 2019 10:48:59 +0200 Subject: [PATCH] Added column aware event drawing and event title wrapping --- Calendar/HourListDesign.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Calendar/HourListDesign.py b/Calendar/HourListDesign.py index ab66170..96f3fa3 100644 --- a/Calendar/HourListDesign.py +++ b/Calendar/HourListDesign.py @@ -30,9 +30,7 @@ class HourListDesign (DesignEntity): self.__calc_parameters__() self.__draw_hour_rows__() self.__draw_lines__() - - for event in self.events: - self.__draw_event__(event) + self.__draw_events__() def __calc_parameters__ (self): self.hour_count = self.last_hour - self.first_hour + 1 @@ -53,6 +51,25 @@ class HourListDesign (DesignEntity): row_height = self.__row_size__[1] return row_height * (hours + minutes / 60) + def __draw_events__ (self): + column_events = [] + for _ in range(self.number_columns): + column_events.append(None) + for event in self.events: + column_events = self.__update_columns_events__(column_events, event) + self.__draw_event__(event, column_events.index(event)) + + def __update_columns_events__ (self, column_events, new_event): + current_time = new_event.begin_datetime + new_event_added = False + for index in range(len(column_events)): + if column_events[index] != None and column_events[index].end_datetime <= current_time: + column_events[index] = None + if new_event_added == False and column_events[index] == None: + column_events[index] = new_event + new_event_added = True + return column_events + def __draw_hour_rows__ (self): for hour in range(self.first_hour, self.last_hour + 1): self.__draw_row__(hour) @@ -111,11 +128,11 @@ class HourListDesign (DesignEntity): text = event.title text_color = colors["bg"] textbox_size = (size[0] - event_title_padding, size[1] - event_title_padding) - txt = TextDesign(textbox_size, text = text, fontsize=event_title_fontsize, color=text_color, background_color=box_color) + txt = TextDesign(textbox_size, text = text, fontsize=event_title_fontsize, color=text_color, background_color=box_color, wrap=True) txt.pos = (pos[0] + event_title_padding, pos[1] + event_title_padding) self.draw_design(txt) - def __get_max_num_simultaneous_events__(self): + def __get_max_num_simultaneous_events__ (self): parallelity_count = 1 for index, event in enumerate(self.events): @@ -128,7 +145,7 @@ class HourListDesign (DesignEntity): parallelity_count = current_parallelity return parallelity_count - def __are_simultaneous__(self, ev_a, ev_b): + def __are_simultaneous__ (self, ev_a, ev_b): if ev_a.begin_datetime > ev_b.begin_datetime: ev_a, ev_b = ev_b, ev_a