buba/buba/BubaAnimator.py
2025-06-01 19:06:50 +02:00

66 lines
No EOL
2 KiB
Python

import logging
from datetime import datetime
from threading import Thread
from time import sleep
from buba.BubaCmd import BubaCmd
class BubaAnimation:
def __init__(self, buba: BubaCmd):
self.buba = buba
pass
def run(self):
pass
def __repr__(self):
return f"<{type(self).__name__}>"
class BubaTime(BubaAnimation):
def __init__(self, buba: BubaCmd):
super().__init__(buba)
def run(self):
self.buba.simple_text(page=0, row=1, col=1, text="Buba")
self.buba.simple_text(page=0, row=2, col=1, text="CCC Hansestadt Hamburg")
self.buba.simple_text(page=0, row=3, col=1, text="")
self.buba.simple_text(page=0, row=4, col=1, text="Hello, world!")
self.buba.set_page(0)
for i in range(15):
self.buba.simple_text(page=0, row=1, col=94, text=datetime.now().strftime("%H:%M:%S"))
sleep(1)
class BubaCharset(BubaAnimation):
def __init__(self, buba: BubaCmd):
super().__init__(buba)
def run(self):
self.buba.simple_text(page=0, row=1, col=1, text=" !\"#$%&'()*+,-./0123456789:;<=>?")
self.buba.simple_text(page=0, row=2, col=1, text="@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_")
self.buba.simple_text(page=0, row=3, col=1, text="`abcdefghijklmnopqrstuvwxyz{|}~\u2302")
self.buba.simple_text(page=0, row=4, col=1, text="That's all, folks!")
sleep(10)
class BubaAnimator:
def __init__(self, buba: BubaCmd):
self.log = logging.getLogger(__name__)
self.buba = buba
self.animations = []
Thread(target=self.run, daemon=True).start()
def run(self):
while True:
if len(self.animations) == 0:
a = BubaTime(self.buba)
a.run()
else:
for a in self.animations:
self.log.debug(f"Starting animation: {a}")
a.run()
def add(self, animation):
self.animations.append(animation(self.buba))