pyface.data_view.data_models.data_accessors module

Classes for extracting data from objects

This module provides helper classes for the row table data model and related classes for extracting data from an object in a consistent way.

class pyface.data_view.data_models.data_accessors.AbstractDataAccessor[source]

Bases: traits.has_traits.ABCHasStrictTraits

Accessor that gets and sets data on an object.

title = Str()

A human-readable label for the accessor.

title_type = Instance(AbstractValueType, factory=TextValue)

The value type of the title of this accessor, suitable for use in a header.

value_type = Instance(AbstractValueType)

The value type of the data accessed.

updated = Event

An event fired when accessor is updated update. The payload is a tuple of the accessor info and whether the title or value changed (or both).

abstract get_value(obj)[source]

Return a value for the provided object.

Parameters

obj (any) – The object that contains the data.

Returns

value – The data value contained in the object.

Return type

any

can_set_value(obj)[source]

Return whether the value can be set on the provided object.

Parameters

obj (any) – The object that contains the data.

Returns

can_set_value – Whether or not the value can be set.

Return type

bool

set_value(obj, value)[source]

Set the value on the provided object.

Parameters
  • obj (any) – The object that contains the data.

  • value (any) – The data value to set.

Raises

DataViewSetError – If setting the value fails.

class pyface.data_view.data_models.data_accessors.ConstantDataAccessor[source]

Bases: pyface.data_view.data_models.data_accessors.AbstractDataAccessor

DataAccessor that returns a constant value.

value = Any()

The value to return.

get_value(obj)[source]

Return the value ignoring the provided object.

Parameters

obj (any) – An object.

Returns

value – The data value contained in this class’ value trait.

Return type

any

class pyface.data_view.data_models.data_accessors.AttributeDataAccessor[source]

Bases: pyface.data_view.data_models.data_accessors.AbstractDataAccessor

DataAccessor that presents an extended attribute on an object.

This is suitable for use with Python objects, including HasTraits classes.

attr = Str()

The extended attribute name of the trait holding the value.

get_value(obj)[source]

Return the attribute value for the provided object.

Parameters

obj (any) – The object that contains the data.

Returns

value – The data value contained in the object’s attribute.

Return type

any

can_set_value(obj)[source]

Return whether the value can be set on the provided object.

Parameters

obj (any) – The object that contains the data.

Returns

can_set_value – Whether or not the value can be set.

Return type

bool

set_value(obj, value)[source]

Set the value on the provided object.

Parameters
  • obj (any) – The object that contains the data.

  • value (any) – The data value to set.

Raises

DataViewSetError – If setting the value fails.

class pyface.data_view.data_models.data_accessors.IndexDataAccessor[source]

Bases: pyface.data_view.data_models.data_accessors.AbstractDataAccessor

DataAccessor that presents an index on a sequence object.

This is suitable for use with a sequence.

index = Int()

The index in a sequence which holds the value.

get_value(obj)[source]

Return the indexed value for the provided object.

Parameters

obj (sequence) – The object that contains the data.

Returns

value – The data value contained in the object at the index.

Return type

any

can_set_value(obj)[source]

Return whether the value can be set on the provided object.

Parameters

obj (any) – The object that contains the data.

Returns

can_set_value – Whether or not the value can be set.

Return type

bool

set_value(obj, value)[source]

Set the value on the provided object.

Parameters
  • obj (any) – The object that contains the data.

  • value (any) – The data value to set.

Raises

DataViewSetError – If setting the value fails.

class pyface.data_view.data_models.data_accessors.KeyDataAccessor[source]

Bases: pyface.data_view.data_models.data_accessors.AbstractDataAccessor

DataAccessor that presents an item on a mapping object.

This is suitable for use with a mapping, such as a dictionary.

key = Instance(Hashable)

The key in the mapping holding the value.

get_value(obj)[source]

Return the key’s value for the provided object.

Parameters

obj (mapping) – The object that contains the data.

Returns

value – The data value contained in the given key of the object.

Return type

any

can_set_value(obj)[source]

Set the value on the provided object.

Parameters
  • obj (mapping) – The object that contains the data.

  • value (any) – The data value to set.

Raises

DataViewSetError – If setting the value fails.

set_value(obj, value)[source]

Set the value on the provided object.

Parameters
  • obj (any) – The object that contains the data.

  • value (any) – The data value to set.

Raises

DataViewSetError – If setting the value fails.