Gtk.DropTargetAsync

g GObject.Object GObject.Object Gtk.EventController Gtk.EventController GObject.Object->Gtk.EventController Gtk.DropTargetAsync Gtk.DropTargetAsync Gtk.EventController->Gtk.DropTargetAsync

Subclasses:

None

Methods

Inherited:

Gtk.EventController (13), GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (formats, actions)

get_actions ()

get_formats ()

reject_drop (drop)

set_actions (actions)

set_formats (formats)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Inherited:

Gtk.EventController (4)

Name

Type

Flags

Short Description

actions

Gdk.DragAction

r/w/en

formats

Gdk.ContentFormats

r/w/en

Signals

Inherited:

GObject.Object (1)

Name

Short Description

accept

Emitted on the drop site when a drop operation is about to begin.

drag-enter

Emitted on the drop site when the pointer enters the widget.

drag-leave

Emitted on the drop site when the pointer leaves the widget.

drag-motion

Emitted while the pointer is moving over the drop target.

drop

Emitted on the drop site when the user drops the data onto the widget.

Fields

Inherited:

GObject.Object (1)

Class Details

class Gtk.DropTargetAsync(**kwargs)
Bases:

Gtk.EventController

Abstract:

No

Structure:

Gtk.DropTargetAsyncClass

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 [class`Gtk`.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 [method`Gtk`.Widget.add_controller].

During a drag operation, the first signal that a GtkDropTargetAsync emits is [signal`Gtk`.DropTargetAsync::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 [signal`Gtk`.DropTargetAsync::drag-enter] signal, followed by [signal`Gtk`.DropTargetAsync::drag-motion] signals as the pointer moves, optionally a [signal`Gtk`.DropTargetAsync::drop] signal when a drop happens, and finally a [signal`Gtk`.DropTargetAsync::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 [method`Gdk`.Drop.finish].

Between the ::drag-enter and ::drag-leave signals the widget is a current drop target, and will receive the Gtk.StateFlags.DROP_ACTIVE state, which can be used by themes to style the widget as a drop target.

classmethod new(formats, actions)[source]
Parameters:
Returns:

the new GtkDropTargetAsync

Return type:

Gtk.DropTargetAsync

Creates a new GtkDropTargetAsync object.

get_actions()[source]
Returns:

the actions that this drop target supports

Return type:

Gdk.DragAction

Gets the actions that this drop target supports.

get_formats()[source]
Returns:

the supported data formats

Return type:

Gdk.ContentFormats or 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)[source]
Parameters:

drop (Gdk.Drop) – the GdkDrop of an ongoing drag operation

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.

set_actions(actions)[source]
Parameters:

actions (Gdk.DragAction) – the supported actions

Sets the actions that this drop target supports.

set_formats(formats)[source]
Parameters:

formats (Gdk.ContentFormats or None) – the supported data formats or None for any format

Sets the data formats that this drop target will accept.

Signal Details

Gtk.DropTargetAsync.signals.accept(drop_target_async, drop)
Signal Name:

accept

Flags:

RUN_LAST

Parameters:
Returns:

True if drop is accepted

Return type:

bool

Emitted on the drop site when a drop operation is about to begin.

If the drop is not accepted, False will be returned and the drop target will ignore the drop. If True is returned, the drop is accepted for now but may be rejected later via a call to [method`Gtk`.DropTargetAsync.reject_drop] or ultimately by returning False from a [signal`Gtk`.DropTargetAsync::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 needs further processing, such as inspecting the data, this function should return True and proceed as is drop was accepted and if it decides to reject the drop later, it should call [method`Gtk`.DropTargetAsync.reject_drop].

Gtk.DropTargetAsync.signals.drag_enter(drop_target_async, drop, x, y)
Signal Name:

drag-enter

Flags:

RUN_LAST

Parameters:
  • drop_target_async (Gtk.DropTargetAsync) – The object which received the signal

  • drop (Gdk.Drop) – the GdkDrop

  • x (float) – the x coordinate of the current pointer position

  • y (float) – the y coordinate of the current pointer position

Returns:

Preferred action for this drag operation.

Return type:

Gdk.DragAction

Emitted on the drop site when the pointer enters the widget.

It can be used to set up custom highlighting.

Gtk.DropTargetAsync.signals.drag_leave(drop_target_async, drop)
Signal Name:

drag-leave

Flags:

RUN_LAST

Parameters:

Emitted on the drop site when the pointer leaves the widget.

Its main purpose it to undo things done in GtkDropTargetAsync ::drag-enter.

Gtk.DropTargetAsync.signals.drag_motion(drop_target_async, drop, x, y)
Signal Name:

drag-motion

Flags:

RUN_LAST

Parameters:
  • drop_target_async (Gtk.DropTargetAsync) – The object which received the signal

  • drop (Gdk.Drop) – the GdkDrop

  • x (float) – the x coordinate of the current pointer position

  • y (float) – the y coordinate of the current pointer position

Returns:

Preferred action for this drag operation.

Return type:

Gdk.DragAction

Emitted while the pointer is moving over the drop target.

Gtk.DropTargetAsync.signals.drop(drop_target_async, drop, x, y)
Signal Name:

drop

Flags:

RUN_LAST

Parameters:
  • drop_target_async (Gtk.DropTargetAsync) – The object which received the signal

  • drop (Gdk.Drop) – the GdkDrop

  • x (float) – the x coordinate of the current pointer position

  • y (float) – the y coordinate of the current pointer position

Returns:

whether the drop is accepted at the given pointer position

Return type:

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 False and no further processing is necessary.

Otherwise, the handler returns True. In this case, this handler will accept the drop. The handler must ensure that [method`Gdk`.Drop.finish] is called to let the source know that the drop is done. The call to [method`Gdk`.Drop.finish] must only be done when all data has been received.

To receive the data, use one of the read functions provided by [class`Gdk`.Drop] such as [method`Gdk`.Drop.read_async] or [method`Gdk`.Drop.read_value_async].

Property Details

Gtk.DropTargetAsync.props.actions
Name:

actions

Type:

Gdk.DragAction

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The GdkDragActions that this drop target supports.

Gtk.DropTargetAsync.props.formats
Name:

formats

Type:

Gdk.ContentFormats

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The GdkContentFormats that determines the supported data formats.