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
See also
Drag and Drop Overview, wx.DataObject, wx.DataObjectSimple, wx.FileDataObject, wx.TextDataObject, wx.BitmapDataObject
The default constructor. |
|
Adds the dataObject to the list of supported objects and it becomes the preferred object if preferred is |
|
Returns a list of wx.DataFormat objects which this data object |
|
Returns the pointer to the object which supports the passed format for the specified direction. |
|
Report the format passed to the |
|
See |
|
wx.
DataObjectComposite
(DataObject)¶Possible constructors:
DataObjectComposite()
DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats.
__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
.
dataObject (wx.DataObjectSimple) –
preferred (bool) –
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.
format (wx.DataFormat) –
dir (DataObject.Direction) –
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.
SetData
(self, format, buf)¶bool
AllFormats
¶See GetAllFormats
ReceivedFormat
¶