Simple picture output

This commit is contained in:
2025-07-28 18:31:42 +02:00
parent 7e729618de
commit 26425c1bfd
7 changed files with 353 additions and 23 deletions

View File

@ -1,3 +1,22 @@
import logging
from collections import defaultdict
class GlobalState:
def __init__(self):
pass
self.listeners = defaultdict(list)
def subscribe(self, event_name: str, callback):
"""Register a function to be called when an event is dispatched."""
logging.info(f"Subscribing '{callback.__qualname__}' to event '{event_name}'")
self.listeners[event_name].append(callback)
def dispatch(self, event_name: str, *args, **kwargs):
"""Call all registered callbacks for a given event."""
logging.info(f"Dispatching event '{event_name}' with data: {kwargs}")
if event_name in self.listeners:
for callback in self.listeners[event_name]:
try:
# Pass the arguments and keyword arguments to the callback
callback(*args, **kwargs)
except Exception as e:
logging.error(f"Error in event callback for '{event_name}': {e}")