Verified Commit 66e33bdc authored by Cheuk Yin Ng's avatar Cheuk Yin Ng 🤡

fix: drawing glitch that draws events from past

Glitch drew past events way into the future. Now fixed.
parent 8caacb73
......@@ -3,6 +3,7 @@ from app.knuthplass import GreedyFormatter
from app.calendar import GoogleCalendar
from datetime import datetime, timedelta
from typing import Tuple
import logging
DAYS = ['Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat', 'Sun']
......@@ -135,33 +136,35 @@ class ScheduleDrawer:
duration = end - start
fullday = duration >= timedelta(days=1)
while duration > timedelta(0) and start - today < timedelta(days=7):
col = (start.weekday() - today.weekday()) % 7
x0 = self.colw + col * (self.colw + 1) + 1
x1 = self.colw + (col + 1) * (self.colw + 1) - 1
if not fullday:
start_percent = percent_of_day(start)
end_percent = percent_of_day(end)
y0 = self.vpad +\
int(start_percent * self.total_space) + self.fontsize // 2
y1 = self.vpad +\
int(end_percent * self.total_space) + self.fontsize // 2
else:
y0 = self.vpad + self.fontsize // 2
y1 = self.vpad + self.fontsize * 2
# Draw event rectangle
fill = self.evtcolor if not fullday else self.fulldaycolor
draw.rectangle((x0, y0, x1, y1),
fill=fill)
# Draw event text
size = (x1 - x0, y1 - y0)
slot = '%02d:%02d-%02d:%02d' % (
start.hour, start.minute,
end.hour, end.minute)
draw.multiline_text((x0 + self.hpad, y0 + self.hpad),
self.find_fit_text(draw, name, slot, size),
fill=self.fontcolor,
font=self.font)
# Only draw the event if it is not a long time ago
if start - today >= -timedelta(seconds=1):
col = (start.weekday() - today.weekday()) % 7
x0 = self.colw + col * (self.colw + 1) + 1
x1 = self.colw + (col + 1) * (self.colw + 1) - 1
if not fullday:
start_percent = percent_of_day(start)
end_percent = percent_of_day(end)
y0 = self.vpad +\
int(start_percent * self.total_space) + self.fontsize // 2
y1 = self.vpad +\
int(end_percent * self.total_space) + self.fontsize // 2
else:
y0 = self.vpad + self.fontsize // 2
y1 = self.vpad + self.fontsize * 2
# Draw event rectangle
fill = self.evtcolor if not fullday else self.fulldaycolor
draw.rectangle((x0, y0, x1, y1),
fill=fill)
# Draw event text
size = (x1 - x0, y1 - y0)
slot = '%02d:%02d-%02d:%02d' % (
start.hour, start.minute,
end.hour, end.minute)
draw.multiline_text((x0 + self.hpad, y0 + self.hpad),
self.find_fit_text(draw, name, slot, size),
fill=self.fontcolor,
font=self.font)
start += timedelta(days=1)
start = start.replace(hour=0, minute=0, second=0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment