This commit is contained in:
vivlim 2023-11-23 02:56:22 -08:00
parent cf9cd2e867
commit a004e5fbd6
5 changed files with 16 additions and 7 deletions

BIN
fonts/Px437_IBM_BIOS.ttf Normal file

Binary file not shown.

Binary file not shown.

BIN
fonts/Px437_IBM_EGA_8x8.ttf Normal file

Binary file not shown.

Binary file not shown.

View File

@ -93,7 +93,7 @@ class LinearDrawable:
self.drawfn = drawfn
self.padding = padding
def text(text, fill='black', font_key='Macintosh128K', anchor="la"):
def text(text, fill='black', font_key='Px437_IBM_VGA_8x16', anchor="la"):
font = fonts[font_key]
bbox = Box.from_pil_box(font.getbbox(text))
@ -104,6 +104,12 @@ class LinearDrawable:
draw.text((x, available_rect.top), text, fill=fill, font=font, anchor=anchor)
return LinearDrawable(bbox, d)
def rectangle(bounds: Box, fill):
def d(draw, b: Box):
if fill != None:
draw.rectangle([(b.left, b.top), (b.right, b.bottom)], fill=fill, outline=None)
return LinearDrawable(bounds, d)
def linear_draw_v(area: Box, draw: ImageDraw.Draw, items: list[LinearDrawable]):
@ -131,12 +137,15 @@ def weather_to_image(weather):
draw.rectangle([(0, 0), image.size], fill = (255, 255, 255))
linear_v_items = [
LinearDrawable.text(datetime.now().strftime("%m/%d @ %H:%M"), anchor="ra"),
LinearDrawable.text(f"{weather.current.temperature}F", font_key="Macintosh128K_4x", anchor="ra"),
LinearDrawable.text(weather.current.description, font_key="Macintosh128K_2x"),
LinearDrawable(Box(0,0,152,8), lambda d, b : d.line([(b.left, b.mid_y()), (b.right, b.mid_y())], fill="black"))
LinearDrawable.text(f"{weather.current.temperature}°F", font_key="Px437_IBM_VGA_8x16_2x", anchor="ra"),
LinearDrawable.rectangle(Box(0,0,152,6), fill=None),
LinearDrawable.rectangle(Box(0,0,152,4), fill="red"),
]
remaining_forecast = 5
# hack
LinearDrawable.text(weather.current.description[:10], font_key="Px437_IBM_VGA_8x16").drawfn(draw, Box(4, 20, 152, 48))
remaining_forecast = 8
for forecast in weather.forecasts:
for hourly in forecast.hourly:
if remaining_forecast <= 0:
@ -145,8 +154,8 @@ def weather_to_image(weather):
if forecast_dt <= datetime.now():
continue
remaining_forecast -= 1
hour_str = forecast_dt.strftime("%H%p")
linear_v_items.append(LinearDrawable.text(f"{hour_str}: {hourly.temperature}F - {hourly.description}"))
hour_str = forecast_dt.strftime("%l%p")
linear_v_items.append(LinearDrawable.text(f"{hour_str} {hourly.temperature}° {hourly.description}", font_key="Px437_IBM_VGA_8x16"))
if remaining_forecast <= 0:
break