traits.trait_dict_object Module

Classes

class traits.trait_dict_object.TraitDictEvent(added=None, changed=None, removed=None)[source]

An object reporting in-place changes to a traits dict.

Parameters
  • added (dict or None) – New keys and values, or optionally None if nothing was added.

  • changed (dict or None) – Updated keys and their previous values, or optionally None if nothing was changed.

  • removed (dict or None) – Old keys and values that were just removed, or optionally None if nothing was removed.

added

New keys and values. If nothing was added this is an empty dict.

Type

dict

changed

Updated keys and their previous values. If nothing was changed this is an empty dict.

Type

dict

removed

Old keys and values that were just removed. If nothing was removed this is an empty dict.

Type

dict

class traits.trait_dict_object.TraitDictObject(trait, object, name, value)[source]

A subclass of dict that fires trait events when mutated.

This is used by the Dict trait type, and all values set into a Dict trait will be copied into a new TraitDictObject instance.

Mutation of the TraitDictObject will fire a “name_items” event with appropriate added, changed and removed values.

Parameters
  • trait (CTrait instance) – The CTrait instance associated with the attribute that this dict has been set to.

  • object (HasTraits instance) – The HasTraits instance that the dict has been set as an attribute for.

  • name (str) – The name of the attribute on the object.

  • value (dict) – The dict of values to initialize the TraitDictObject with.

trait

The CTrait instance associated with the attribute that this dict has been set to.

Type

CTrait instance

object

A weak reference to a HasTraits instance that the dict has been set as an attribute for.

Type

weak reference to a HasTraits instance

name

The name of the attribute on the object.

Type

str

name_items

The name of the items event trait that the trait dict will fire when mutated.

Type

str

clear() → None. Remove all items from D.[source]
update([E, ]**F) → None. Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
pop(k[, d]) → v, remove specified key and return the corresponding value.[source]

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[source]

2-tuple; but raise KeyError if D is empty.