2022-09-28 18:03:22 +01:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
2022-08-02 09:28:32 +01:00
|
|
|
class Event:
|
2022-09-29 11:48:30 +01:00
|
|
|
"""Keeps track of event subscriptions"""
|
|
|
|
|
2022-09-28 18:03:22 +01:00
|
|
|
logger = logging.getLogger("event.event")
|
|
|
|
|
2022-08-02 09:28:32 +01:00
|
|
|
def __init__(self, subs: dict):
|
|
|
|
self.subs = subs
|
|
|
|
|
2022-09-29 11:48:30 +01:00
|
|
|
def info(self, msg=None):
|
|
|
|
info = (f"{msg} events",) if msg else ()
|
2022-09-28 18:03:22 +01:00
|
|
|
if self.any():
|
|
|
|
info += (f"now listening for {', '.join(self.get())} events",)
|
|
|
|
else:
|
|
|
|
info += (f"not listening for any events",)
|
|
|
|
self.logger.info(", ".join(info))
|
2022-08-02 09:28:32 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def pdirty(self):
|
|
|
|
return self.subs["pdirty"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ldirty(self):
|
|
|
|
return self.subs["ldirty"]
|
|
|
|
|
|
|
|
def get(self) -> list:
|
|
|
|
return [k for k, v in self.subs.items() if v]
|
|
|
|
|
|
|
|
def any(self) -> bool:
|
|
|
|
return any(self.subs.values())
|
|
|
|
|
|
|
|
def add(self, event):
|
|
|
|
self.subs[event] = True
|
|
|
|
self.info(f"{event} added to")
|
|
|
|
|
|
|
|
def remove(self, event):
|
|
|
|
self.subs[event] = False
|
|
|
|
self.info(f"{event} removed from")
|