mitk.property_view.PropertyView#

class mitk.property_view.PropertyView(owner)#

Bases: MutableMapping

Live, lazy view over an object’s properties.

A MutableMapping that delegates every operation to the wrapped IPropertyOwner (typically an mitk.Image or mitk.MultiLabelSegmentation). It is not a snapshot: the view always reflects the current state of the underlying C++ object.

Notes

Reading (view[key], iteration, in) works for all properties, both owned and provided. Writing (view[key] = val, del view[key]) only works for owned properties and raises mitk.PropertyNotOwnedError for read-only (provided but not owned) properties. Use obj.property_is_owned(key) to check before writing.

PropertyView provides no synchronization. If properties are modified concurrently (for example from a C++ background thread), keys obtained during iteration may become stale before they are used. Callers that need a consistent snapshot should copy the view into a dict: snapshot = dict(view.items()).

Examples

>>> img.properties["DICOM.PatientName"] = "Doe^John"
>>> "DICOM.PatientName" in img.properties
True
>>> for key, value in img.properties.items():
...     print(key, value)
Parameters:

owner (Any)

__init__(owner)#

Wrap an object implementing the property-owner interface.

Parameters:

owner (Any) – An object exposing get_property, set_property, remove_property, and property_keys.

Return type:

None

Methods

__init__(owner)

Wrap an object implementing the property-owner interface.

clear()

get(k[,d])

items()

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.keys(): 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()

__contains__(key)#
Return type:

bool

Parameters:

key (object)

__delitem__(key)#

Remove key from the underlying object.

Parameters:

key (str) – Property name.

Raises:
Return type:

None

__eq__(other)#

Return self==value.

__getitem__(key)#

Return the coerced Python value for key.

Parameters:

key (str) – Property name.

Return type:

Any

Returns:

str, bool, int, float, an (r, g, b) tuple for color properties, or a mitk.BaseProperty for types without a known Python equivalent.

Raises:

KeyError – If key is not set on the underlying object.

__iter__()#
Return type:

Iterator[str]

__len__()#
Return type:

int

__setitem__(key, value)#

Set key to value on the underlying object.

Parameters:
  • key (str) – Property name.

  • value (Any) – Value to store. Auto-wrapped into the appropriate BaseProperty subtype.

Raises:

PropertyNotOwnedError – If the property is provided read-only (not owned) by the underlying object.

Return type:

None

clear() None.  Remove all items from D.#
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.keys(): 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#