led-marquee-sign-client/led_marquee_sign_client/line.py

63 lines
1.6 KiB
Python
Raw Normal View History

2024-04-14 20:53:03 +02:00
from led_marquee_sign_client.enums import *
class Line:
"""
Builds a line step for the sign step by step. Renders into a formatted string.
"""
def __init__(
self,
transition: Transition = Transition.default(),
brightness: Brightness = Brightness.default(),
font_type: FontType = FontType.default(),
):
# every line may have just one transition method
# we make it a public property
self.transition = transition
# our internal state
self._data = []
# every line has an initial brightness and font type set
# these can be changed at any time
self.add(brightness)
self.add(font_type)
def add(
self,
data: str | FontType | Brightness | Macro | Symbol | Cartoon | ExtendedChar,
):
if isinstance(data, str):
data = ExtendedChar.translateUtf16(data)
self._data.append(data)
return self
def __str__(self):
components = [str(self.transition)]
components += map(str, self._data)
components.append("\r")
return "".join(components)
class Message:
"""
Builds a message for the sign step by step. Renders into a formatted string.
"""
def __init__(self, address: int = 128):
self.address = address
self._lines = []
def add(self, line: Line):
self._lines.append(line)
return self
def __str__(self):
components = [f"~{self.address}~f01"]
components += self._lines
components.append("\r\r\r")
return "".join(map(str, components))