pyface.data_view.i_data_wrapper module

class pyface.data_view.i_data_wrapper.DataFormat(mimetype: str, serialize: Callable[[Any], bytes], deserialize: Callable[[bytes], Any])[source]

Bases: tuple

Information about a mimetype and serializers.

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

mimetype: str

The mimetype of the data.

serialize: Callable[[Any], bytes]

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

deserialize: Callable[[bytes], Any]

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

DataFormat factory for text mimetypes.

class pyface.data_view.i_data_wrapper.IDataWrapper(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: 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()[source]

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

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

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

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

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

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

Bases: 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)[source]

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

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

Encode and set data for the format.

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

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