From 605e443296af938298e21553ce808aff62f8fe32 Mon Sep 17 00:00:00 2001 From: Thea Barnes Date: Wed, 15 Sep 2021 10:46:10 -0400 Subject: [PATCH] Changes to how calendar is rendered --- apps/__init__.py | 7 ++++++- apps/calendar.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/__init__.py b/apps/__init__.py index ff487e8..808c6ed 100644 --- a/apps/__init__.py +++ b/apps/__init__.py @@ -56,11 +56,16 @@ def wrapped_text(self, text, position=(5, 5), font_name=None, font_size=20, colo avg_char_width: int = sum(font.getsize(char)[0] for char in ascii_letters) / len(ascii_letters) max_char_count: int = int((self.image.size[0] * .95) / avg_char_width) + number_of_lines: int = 0 scaled_wrapped_text: str = '' for line in text.split('\n'): - scaled_wrapped_text += textwrap.fill(text=line, width=max_char_count) + '\n' + new_wrapped_text = textwrap.fill(text=line, width=max_char_count) + '\n' + number_of_lines += len(new_wrapped_text.split('\n')) + scaled_wrapped_text += new_wrapped_text draw.text(position, scaled_wrapped_text, font=font, fill=color) + return number_of_lines + def paste_image(self, image, position=(5, 5)): if not self.image: raise ValueError("self.image is None") diff --git a/apps/calendar.py b/apps/calendar.py index c76a525..b3369ee 100644 --- a/apps/calendar.py +++ b/apps/calendar.py @@ -1,3 +1,4 @@ +import logging from apps import AbstractApp from libs.calendar import Calendar, get_calendar @@ -6,6 +7,20 @@ class App(AbstractApp): calendar: Calendar = get_calendar() def reload(self): + lines = self.calendar.events_as_lines() + + self.blank() + + if len(lines) < 1: + self.wrapped_text('No current events', (5, 5), font_size=30) + return + + current_line_height = 5 + for line in lines: + number_of_lines = self.wrapped_text(line, (5, current_line_height), font_size=20) + current_line_height += 20 * number_of_lines + + def reload_old(self): text = self.calendar.events_as_string() self.blank()