traits.trait_list_object Module

Classes

class traits.trait_list_object.TraitListEvent(index=0, removed=None, added=None)[source]

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

Parameters
  • index (int or slice) – An index or slice indicating the location of the changes to the list.

  • added (list or None) – The list of values added to the list, or optionally None if nothing is added.

  • removed (list or None) – The list of values removed from the list, or optionally None if nothing is removed.

index

An index or slice indicating the location of the changes to the list.

Type

int or slice

added

The list of values added to the list. If nothing was added this is an empty list.

Type

list

removed

The list of values removed from the list. If nothing was removed this is an empty list.

Type

list

class traits.trait_list_object.TraitListObject(trait, object, name, value)[source]

A subclass of list that fires trait events when mutated.

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

Mutation of the TraitListObject will fire a “name_items” event with appropriate index, added and removed values. In the case of setting or deleting items with a slice, the index will hold either:

  • the location of the first element changed, if the step is 1. In this case the last element changed can be inferred from the length of the removed values.

  • the slice that was used, otherwise.

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

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

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

  • value (list) – The list of values to initialize the TraitListObject with.

trait

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

Type

CTrait instance

object

A weak reference to a HasTraits instance that the list 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 list will fire when mutated.

Type

str

append(object) → None -- append object to end[source]
insert(index, value)[source]

L.insert(index, object) – insert object before index

extend(iterable) → None -- extend list by appending elements from the iterable[source]
remove(value) → None -- remove first occurrence of value.[source]

Raises ValueError if the value is not present.

sort(key=None, reverse=False) → None -- stable sort *IN PLACE*[source]
reverse()[source]

L.reverse() – reverse IN PLACE

pop([index]) → item -- remove and return item at index (default last).[source]

Raises IndexError if list is empty or index is out of range.

clear() → None -- remove all items from L[source]
len_error(len)[source]

Utility method that raises an error if length is incorrect.