Skip to content

Gdk.Drop

class — extends GObject.Object

Represents the target of an ongoing DND operation.

Possible drop sites get informed about the status of the ongoing drag operation with events of type GDK_DRAG_ENTER, GDK_DRAG_LEAVE, GDK_DRAG_MOTION and GDK_DROP_START. The GdkDrop object can be obtained from these Event types using DNDEvent.get_drop.

The actual data transfer is initiated from the target side via an async read, using one of the GdkDrop methods for this purpose: Drop.read_async or Drop.read_value_async.

GTK provides a higher level abstraction based on top of these functions, and so they are not normally needed in GTK applications. See the "Drag and Drop" section of the GTK documentation for more information.

Methods

finish

def finish(self, action: DragAction | int) -> None

Ends the drag operation after a drop.

The action must be a single action selected from the actions available via Drop.get_actions.

Parameters:

  • action — the action performed by the destination or GDK_ACTION_NONE if the drop failed

get_actions

def get_actions(self) -> DragAction

Returns the possible actions for this GdkDrop.

If this value contains multiple actions - i.e. DragAction.is_unique returns false for the result - Drop.finish must choose the action to use when accepting the drop. This will only happen if you passed GDK_ACTION_ASK as one of the possible actions in Drop.status. GDK_ACTION_ASK itself will not be included in the actions returned by this function.

This value may change over the lifetime of the Drop both as a response to source side actions as well as to calls to Drop.status or Drop.finish. The source side will not change this value anymore once a drop has started.

get_device

def get_device(self) -> Device

Returns the GdkDevice performing the drop.

get_display

def get_display(self) -> Display

Gets the GdkDisplay that self was created for.

get_drag

def get_drag(self) -> Drag | None

If this is an in-app drag-and-drop operation, returns the GdkDrag that corresponds to this drop.

If it is not, NULL is returned.

get_formats

def get_formats(self) -> ContentFormats

Returns the GdkContentFormats that the drop offers the data to be read in.

get_surface

def get_surface(self) -> Surface

Returns the GdkSurface performing the drop.

read_async

def read_async(self, mime_types: list[str], io_priority: int, cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Asynchronously read the dropped data from a GdkDrop in a format that complies with one of the mime types.

Parameters:

  • mime_types — pointer to an array of mime types
  • io_priority — the I/O priority for the read operation
  • cancellable — optional GCancellable object
  • callback — a GAsyncReadyCallback to call when the request is satisfied

read_finish

def read_finish(self, result: Gio.AsyncResult) -> tuple[Gio.InputStream | None, str]

Finishes an async drop read operation.

Note that you must not use blocking read calls on the returned stream in the GTK thread, since some platforms might require communication with GTK to complete the data transfer. You can use async APIs such as Gio.InputStream.read_bytes_async.

See Drop.read_async.

Parameters:

  • result — a GAsyncResult

read_value_async

def read_value_async(self, type: type | GObject.Type, io_priority: int, cancellable: Gio.Cancellable | None = ..., callback: Gio.AsyncReadyCallback | None = ...) -> None

Asynchronously request the drag operation's contents converted to the given type.

For local drag-and-drop operations that are available in the given GType, the value will be copied directly. Otherwise, GDK will try to use content_deserialize_async to convert the data.

Parameters:

  • type — a GType to read
  • io_priority — the I/O priority of the request.
  • cancellable — optional GCancellable object, None to ignore.
  • callback — callback to call when the request is satisfied

read_value_finish

def read_value_finish(self, result: Gio.AsyncResult) -> GObject.Value

Finishes an async drop read.

See Drop.read_value_async.

Parameters:

  • result — a GAsyncResult

status

def status(self, actions: DragAction | int, preferred: DragAction | int) -> None

Selects all actions that are potentially supported by the destination.

When calling this function, do not restrict the passed in actions to the ones provided by Drop.get_actions. Those actions may change in the future, even depending on the actions you provide here.

The preferred action is a hint to the drag-and-drop mechanism about which action to use when multiple actions are possible.

This function should be called by drag destinations in response to GDK_DRAG_ENTER or GDK_DRAG_MOTION events. If the destination does not yet know the exact actions it supports, it should set any possible actions first and then later call this function again.

Parameters:

  • actions — Supported actions of the destination, or GDK_ACTION_NONE to indicate that a drop will not be accepted
  • preferred — A unique action that's a member of actions indicating the preferred action

Properties

actions

actions: DragAction | int  # read/write

The possible actions for this drop

device

device: Device  # read/write

The GdkDevice performing the drop

display

display: Display  # read-only

The GdkDisplay that the drop belongs to.

drag

drag: Drag  # read/write

The GdkDrag that initiated this drop

formats

formats: ContentFormats  # read/write

The possible formats that the drop can provide its data in.

surface

surface: Surface  # read/write

The GdkSurface the drop happens on