add property setters in event class

use event property setters in examples

update README

patch bump
This commit is contained in:
onyx-and-iris 2022-10-06 16:45:15 +01:00
parent 243a43ac22
commit 0c60fe3d5e
4 changed files with 32 additions and 14 deletions

View File

@ -302,20 +302,30 @@ The following methods are available:
example: example:
```python ```python
# register the app self as an event observer # register an app to receive updates
self.vban.subject.add(self) class App():
def __init__(self, vban):
vban.subject.add(self)
...
``` ```
#### `vban.event` #### `vban.event`
You may also add/remove event subscriptions as necessary with the Event class. Use the event class to toggle updates as necessary.
The following properties are available:
- `pdirty`: boolean
- `mdirty`: boolean
- `midi`: boolean
- `ldirty`: boolean
example: example:
```python ```python
vban.event.add("ldirty") vban.event.ldirty = True
vban.event.remove("pdirty") vban.event.pdirty = False
# get a list of currently subscribed # get a list of currently subscribed
print(vban.event.get()) print(vban.event.get())

View File

@ -8,8 +8,8 @@ class Observer:
self.vban = vban self.vban = vban
# register your app as event observer # register your app as event observer
self.vban.subject.add(self) self.vban.subject.add(self)
# add level updates, since they are disabled by default. # enable level updates, since they are disabled by default.
self.vban.event.add("ldirty") self.vban.event.ldirty = True
# define an 'on_update' callback function to receive event updates # define an 'on_update' callback function to receive event updates
def on_update(self, subject): def on_update(self, subject):

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "vban-cmd" name = "vban-cmd"
version = "1.5.4" version = "1.5.5"
description = "Python interface for the VBAN RT Packet Service (Sendtext)" description = "Python interface for the VBAN RT Packet Service (Sendtext)"
authors = ["onyx-and-iris <code@onyxandiris.online>"] authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT" license = "MIT"

View File

@ -18,13 +18,23 @@ class Event:
self.logger.info(", ".join(info)) self.logger.info(", ".join(info))
@property @property
def pdirty(self): def pdirty(self) -> bool:
return self.subs["pdirty"] return self.subs["pdirty"]
@pdirty.setter
def pdirty(self, val: bool):
self.subs["pdirty"] = val
self.info(f"pdirty {'added to' if val else {'removed from'}}")
@property @property
def ldirty(self): def ldirty(self) -> bool:
return self.subs["ldirty"] return self.subs["ldirty"]
@ldirty.setter
def ldirty(self, val: bool):
self.subs["ldirty"] = val
self.info(f"ldirty {'added to' if val else {'removed from'}}")
def get(self) -> list: def get(self) -> list:
return [k for k, v in self.subs.items() if v] return [k for k, v in self.subs.items() if v]
@ -32,9 +42,7 @@ class Event:
return any(self.subs.values()) return any(self.subs.values())
def add(self, event): def add(self, event):
self.subs[event] = True setattr(self, event, True)
self.info(f"{event} added to")
def remove(self, event): def remove(self, event):
self.subs[event] = False setattr(self, event, False)
self.info(f"{event} removed from")