:right-sidebar: True DragSource =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: DragSource(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.GestureSingle`, :class:`~gi.repository.Gtk.Gesture`, :class:`~gi.repository.Gtk.EventController`, :class:`~gi.repository.GObject.Object` :Constructors: :: DragSource(**properties) new() -> Gtk.DragSource Constructors ------------ .. rst-class:: interim-class .. class:: DragSource :no-index: .. classmethod:: new() -> ~gi.repository.Gtk.DragSource Creates a new ``GtkDragSource`` object. Methods ------- .. rst-class:: interim-class .. class:: DragSource :no-index: .. method:: drag_cancel() -> None Cancels a currently ongoing drag operation. .. method:: get_actions() -> ~gi.repository.Gdk.DragAction Gets the actions that are currently set on the ``GtkDragSource``. .. method:: get_content() -> ~gi.repository.Gdk.ContentProvider | None Gets the current content provider of a ``GtkDragSource``. .. method:: get_drag() -> ~gi.repository.Gdk.Drag | None Returns the underlying ``GdkDrag`` object for an ongoing drag. .. method:: set_actions(actions: ~gi.repository.Gdk.DragAction) -> None Sets the actions on the ``GtkDragSource``. During a DND operation, the actions are offered to potential drop targets. If ``actions`` include ``%GDK_ACTION_MOVE``, you need to listen to the :obj:`~gi.repository.Gtk.DragSource.signals.drag_end` signal and handle ``delete_data`` being :const:`True`. This function can be called before a drag is started, or in a handler for the :obj:`~gi.repository.Gtk.DragSource.signals.prepare` signal. :param actions: the actions to offer .. method:: set_content(content: ~gi.repository.Gdk.ContentProvider | None = None) -> None Sets a content provider on a ``GtkDragSource``. When the data is requested in the cause of a DND operation, it will be obtained from the content provider. This function can be called before a drag is started, or in a handler for the :obj:`~gi.repository.Gtk.DragSource.signals.prepare` signal. You may consider setting the content provider back to :const:`None` in a :obj:`~gi.repository.Gtk.DragSource.signals.drag_end` signal handler. :param content: a ``GdkContentProvider`` .. method:: set_icon(paintable: ~gi.repository.Gdk.Paintable | None, hot_x: int, hot_y: int) -> None Sets a paintable to use as icon during DND operations. The hotspot coordinates determine the point on the icon that gets aligned with the hotspot of the cursor. If ``paintable`` is :const:`None`, a default icon is used. This function can be called before a drag is started, or in a :obj:`~gi.repository.Gtk.DragSource.signals.prepare` or :obj:`~gi.repository.Gtk.DragSource.signals.drag_begin` signal handler. :param paintable: the ``GdkPaintable`` to use as icon :param hot_x: the hotspot X coordinate on the icon :param hot_y: the hotspot Y coordinate on the icon Properties ---------- .. rst-class:: interim-class .. class:: DragSource :no-index: .. attribute:: props.actions :type: ~gi.repository.Gdk.DragAction The actions that are supported by drag operations from the source. Note that you must handle the :obj:`~gi.repository.Gtk.DragSource.signals.drag_end` signal if the actions include ``%GDK_ACTION_MOVE``. .. attribute:: props.content :type: ~gi.repository.Gdk.ContentProvider The data that is offered by drag operations from this source. Signals ------- .. rst-class:: interim-class .. class:: DragSource.signals :no-index: .. method:: drag_begin(drag: ~gi.repository.Gdk.Drag) -> None Emitted on the drag source when a drag is started. It can be used to e.g. set a custom drag icon with :obj:`~gi.repository.Gtk.DragSource.set_icon`. :param drag: the ``GdkDrag`` object .. method:: drag_cancel(drag: ~gi.repository.Gdk.Drag, reason: ~gi.repository.Gdk.DragCancelReason) -> bool Emitted on the drag source when a drag has failed. The signal handler may handle a failed drag operation based on the type of error. It should return :const:`True` if the failure has been handled and the default "drag operation failed" animation should not be shown. :param drag: the ``GdkDrag`` object :param reason: information on why the drag failed .. method:: drag_end(drag: ~gi.repository.Gdk.Drag, delete_data: bool) -> None Emitted on the drag source when a drag is finished. A typical reason to connect to this signal is to undo things done in :obj:`~gi.repository.Gtk.DragSource.signals.prepare` or :obj:`~gi.repository.Gtk.DragSource.signals.drag_begin` handlers. :param drag: the ``GdkDrag`` object :param delete_data: :const:`True` if the drag was performing ``%GDK_ACTION_MOVE``, and the data should be deleted .. method:: prepare(x: float, y: float) -> ~gi.repository.Gdk.ContentProvider | None Emitted when a drag is about to be initiated. It returns the ``GdkContentProvider`` to use for the drag that is about to start. The default handler for this signal returns the value of the :obj:`~gi.repository.Gtk.DragSource.props.content` property, so if you set up that property ahead of time, you don't need to connect to this signal. :param x: the X coordinate of the drag starting point :param y: the Y coordinate of the drag starting point