Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsbarnes committed Sep 15, 2021
1 parent a773312 commit 6187071
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
18 changes: 18 additions & 0 deletions apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def blank(self):
else:
self.image = Image.new("RGBA", self.framebuffer.size, settings.BACKGROUND_COLOR)

def text(self, text, position=(5, 5), font_name=None, font_size=20, color=None):
if not font_name:
font_name = settings.FONT
if not color:
color = settings.TEXT_COLOR
if not self.image:
raise ValueError("self.image is None")

font: ImageFont = ImageFont.truetype(font_name, font_size)
draw: ImageDraw = ImageDraw.Draw(self.image)

draw.text(position, text, font=font, fill=color)

def wrapped_text(self, text, position=(5, 5), font_name=None, font_size=20, color=None):
if not font_name:
font_name = settings.FONT
Expand All @@ -48,6 +61,11 @@ def wrapped_text(self, text, position=(5, 5), font_name=None, font_size=20, colo
scaled_wrapped_text += textwrap.fill(text=line, width=max_char_count) + '\n'
draw.text(position, scaled_wrapped_text, font=font, fill=color)

def paste_image(self, image, position=(5, 5)):
if not self.image:
raise ValueError("self.image is None")
self.image.paste(image, position)

def show(self):
if not self.image:
logging.error("App '{0}' called 'show' without an image!".format(self.__module__))
Expand Down
16 changes: 16 additions & 0 deletions libs/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def get_latest_events(self):

return self.events

def events_as_lines(self):
lines = []
last_date = None

for obj in self.events:
if obj["start"] != last_date:
if obj["start"].date() > datetime.today().date():
lines.append('-- ' + humanize.naturaldate(obj["start"]) + ' --')
else:
lines.append('-- ' + humanize.naturaltime(obj["start"], when=datetime.now(self.timezone)) + ' --')
last_date = obj["start"]

lines.append(obj["summary"].replace('\n', ' '))

return lines

def events_as_string(self):
text = ''

Expand Down
2 changes: 1 addition & 1 deletion pitftmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def main_loop(self):
app.framebuffer.blank()
# image = wrapped_text("Starting PiTFT Manager...", app.framebuffer.size,
# font_name=settings.FONT, font_size=40, background_color="black")
# image = Image.open()
# image = Image.open("raspberry-pi.png")
# app.framebuffer.show(image)

app.main_loop()

0 comments on commit 6187071

Please sign in to comment.