DropTargetAsync#
Superclasses: EventController
, Object
GtkDropTargetAsync
is an event controller to receive Drag-and-Drop
operations, asynchronously.
It is the more complete but also more complex method of handling drop
operations compared to DropTarget
, and you should only use
it if GtkDropTarget
doesn’t provide all the features you need.
To use a GtkDropTargetAsync
to receive drops on a widget, you create
a GtkDropTargetAsync
object, configure which data formats and actions
you support, connect to its signals, and then attach it to the widget
with add_controller
.
During a drag operation, the first signal that a GtkDropTargetAsync
emits is accept
, which is meant to determine
whether the target is a possible drop site for the ongoing drop. The
default handler for the ::accept signal accepts the drop if it finds
a compatible data format and an action that is supported on both sides.
If it is, and the widget becomes a target, you will receive a
drag_enter
signal, followed by
drag_motion
signals as the pointer moves,
optionally a drop
signal when a drop happens,
and finally a drag_leave
signal when the
pointer moves off the widget.
The ::drag-enter and ::drag-motion handler return a GdkDragAction
to update the status of the ongoing operation. The ::drop handler
should decide if it ultimately accepts the drop and if it does, it
should initiate the data transfer and finish the operation by calling
finish
.
Between the ::drag-enter and ::drag-leave signals the widget is a
current drop target, and will receive the DROP_ACTIVE
state, which can be used by themes to style the widget as a drop target.
Constructors#
- class DropTargetAsync
- classmethod new(formats: ContentFormats | None, actions: DragAction) DropTargetAsync #
Creates a new
GtkDropTargetAsync
object.- Parameters:
formats – the supported data formats
actions – the supported actions
Methods#
- class DropTargetAsync
- get_actions() DragAction #
Gets the actions that this drop target supports.
- get_formats() ContentFormats | None #
Gets the data formats that this drop target accepts.
If the result is
None
, all formats are expected to be supported.
- reject_drop(drop: Drop) None #
Sets the
drop
as not accepted on this drag site.This function should be used when delaying the decision on whether to accept a drag or not until after reading the data.
- Parameters:
drop – the
GdkDrop
of an ongoing drag operation
- set_actions(actions: DragAction) None #
Sets the actions that this drop target supports.
- Parameters:
actions – the supported actions
- set_formats(formats: ContentFormats | None = None) None #
Sets the data formats that this drop target will accept.
- Parameters:
formats – the supported data formats or
None
for any format
Properties#
- class DropTargetAsync
- props.actions: DragAction#
The type of the None singleton.
- props.formats: ContentFormats#
The type of the None singleton.
Signals#
- class DropTargetAsync.signals
-
- drag_enter(drop: Drop, x: float, y: float) DragAction #
The type of the None singleton.
- Parameters:
drop – the
GdkDrop
x – the x coordinate of the current pointer position
y – the y coordinate of the current pointer position
- drag_motion(drop: Drop, x: float, y: float) DragAction #
The type of the None singleton.
- Parameters:
drop – the
GdkDrop
x – the x coordinate of the current pointer position
y – the y coordinate of the current pointer position