Simple picture output
This commit is contained in:
@ -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}")
|
Reference in New Issue
Block a user