Mercurial > libervia-backend
changeset 3167:d0fb79f97466
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Feb 2020 19:44:05 +0100 |
parents | 122075ceaa53 |
children | 1cb232c9e845 |
files | sat_frontends/quick_frontend/quick_app.py |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_app.py Wed Feb 12 19:40:48 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_app.py Wed Feb 12 19:44:05 2020 +0100 @@ -581,18 +581,22 @@ 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