Skip to content

Commit

Permalink
Changes to how calendar is rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
tsbarnes committed Sep 15, 2021
1 parent 6187071 commit 605e443
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions apps/calendar.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from apps import AbstractApp
from libs.calendar import Calendar, get_calendar

Expand All @@ -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()
Expand Down

0 comments on commit 605e443

Please sign in to comment.