CallbackList¶
- class echo.CallbackList(callback, *args, **kwargs)[source]¶
Bases:
list,ContainerMixinA list that calls a callback function when it is modified.
The first argument should be the callback function (which takes no arguments), and subsequent arguments are as for list.
Methods
add_callback(func[, priority, validator])Add a callback to the container.
append(value)Append object to the end of the list.
clear()Remove all items from list.
copy(/)Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
extend(iterable)Extend list by appending elements from the iterable.
index(value[, start, stop])Return first index of value.
insert(index, value)Insert object before index.
pop([index])Remove and return item at index (default last).
remove(value)Remove first occurrence of value.
remove_callback(func)Remove a callback from the container.
reverse()Reverse IN PLACE.
sort([key, reverse])Sort the list in ascending order and return None.
notify_all
Methods Summary
add_callback(func[, priority, validator])Add a callback to the container.
append(value)Append object to the end of the list.
clear()Remove all items from list.
copy(/)Return a shallow copy of the list.
count(value, /)Return number of occurrences of value.
extend(iterable)Extend list by appending elements from the iterable.
index(value[, start, stop])Return first index of value.
insert(index, value)Insert object before index.
notify_all(*args, **kwargs)pop([index])Remove and return item at index (default last).
remove(value)Remove first occurrence of value.
remove_callback(func)Remove a callback from the container.
reverse()Reverse IN PLACE.
sort([key, reverse])Sort the list in ascending order and return None.
Methods Documentation
- add_callback(func, priority=0, validator=False)¶
Add a callback to the container.
Note that validators are applied on a per item basis, whereas regular callbacks are called with the whole list after modification.
- Parameters:
- funcfunc
The callback function to add
- priorityint, optional
This can optionally be used to force a certain order of execution of callbacks (larger values indicate a higher priority).
- validatorbool, optional
Whether the callback is a validator, which is a special kind of callback that gets called with the item being added to the container before the container is modified. The validator can return the value as-is, modify it, or emit warnings or an exception.
- copy(/)¶
Return a shallow copy of the list.
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=sys.maxsize, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- notify_all(*args, **kwargs)¶
- pop(index=-1)[source]¶
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- remove(value)[source]¶
Remove first occurrence of value.
Raises ValueError if the value is not present.
- remove_callback(func)¶
Remove a callback from the container.
- sort(key=None, reverse=False)[source]¶
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.