pyface.data_view.i_data_wrapper module

class pyface.data_view.i_data_wrapper.DataFormat

Bases: tuple

Information about a mimetype and serializers.

Simple namedtuple-based class that stores the mimetype, serializer and deserializer together.

property mimetype

The mimetype of the data.

property serialize

A callable that serializes this format. It should take an python object of a supported type, and return a bytestring.

property deserialize

A callable that deserializes this format. It should take a bytestring and return the extracted object.

pyface.data_view.i_data_wrapper.text_format(encoding='utf-8', mimetype='text/plain')

DataFormat factory for text mimetypes.

class pyface.data_view.i_data_wrapper.IDataWrapper

Bases: traits.has_traits.Interface

Wrapper around polymorphic toolkit data object containing mimedata.

To support clipboard and drag and drop operations, toolkits need a way of generically representing data in multiple formats. This is a wrapper class that provides a toolkit independent intreface to these classes which allow the exchange of data, with types specified by MIME types.

toolkit_data = Any()

The toolkit data object.

mimetypes()

Return a set of mimetypes holding data.

Returns

mimetypes – The set of mimetypes currently storing data in the toolkit data object.

Return type

set of str

has_format(format)

Whether or not a particular format has available data.

Parameters

format (DataFormat) – A data format object.

Returns

has_format – Whether or not there is data associated with that format in the underlying toolkit object.

Return type

bool

get_format(format)

The decoded data associted with the format.

Parameters

format (DataFormat) – A data format object.

Returns

data – The data decoded for the given format.

Return type

any

set_format(format, data)

Encode and set data for the format.

Parameters
  • format (DataFormat) – A data format object.

  • data (any) – The data to be encoded and stored.

get_mimedata(mimetype)

Get raw data for the given media type.

Parameters

mimetype (str) – The mime media type to be extracted.

Returns

mimedata – The mime media data as bytes.

Return type

bytes

set_mimedata(mimetype, mimedata)

Set raw data for the given media type.

Parameters
  • mimetype (str) – The mime media type to be extracted.

  • mimedata (bytes) – The mime media data encoded as bytes..

class pyface.data_view.i_data_wrapper.MDataWrapper

Bases: traits.has_traits.HasStrictTraits

Mixin class for DataWrappers.

This provides standard methods for using DataFormat objects, but not the low-level communication with the underlying toolkit.

has_format(format)

Whether or not a particular format has available data.

Parameters

format (DataFormat) – A data format object.

Returns

has_format – Whether or not there is data associated with that format in the underlying toolkit object.

Return type

bool

get_format(format)

The decoded data associted with the format.

Parameters

format (DataFormat) – A data format object.

Returns

data – The data decoded for the given format.

Return type

any

set_format(format, data)

Encode and set data for the format.

Parameters
  • format (DataFormat) – A data format object.

  • data (any) – The data to be encoded and stored.