32 lines
772 B
Python
32 lines
772 B
Python
"""What a screen view looks like to the runner."""
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
from typing import Hashable, Protocol
|
|
|
|
from PIL import Image
|
|
|
|
|
|
@dataclass
|
|
class Patch:
|
|
"""A partial update: draw `image` with its top-left corner at (x, y)."""
|
|
image: Image.Image
|
|
x: int
|
|
y: int
|
|
|
|
|
|
class View(Protocol):
|
|
name: str
|
|
|
|
def start(self) -> None: ...
|
|
|
|
def stop(self) -> None: ...
|
|
|
|
def frame_key(self, now: datetime) -> Hashable:
|
|
"""Changes whenever a full redraw is needed."""
|
|
|
|
def render(self, now: datetime) -> Image.Image:
|
|
"""The full 480x320 frame."""
|
|
|
|
def patch(self, now: datetime) -> Patch | None:
|
|
"""Cheap partial update valid while frame_key is unchanged (e.g. the seconds)."""
|