Table Of Contents

Previous topic

DataObject

Next topic

DataObjectSimple

This Page

phoenix_title DataObjectComposite

DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats.

It contains several DataObjectSimple objects and supports any format supported by at least one of them. Only one of these data objects is preferred (the first one if not explicitly changed by using the second parameter of Add) and its format determines the preferred format of the composite data object as well.

See DataObject documentation for the reasons why you might prefer to use DataObject directly instead of DataObjectComposite for efficiency reasons.

This example shows how a composite data object capable of storing either bitmaps or file names (presumably of bitmap files) can be initialized and used:

def MyDropTarget(self):

    dataobj = wx.DataObjectComposite()
    dataobj.Add(wx.BitmapDataObject(), True)
    dataobj.Add(wx.FileDataObject())
    self.SetDataObject(dataobj)


def OnData(self, x, y, defaultDragResult):

    dragResult = wx.DropTarget.OnData(x, y, defaultDragResult)

    if dragResult == defaultDragResult:
        dataobjComp = self.GetDataObject()

        format = dataObjects.GetReceivedFormat()
        dataobj = dataobjComp.GetObject(format)

        if format.GetType() == wx.DF_BITMAP:
            dataobjBitmap = dataobj
            # ... use dataobj.GetBitmap() ...


        elif format.GetType() == wx.DF_FILENAME:
            dataobjFile = dataobj
            # ... use dataobj.GetFilenames() ...

        else:
            raise Exception("unexpected data object format")

    return dragResult

class_hierarchy Inheritance Diagram

Inheritance diagram for class DataObjectComposite

Inheritance diagram of DataObjectComposite


method_summary Methods Summary

__init__ The default constructor.
Add Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is True.
GetAllFormats Returns a list of wx.DataFormat objects which this data object supports
GetObject Returns the pointer to the object which supports the passed format for the specified direction.
GetReceivedFormat Report the format passed to the SetData method.

api Class API



class DataObjectComposite(DataObject)

DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats.

Possible constructors:

DataObjectComposite()

Methods



__init__(self)

The default constructor.



Add(self, dataObject, preferred=False)

Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is True.

Parameters:


GetAllFormats(self, dir=DataObject::Get)
Returns a list of wx.DataFormat objects which this data object supports transfering in the given direction.
Return type:PyObject


GetObject(self, format, dir=DataObject.Get)

Returns the pointer to the object which supports the passed format for the specified direction.

None is returned if the specified format is not supported for this direction dir. The returned pointer is owned by DataObjectComposite itself and shouldn’t be deleted by caller.

Parameters:
  • format (DataFormat) –
  • dir (DataObject.Direction) –
Return type:

DataObjectSimple

New in version 2.9.1.



GetReceivedFormat(self)

Report the format passed to the SetData method.

This should be the format of the data object within the composite that received data from the clipboard or the DnD operation. You can use this method to find out what kind of data object was received.

Return type: DataFormat

Properties



AllFormats

See GetAllFormats



ReceivedFormat

See GetReceivedFormat