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
See also
Drag and Drop Overview, wx.DataObject, wx.DataObjectSimple, wx.FileDataObject, wx.TextDataObject, wx.BitmapDataObject
Class Hierarchy¶
Methods Summary¶
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 |
|
Properties Summary¶
See |
|
Class API¶
- class wx.DataObjectComposite(DataObject)¶
Possible constructors:
DataObjectComposite() -> None
DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats.
Methods¶
- __init__(self)¶
The default constructor.
- Return type:
None
- 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:
dataObject (wx.DataObjectSimple)
preferred (bool)
- Return type:
None
- GetAllFormats(self, dir=DataObject.Get)¶
Returns a list of wx.DataFormat objects which this data object supports transferring in the given direction.
- Return type:
Any
- 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:
format (wx.DataFormat)
dir (DataObject.Direction)
- Return type:
Added 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:
- SetData(self, format, buf)¶
- Return type:
bool
Properties¶
- AllFormats¶
See
GetAllFormats
- ReceivedFormat¶