diff --git a/Calendar/DayListPanel.py b/Calendar/DayListPanel.py index 2f8ecd5..5edfb43 100644 --- a/Calendar/DayListPanel.py +++ b/Calendar/DayListPanel.py @@ -1,34 +1,37 @@ from PanelDesign import PanelDesign from Assets import * from settings import * -import calendar -from datetime import datetime, timedelta +import calendar as callib +from datetime import datetime, timedelta, date from PIL import ImageDraw from TextDesign import TextDesign from BoxDesign import BoxDesign from EllipseDesign import EllipseDesign from DayHeaderDesign import DayHeaderDesign +from DayRowDesign import DayRowDesign todayheader_pos = (0,0) todayheader_size = (1,0.25) -headerline_color = "black" +line_color = "black" lines_thickness = 1 +dayrowsarea_ypos = todayheader_size[1] +dayrowsarea_height = 1 - todayheader_size[1] +dayrow_min_format = 55 / 680 +dayrow_max_format = 85 / 680 + 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.__first_render__() self.__day_rows__ = [] + self.__calc_dayrow_size__() + self.__first_render__() def __first_render__ (self): - if week_starts_on == "Monday": - calendar.setfirstweekday(calendar.MONDAY) - elif week_starts_on == "Sunday": - calendar.setfirstweekday(calendar.SUNDAY) - self.__draw_today_header__() + self.__draw_day_rows__() def add_weather (self, weather): pass @@ -39,14 +42,51 @@ class DayListPanel (PanelDesign): def add_rssfeed (self, rss): pass - def __draw_today_header__ (self): - header = DayHeaderDesign(self.__abs_co__(todayheader_size), datetime.now()) - header.pos = self.__abs_co__(todayheader_pos) - self.draw_design(header) + 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) - line_start = (0, self.__abs_co__(todayheader_size)[1]) - line_end = self.__abs_co__(todayheader_size) - ImageDraw.Draw(self.__image__).line([line_start, line_end], fill=headerline_color, width=lines_thickness) + 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] + max_row_number = max_area_height / (dayrow_min_format * self.size[1]) + min_row_number = max_area_height / (dayrow_max_format * self.size[1]) + 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 + + def __draw_today_header__ (self): + header = DayHeaderDesign(self.__abs_co__(todayheader_size), date.today()) + header.pos = self.__abs_co__(todayheader_pos) + self.__day_rows__.append(header) + + def __draw_lines__(self): + positions = [] + for i in range(self.dayrow_count): + positions.append(self.__get_day_row_pos__(i)[1]) + for ypos in positions: + line_start = (0, ypos) + line_end = (self.size[0], ypos) + ImageDraw.Draw(self.__image__).line([line_start, line_end], fill=line_color, width=lines_thickness) + + def __finish_image__(self): + for design in self.__day_rows__: + self.draw_design(design) + self.__draw_lines__() def __abs_co__(self, coordinates): return (int(coordinates[0] * self.size[0]),int(coordinates[1] * self.size[1])) \ No newline at end of file diff --git a/Calendar/DayRowDesign.py b/Calendar/DayRowDesign.py new file mode 100644 index 0000000..e95c603 --- /dev/null +++ b/Calendar/DayRowDesign.py @@ -0,0 +1,65 @@ +from PIL import ImageDraw +from TextDesign import TextDesign +from settings import week_starts_on +from DesignEntity import DesignEntity + +daynumber_y_size = (1, 0.65) +weekday_y_size = (daynumber_y_size[0], 1 - daynumber_y_size[1]) +weekday_ypos = daynumber_y_size[1] +daynumber_fontsize = daynumber_y_size[1] * 0.8 +weekday_fontsize = weekday_y_size[1] * 0.75 + +general_text_color = "black" +highlight_text_color = "red" +background_color = "white" + +class DayRowDesign (DesignEntity): + """Detailed view of a given date.""" + def __init__ (self, size, date): + super(DayRowDesign, self).__init__(size) + self.__init_image__(color=background_color) + self.date = date + + def __finish_image__ (self): + self.__draw_day_number__() + self.__draw_weekday__() + + def __draw_weekday__ (self): + font_size = int(weekday_fontsize * self.size[1]) + size = (weekday_y_size[0] * self.size[1], weekday_y_size[1] * self.size[1]) + ypos = weekday_ypos * self.size[1] + pos = (0, ypos) + + color = self.__get_day_color__() + week_day_name = self.date.strftime("%a") + + week_day = TextDesign(size, text=week_day_name, background_color=background_color, color=color, fontsize=font_size, horizontalalignment="center", verticalalignment="top") + week_day.pos = pos + self.draw_design(week_day) + + def __draw_day_number__ (self): + font_size = int(daynumber_fontsize * self.size[1]) + size = (daynumber_y_size[0] * self.size[1], daynumber_y_size[1] * self.size[1]) + pos = (0, 0) + + day_text = self.__get_day_text__() + color = self.__get_day_color__() + + number = TextDesign(size, text=day_text, background_color=background_color, color=color, fontsize=font_size, horizontalalignment="center", verticalalignment="bottom") + number.pos = pos + self.draw_design(number) + + def __abs_co__ (self, coordinates): + return (int(coordinates[0] * self.size[0]),int(coordinates[1] * self.size[1])) + + def __get_day_text__ (self): + return str(self.date.day) + + def __get_day_color__ (self): + """Depending on week_starts_on""" + if week_starts_on == "Monday" and self.date.strftime("%w") == "0": + return highlight_text_color + elif week_starts_on == "Sunday" and self.date.strftime("%w") == "6": + return highlight_text_color + else: + return general_text_color \ No newline at end of file