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:08 +01:00
parent 08fdad135d
commit 86612a65cb
5 changed files with 47 additions and 19 deletions

View File

@ -605,20 +605,30 @@ The following methods are available:
example:
```python
# register the app self as an event observer
self.vm.subject.add(self)
# register an app to receive updates
class App():
def __init__(self, vm):
vm.subject.add(self)
...
```
#### `vm.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:
```python
vm.event.add("ldirty")
vm.event.ldirty = True
vm.event.remove("pdirty")
vm.event.pdirty = False
# get a list of currently subscribed
print(vm.event.get())

View File

@ -56,7 +56,7 @@ class Parser:
def main(cmds=None):
kind_id = "banana"
subs = {ev: False for ev in ["pdirty", "mdirty", "ldirty", "midi"]}
subs = {ev: False for ev in ["pdirty", "mdirty", "midi"]}
with voicemeeterlib.api(kind_id, subs=subs) as vm:
parser = Parser(vm)

View File

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

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "voicemeeter-api"
version = "0.8.2"
version = "0.8.3"
description = "A Python wrapper for the Voiceemeter API"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"

View File

@ -18,21 +18,41 @@ class Event:
self.logger.info(", ".join(info))
@property
def pdirty(self):
def pdirty(self) -> bool:
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
def mdirty(self):
def mdirty(self) -> bool:
return self.subs["mdirty"]
@property
def midi(self):
return self.subs["midi"]
@mdirty.setter
def mdirty(self, val: bool):
self.subs["mdirty"] = val
self.info(f"mdirty {'added to' if val else {'removed from'}}")
@property
def ldirty(self):
def midi(self) -> bool:
return self.subs["midi"]
@midi.setter
def midi(self, val: bool):
self.subs["midi"] = val
self.info(f"midi {'added to' if val else {'removed from'}}")
@property
def ldirty(self) -> bool:
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:
return [k for k, v in self.subs.items() if v]
@ -40,9 +60,7 @@ class Event:
return any(self.subs.values())
def add(self, event):
self.subs[event] = True
self.info(f"{event} added to")
setattr(self, event, True)
def remove(self, event):
self.subs[event] = False
self.info(f"{event} removed from")
setattr(self, event, False)