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.
This commit is contained in:
parent
0bbb13e6c4
commit
03204f56b9
1 changed files with 9 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue