This module contains the ObservableList.
This list works like a normal list but additionally observers can be registered
that are notified, whenever the list is changed.
-
class
ObservableList.
ObservableList
(iterable=())[source]
Bases: list
The observable list behaves like a list but changes can be observed.
See the Observer Pattern for more understanding.
The methods “clear” and “copy” are not available in Python 2.
-
__delitem__
(index_or_slice)[source]
Delete self[key].
-
__iadd__
(other)[source]
Implement self+=value.
-
__imul__
(multiplier)[source]
Implement self*=value.
-
__init__
(iterable=())[source]
Initialize self. See help(type(self)) for accurate signature.
-
__setitem__
(index_or_slice, value)[source]
Set self[key] to value.
-
__weakref__
list of weak references to the object (if defined)
-
append
(object) → None -- append object to end[source]
-
clear
() → None -- remove all items from L[source]
-
extend
(iterable) → None -- extend list by appending elements from the iterable[source]
-
insert
(index, item)[source]
L.insert(index, object) – insert object before index
-
notify_observers
(change)[source]
Notify the observers about the change.
-
pop
([index]) → item -- remove and return item at index (default last).[source]
Raises IndexError if list is empty or index is out of range.
-
register_observer
(observer)[source]
Register an observer.
Parameters: | observer – callable that takes a Change as first
argument |
-
remove
(value) → None -- remove first occurrence of value.[source]
Raises ValueError if the value is not present.
-
class
ObservableList.
Change
(list_, slice_)[source]
Bases: object
The base class for changes.
-
__init__
(list_, slice_)[source]
Initialize the change.
Parameters: |
- list_ (list) – the list that changed
- slice_ (slice) – the slice of the
list_ to change
|
-
__repr__
()[source]
The change as string.
-
__weakref__
list of weak references to the object (if defined)
-
adds
()[source]
Whether the change adds values.
-
changed_object
The object that was changed.
Returns: | the object that was changed |
-
elements
The elements affected by this change.
-
items
()[source]
Return an iterable over pairs of index and value.
-
length
The number of elements changed.
assert change.length == len(change.indices)
assert change.length == len(change.elements)
-
range
The indices of the changed objects.
-
removes
()[source]
Whether the change removes values.
-
start
The start index of the change.
-
step
The step size of the change.
-
stop
The stop index of the change.
Note
As with lists, the element at the stop index is excluded
from the change.
-
class
ObservableList.
AddChange
(list_, slice_)[source]
Bases: ObservableList.Change
A change that adds elements.
-
adds
()[source]
Whether the change adds values (True).
-
class
ObservableList.
RemoveChange
(list_, slice_)[source]
Bases: ObservableList.Change
A change that removes elements.
-
removes
()[source]
Whether the change removes values (True).