From 03204f56b933e2af253f68ca8ebe182c3a7a8d60 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 12 Feb 2020 19:44:05 +0100 Subject: [PATCH] quick frontends (app): added an "ignore_missing" argument to RemoveListener: normally an error is logged when removeListener is call on a inexisting listener, but sometimes listeners are added only in specific scenarios, and it may be handy to try to delete them without having to explictly check that they have been used. --- sat_frontends/quick_frontend/quick_app.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sat_frontends/quick_frontend/quick_app.py b/sat_frontends/quick_frontend/quick_app.py index fcbfe402..c8bce06c 100644 --- a/sat_frontends/quick_frontend/quick_app.py +++ b/sat_frontends/quick_frontend/quick_app.py @@ -581,18 +581,22 @@ class QuickApp(object): assert type_ in C.LISTENERS self._listeners.setdefault(type_, {})[callback] = profiles_filter - def removeListener(self, type_, callback): + def removeListener(self, type_, callback, ignore_missing=False): """Remove a callback from listeners - @param type_: same as for [addListener] - @param callback: callback to remove + @param type_(str): same as for [addListener] + @param callback(callable): callback to remove + @param ignore_missing(bool): if True, don't log error if the listener doesn't + exist """ assert type_ in C.LISTENERS try: self._listeners[type_].pop(callback) except KeyError: - log.error( - f"Trying to remove an inexisting listener (type = {type_}): {callback}") + if not ignore_missing: + log.error( + f"Trying to remove an inexisting listener (type = {type_}): " + f"{callback}") def callListeners(self, type_, *args, **kwargs): """Call the methods which listen type_ event. If a profiles filter has