Making an ESP32-based quadcopter from scratch
Python arduinoautopilotcontrol-theorydroneesp32flight-controlflight-controllermavlinkquadcopterquadcopter-firmwareuav
pyflix: add passing event name to off method
Oleg Kalachevb3dffe99fb30
diff --git a/tools/pyflix/README.md b/tools/pyflix/README.mdindex 9f49d7b..47d5633 100644--- a/tools/pyflix/README.md+++ b/tools/pyflix/README.md@@ -59,6 +59,13 @@ flix.on('disconnected', lambda: print('Disconnected from Flix'))flix.on('print', lambda text: print(f'Flix says: {text}'))```+Unsubscribe from events using `off` method:++```python+flix.off('print') # unsubscribe from print events+flix.off(callback) # unsubscribe specific callback+```+You can also wait for specific events using `wait` method. This method returns the data associated with the event:```pythondiff --git a/tools/pyflix/flix.py b/tools/pyflix/flix.pyindex 472a9b1..6b9bcd6 100644--- a/tools/pyflix/flix.py+++ b/tools/pyflix/flix.py@@ -87,10 +87,15 @@ class Flix:self._event_listeners[event] = []self._event_listeners[event].append(callback)- def off(self, callback: Callable):- for event in self._event_listeners:- if callback in self._event_listeners[event]:- self._event_listeners[event].remove(callback)+ def off(self, event_or_callback: Union[str, Callable]):+ if isinstance(event_or_callback, str):+ event = event_or_callback.lower()+ if event in self._event_listeners:+ del self._event_listeners[event]+ else:+ for event in self._event_listeners:+ if event_or_callback in self._event_listeners[event]:+ self._event_listeners[event].remove(event_or_callback)def _trigger(self, event: str, *args):event = event.lower()