From b3267c1cbf915c4702989d279189fa375e00705b Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 2 Aug 2022 09:31:41 +0100 Subject: [PATCH] observer example updated. some docstrings added --- examples/observer/__main__.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/observer/__main__.py b/examples/observer/__main__.py index cfb2e93..e8d97d6 100644 --- a/examples/observer/__main__.py +++ b/examples/observer/__main__.py @@ -4,20 +4,25 @@ import vban_cmd class Observer: def __init__(self, vban): self.vban = vban + # register your app as event observer + self.vban.subject.add(self) + # add level updates, since they are disabled by default. + self.vm.event.add("ldirty") + # define an 'on_update' callback function to receive event updates def on_update(self, subject): if subject == "pdirty": print("pdirty!") - if subject == "ldirty": + elif subject == "ldirty": info = ( - f"[{self.vban.bus[0]} {self.vban.bus[0].levels.is_updated}]", - f"[{self.vban.bus[1]} {self.vban.bus[1].levels.is_updated}]", - f"[{self.vban.bus[2]} {self.vban.bus[2].levels.is_updated}]", - f"[{self.vban.bus[3]} {self.vban.bus[3].levels.is_updated}]", - f"[{self.vban.bus[4]} {self.vban.bus[4].levels.is_updated}]", - f"[{self.vban.bus[5]} {self.vban.bus[5].levels.is_updated}]", - f"[{self.vban.bus[6]} {self.vban.bus[6].levels.is_updated}]", - f"[{self.vban.bus[7]} {self.vban.bus[7].levels.is_updated}]", + f"[{self.vban.bus[0]} {self.vban.bus[0].levels.isdirty}]", + f"[{self.vban.bus[1]} {self.vban.bus[1].levels.isdirty}]", + f"[{self.vban.bus[2]} {self.vban.bus[2].levels.isdirty}]", + f"[{self.vban.bus[3]} {self.vban.bus[3].levels.isdirty}]", + f"[{self.vban.bus[4]} {self.vban.bus[4].levels.isdirty}]", + f"[{self.vban.bus[5]} {self.vban.bus[5].levels.isdirty}]", + f"[{self.vban.bus[6]} {self.vban.bus[6].levels.isdirty}]", + f"[{self.vban.bus[7]} {self.vban.bus[7].levels.isdirty}]", ) print(" ".join(info)) @@ -25,7 +30,6 @@ class Observer: def main(): with vban_cmd.api(kind_id, **opts) as vban: obs = Observer(vban) - vban.subject.add(obs) while cmd := input("Press to exit\n"): if not cmd: