.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.DropTarget: ========================================================================================================================================== |phoenix_title| **wx.DropTarget** ========================================================================================================================================== This class represents a target for a drag and drop operation. A :ref:`wx.DataObject` can be associated with it and by default, this object will be filled with the data from the drag source, if the data formats supported by the data object match the drag source data format. There are various virtual handler functions defined in this class which may be overridden to give visual feedback or react in a more fine-tuned way, e.g. by not accepting data on the whole window area, but only a small portion of it. The normal sequence of calls is :meth:`~wx.DropTarget.OnEnter`, :meth:`~wx.DropTarget.OnDragOver` possibly many times, :meth:`~wx.DropTarget.OnDrop` and finally :meth:`~wx.DropTarget.OnData`. .. seealso:: :ref:`Drag and Drop Overview `, :ref:`DataObject Overview `, :ref:`wx.DropSource`, :ref:`wx.TextDropTarget`, :ref:`wx.FileDropTarget`, :ref:`wx.DataFormat`, :ref:`wx.DataObject` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html
Inheritance diagram for class DropTarget:
| |sub_classes| Known Subclasses ============================== :ref:`wx.FileDropTarget`, :ref:`wx.TextDropTarget` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.DropTarget.__init__` Constructor. :meth:`~wx.DropTarget.GetData` This method may only be called from within :meth:`~DropTarget.OnData` . :meth:`~wx.DropTarget.GetDataObject` Returns the data :ref:`wx.DataObject` associated with the drop target. :meth:`~wx.DropTarget.GetDefaultAction` Returns default action for drag and drop or DragNone if this not specified. :meth:`~wx.DropTarget.OnData` Called after :meth:`~DropTarget.OnDrop` returns ``True``. :meth:`~wx.DropTarget.OnDragOver` Called when the mouse is being dragged over the drop target. :meth:`~wx.DropTarget.OnDrop` Called when the user drops a data object on the target. :meth:`~wx.DropTarget.OnEnter` Called when the mouse enters the drop target. :meth:`~wx.DropTarget.OnLeave` Called when the mouse leaves the drop target. :meth:`~wx.DropTarget.SetDataObject` Sets the data :ref:`wx.DataObject` associated with the drop target and deletes any previously associated data object. :meth:`~wx.DropTarget.SetDefaultAction` Sets the default action for drag and drop. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.DropTarget.Data` See :meth:`~wx.DropTarget.GetData` :attr:`~wx.DropTarget.DataObject` See :meth:`~wx.DropTarget.GetDataObject` and :meth:`~wx.DropTarget.SetDataObject` :attr:`~wx.DropTarget.DefaultAction` See :meth:`~wx.DropTarget.GetDefaultAction` and :meth:`~wx.DropTarget.SetDefaultAction` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.DropTarget(object) **Possible constructors**:: DropTarget(data=None) This class represents a target for a drag and drop operation. .. method:: __init__(self, data=None) Constructor. `data` is the data to be associated with the drop target. :param `data`: :type `data`: wx.DataObject .. method:: GetData(self) This method may only be called from within :meth:`OnData` . By default, this method copies the data from the drop source to the :ref:`wx.DataObject` associated with this drop target, calling its :meth:`wx.DataObject.SetData` method. :rtype: `bool` .. method:: GetDataObject(self) Returns the data :ref:`wx.DataObject` associated with the drop target. :rtype: :ref:`wx.DataObject` .. method:: GetDefaultAction(self) Returns default action for drag and drop or DragNone if this not specified. :rtype: :ref:`wx.DragResult` .. method:: OnData(self, x, y, defResult) Called after :meth:`OnDrop` returns ``True``. By default this will usually :meth:`GetData` and will return the suggested default value `defResult`. :param `x`: :type `x`: int :param `y`: :type `y`: int :param `defResult`: :type `defResult`: wx.DragResult :rtype: :ref:`wx.DragResult` .. method:: OnDragOver(self, x, y, defResult) Called when the mouse is being dragged over the drop target. By default, this calls functions return the suggested return value `defResult`. :param `x`: The x coordinate of the mouse. :type `x`: int :param `y`: The y coordinate of the mouse. :type `y`: int :param `defResult`: Suggested value for return value. Determined by ``SHIFT`` or ``CONTROL`` key states. :type `defResult`: wx.DragResult :rtype: :ref:`wx.DragResult` :returns: The desired operation or DragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon. .. method:: OnDrop(self, x, y) Called when the user drops a data object on the target. Return ``False`` to veto the operation. :param `x`: The x coordinate of the mouse. :type `x`: int :param `y`: The y coordinate of the mouse. :type `y`: int :rtype: `bool` :returns: ``True`` to accept the data, or ``False`` to veto the operation. .. method:: OnEnter(self, x, y, defResult) Called when the mouse enters the drop target. By default, this calls :meth:`OnDragOver` . :param `x`: The x coordinate of the mouse. :type `x`: int :param `y`: The y coordinate of the mouse. :type `y`: int :param `defResult`: Suggested default for return value. Determined by ``SHIFT`` or ``CONTROL`` key states. :type `defResult`: wx.DragResult :rtype: :ref:`wx.DragResult` :returns: The desired operation or DragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon. .. method:: OnLeave(self) Called when the mouse leaves the drop target. .. method:: SetDataObject(self, data) Sets the data :ref:`wx.DataObject` associated with the drop target and deletes any previously associated data object. :param `data`: :type `data`: wx.DataObject .. method:: SetDefaultAction(self, action) Sets the default action for drag and drop. Use DragMove or DragCopy to set default action to move or copy and use DragNone (default) to set default action specified by initialization of dragging (see :meth:`wx.DropSource.DoDragDrop` ) :param `action`: :type `action`: wx.DragResult .. attribute:: Data See :meth:`~wx.DropTarget.GetData` .. attribute:: DataObject See :meth:`~wx.DropTarget.GetDataObject` and :meth:`~wx.DropTarget.SetDataObject` .. attribute:: DefaultAction See :meth:`~wx.DropTarget.GetDefaultAction` and :meth:`~wx.DropTarget.SetDefaultAction`