napari.utils.events.EventedDict¶
- class napari.utils.events.EventedDict(data: Optional[Mapping[napari.utils.events.containers._dict._K, napari.utils.events.containers._dict._T]] = None, basetype: Union[Type[napari.utils.events.containers._dict._T], Sequence[Type[napari.utils.events.containers._dict._T]]] = ())[source]¶
Bases:
napari.utils.events.containers._dict.TypedMutableMapping
[napari.utils.events.containers._dict._K
,napari.utils.events.containers._dict._T
]Mutable dictionary that emits events when altered.
This class is designed to behave exactly like builtin
dict
, but will emit events before and after all mutations (addition, removal, and changing).- Parameters
data (Mapping, optional) – Dictionary to initialize the class with.
basetype (type of sequence of types, optional) – Type of the element in the dictionary.
- Events
changed (key (K, old_value: T, value: T)) – emitted when item at
key
is changed fromold_value
tovalue
adding (key (K)) – emitted before an item is added to the dictionary with
key
added (key (K, value: T)) – emitted after
value
was added to the dictionary withkey
removing (key (K)) – emitted before
key
is removed from the dictionaryremoved (key (K, value: T)) – emitted after
key
was removed from the dictionaryupdated (key, K, value (T)) – emitted after
value
ofkey
was changed. Only implemented by subclasses to give them an option to trigger some update aftervalue
was changed and this class did not register it. This can be useful if thebasetype
is not an evented object.
Methods
clear
()copy
()Return a shallow copy of the dictionary.
get
(k[,d])items
()key
(value)Return first instance of value.
keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem
()as a 2-tuple; but raise KeyError if D is empty.
setdefault
(k[,d])update
([E, ]**F)If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values
()Attributes
Details
- clear() None. Remove all items from D. ¶
- copy() napari.utils.events.containers._dict.TypedMutableMapping[napari.utils.events.containers._dict._T] ¶
Return a shallow copy of the dictionary.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values ¶