napari.utils.events.EventedDict#
- class napari.utils.events.EventedDict(data: Mapping[_K, _T] | None = None, basetype: type[_T] | Sequence[type[_T]] = ())[source]#
Bases:
TypedMutableMapping
[_K
,_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:
changing (key (K)) – emitted before an item at
key
is changedchanged (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() TypedMutableMapping[_K, _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 #