Phoenix Logo

phoenix_title wx.DataObjectComposite

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

It contains several wx.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 wx.DataObject documentation for the reasons why you might prefer to use wx.DataObject directly instead of wx.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 Class Hierarchy

Inheritance diagram for class 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
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.
SetData  

api Class API



class wx.DataObjectComposite(DataObject)

Possible constructors:

DataObjectComposite()

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


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 transferring in the given direction.



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 wx.DataObjectComposite itself and shouldn’t be deleted by caller.

Parameters:
Return type:

wx.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: wx.DataFormat


SetData(self, format, buf)
Return type:bool

Properties



AllFormats

See GetAllFormats



ReceivedFormat

See GetReceivedFormat