works reliably - especially when using gunicorn

This commit is contained in:
Christoph Haas 2026-01-16 22:36:32 +01:00
parent c937450f92
commit 39cd98823a
7 changed files with 253 additions and 38 deletions

39
scenes/clock.py Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import io
from time import sleep
from PIL import Image, ImageDraw, ImageFont
import lib.display
import datetime
import locale
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
def start(stop_event, text="Hello World!"):
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)
while not stop_event.is_set():
# All to black
draw.rectangle( ((0,0),(lib.display.matrix.width-1,lib.display.matrix.height-1)), fill=(0,50,0) )
#draw.rectangle( ((0,0),(lib.display.matrix.width-1,lib.display.matrix.height-1)), fill=(255,255,255) )
# Current time
now = datetime.datetime.now()
#now_string = now.strftime('%d. %B %Y %H:%M:%S')
# Date into top left
draw.text((0, 0), now.strftime('%d. %B %Y'), fill=(255, 255, 0), font=lib.display.matrix.font)
# Time into middle
draw.text((20, 20), now.strftime('%H:%M:%S'), fill=(0, 255, 255), font=lib.display.matrix.large_font)
float_seconds = now.second + now.microsecond/10**6
length = 64*4/60.0*float_seconds
# 64*4 = 60
# x = seconds
# x=64*4/60*seconds
#draw.line( ((0,63), (now.second,63)), fill=(128,128,128), width=1)
draw.line( ((0,62), (length,62)), fill=(128,128,128), width=2)
lib.display.matrix.show(image_buffer)
sleep(0.05)