vban-cmd-python/vban_cmd/misc.py
onyx-and-iris 6971feb398 defaultkwarg subs added.
misc module added with Event class.

base class observable thread now checks for currently registered events.
2022-08-02 09:28:32 +01:00

41 lines
889 B
Python

class Event:
def __init__(self, subs: dict):
self.subs = subs
def info(self, msg):
info = (
f"{msg} events",
f"Now listening for {', '.join(self.get())} events",
)
print("\n".join(info))
@property
def pdirty(self):
return self.subs["pdirty"]
@property
def mdirty(self):
return self.subs["mdirty"]
@property
def midi(self):
return self.subs["midi"]
@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")