.. include:: headings.inc .. _DataObjectComposite: ========================================================================================================================================== |phoenix_title| **DataObjectComposite** ========================================================================================================================================== :ref:`DataObjectComposite` is the simplest :ref:`DataObject` derivation which may be used to support multiple formats. It contains several :ref:`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 :meth:`~DataObjectComposite.Add`) and its format determines the preferred format of the composite data object as well. See :ref:`DataObject` documentation for the reasons why you might prefer to use :ref:`DataObject` directly instead of :ref:`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 .. seealso:: :ref:`Drag and Drop Overview `, :ref:`DataObject`, :ref:`DataObjectSimple`, :ref:`FileDataObject`, :ref:`TextDataObject`, :ref:`BitmapDataObject` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **DataObjectComposite** .. raw:: html

Inheritance diagram of DataObjectComposite

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~DataObjectComposite.__init__` The default constructor. :meth:`~DataObjectComposite.Add` Adds the `dataObject` to the list of supported objects and it becomes the preferred object if `preferred` is ``True``. :meth:`~DataObjectComposite.GetAllFormats` Returns a list of wx.DataFormat objects which this data object supports :meth:`~DataObjectComposite.GetObject` Returns the pointer to the object which supports the passed format for the specified direction. :meth:`~DataObjectComposite.GetReceivedFormat` Report the format passed to the :meth:`SetData` method. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~DataObjectComposite.AllFormats` See :meth:`~DataObjectComposite.GetAllFormats` :attr:`~DataObjectComposite.ReceivedFormat` See :meth:`~DataObjectComposite.GetReceivedFormat` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: DataObjectComposite(DataObject) DataObjectComposite is the simplest DataObject derivation which may be used to support multiple formats. **Possible constructors**:: DataObjectComposite() .. method:: __init__(self) The default constructor. .. method:: Add(self, dataObject, preferred=False) Adds the `dataObject` to the list of supported objects and it becomes the preferred object if `preferred` is ``True``. :param `dataObject`: :type `dataObject`: DataObjectSimple :param `preferred`: :type `preferred`: bool .. method:: GetAllFormats(self, dir=DataObject::Get) Returns a list of wx.DataFormat objects which this data object supports transfering in the given direction. :rtype: `PyObject` .. method:: 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 :ref:`DataObjectComposite` itself and shouldn't be deleted by caller. :param `format`: :type `format`: DataFormat :param `dir`: :type `dir`: DataObject.Direction :rtype: :ref:`DataObjectSimple` .. versionadded:: 2.9.1 .. method:: GetReceivedFormat(self) Report the format passed to the :meth:`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. :rtype: :ref:`DataFormat` .. attribute:: AllFormats See :meth:`~DataObjectComposite.GetAllFormats` .. attribute:: ReceivedFormat See :meth:`~DataObjectComposite.GetReceivedFormat`