:right-sidebar: True DropTarget =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: DropTarget(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.EventController`, :class:`~gi.repository.GObject.Object` :Constructors: :: DropTarget(**properties) new(type:GType, actions:Gdk.DragAction) -> Gtk.DropTarget Constructors ------------ .. rst-class:: interim-class .. class:: DropTarget :no-index: .. classmethod:: new(type: type, actions: ~gi.repository.Gdk.DragAction) -> ~gi.repository.Gtk.DropTarget Creates a new ``GtkDropTarget`` object. If the drop target should support more than 1 type, pass ``Invalid`` for ``type`` and then call :obj:`~gi.repository.Gtk.DropTarget.set_gtypes`. :param type: The supported type or ``Invalid`` :param actions: the supported actions Methods ------- .. rst-class:: interim-class .. class:: DropTarget :no-index: .. method:: get_actions() -> ~gi.repository.Gdk.DragAction Gets the actions that this drop target supports. .. method:: get_current_drop() -> ~gi.repository.Gdk.Drop | None Gets the currently handled drop operation. If no drop operation is going on, :const:`None` is returned. .. versionadded:: 4.4 .. method:: get_drop() -> ~gi.repository.Gdk.Drop | None Gets the currently handled drop operation. If no drop operation is going on, :const:`None` is returned. .. deprecated:: 4.4 Use :obj:`~gi.repository.Gtk.DropTarget.get_current_drop` instead .. method:: get_formats() -> ~gi.repository.Gdk.ContentFormats | None Gets the data formats that this drop target accepts. If the result is :const:`None`, all formats are expected to be supported. .. method:: get_gtypes() -> list[type] | None Gets the list of supported ``GType``'s that can be dropped on the target. If no types have been set, ``NULL`` will be returned. .. method:: get_preload() -> bool Gets whether data should be preloaded on hover. .. method:: get_value() -> ~typing.Any | None Gets the current drop data, as a ``GValue``. .. method:: reject() -> None Rejects the ongoing drop operation. If no drop operation is ongoing, i.e when :obj:`~gi.repository.Gtk.DropTarget.props.current_drop` is :const:`None`, this function does nothing. This function should be used when delaying the decision on whether to accept a drag or not until after reading the data. .. method:: set_actions(actions: ~gi.repository.Gdk.DragAction) -> None Sets the actions that this drop target supports. :param actions: the supported actions .. method:: set_gtypes(types: ~typing.Sequence[type] | None = None) -> None Sets the supported ``GType``'s for this drop target. :param types: all supported ``GType``'s that can be dropped on the target .. method:: set_preload(preload: bool) -> None Sets whether data should be preloaded on hover. :param preload: :const:`True` to preload drop data Properties ---------- .. rst-class:: interim-class .. class:: DropTarget :no-index: .. attribute:: props.actions :type: ~gi.repository.Gdk.DragAction The ``GdkDragActions`` that this drop target supports. .. attribute:: props.current_drop :type: ~gi.repository.Gdk.Drop The ``GdkDrop`` that is currently being performed. .. versionadded:: 4.4 .. attribute:: props.formats :type: ~gi.repository.Gdk.ContentFormats The ``GdkContentFormats`` that determine the supported data formats. .. attribute:: props.preload :type: bool Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released. Setting this property allows finer grained reaction to an ongoing drop at the cost of loading more data. The default value for this property is :const:`False` to avoid downloading huge amounts of data by accident. For example, if somebody drags a full document of gigabytes of text from a text editor across a widget with a preloading drop target, this data will be downloaded, even if the data is ultimately dropped elsewhere. For a lot of data formats, the amount of data is very small (like ``%GDK_TYPE_RGBA``), so enabling this property does not hurt at all. And for local-only Drag-and-Drop operations, no data transfer is done, so enabling it there is free. .. attribute:: props.value :type: ~typing.Any The value for this drop operation. This is :const:`None` if the data has not been loaded yet or no drop operation is going on. Data may be available before the :obj:`~gi.repository.Gtk.DropTarget.signals.drop` signal gets emitted - for example when the :obj:`~gi.repository.Gtk.DropTarget.props.preload` property is set. You can use the ::notify signal to be notified of available data. Signals ------- .. rst-class:: interim-class .. class:: DropTarget.signals :no-index: .. method:: accept(drop: ~gi.repository.Gdk.Drop) -> bool Emitted on the drop site when a drop operation is about to begin. If the drop is not accepted, :const:`False` will be returned and the drop target will ignore the drop. If :const:`True` is returned, the drop is accepted for now but may be rejected later via a call to :obj:`~gi.repository.Gtk.DropTarget.reject` or ultimately by returning :const:`False` from a :obj:`~gi.repository.Gtk.DropTarget.signals.drop` handler. The default handler for this signal decides whether to accept the drop based on the formats provided by the ``drop``. If the decision whether the drop will be accepted or rejected depends on the data, this function should return :const:`True`, the :obj:`~gi.repository.Gtk.DropTarget.props.preload` property should be set and the value should be inspected via the ::notify:value signal, calling :obj:`~gi.repository.Gtk.DropTarget.reject` if required. :param drop: the ``GdkDrop`` .. method:: drop(value: ~typing.Any, x: float, y: float) -> bool Emitted on the drop site when the user drops the data onto the widget. The signal handler must determine whether the pointer position is in a drop zone or not. If it is not in a drop zone, it returns :const:`False` and no further processing is necessary. Otherwise, the handler returns :const:`True`. In this case, this handler will accept the drop. The handler is responsible for using the given ``value`` and performing the drop operation. :param value: the ``GValue`` being dropped :param x: the x coordinate of the current pointer position :param y: the y coordinate of the current pointer position .. method:: enter(x: float, y: float) -> ~gi.repository.Gdk.DragAction Emitted on the drop site when the pointer enters the widget. It can be used to set up custom highlighting. :param x: the x coordinate of the current pointer position :param y: the y coordinate of the current pointer position .. method:: leave() -> None Emitted on the drop site when the pointer leaves the widget. Its main purpose it to undo things done in :obj:`~gi.repository.Gtk.DropTarget.signals.enter`. .. method:: motion(x: float, y: float) -> ~gi.repository.Gdk.DragAction Emitted while the pointer is moving over the drop target. :param x: the x coordinate of the current pointer position :param y: the y coordinate of the current pointer position