Skip to content

Gdk.Drag

class — extends GObject.Object

Represents the source of an ongoing DND operation.

A GdkDrag is created when a drag is started, and stays alive for duration of the DND operation. After a drag has been started with Drag.begin, the caller gets informed about the status of the ongoing drag operation with signals on the GdkDrag object.

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

drop_done

def drop_done(self, success: bool) -> None

Informs GDK that the drop ended.

Passing False for success may trigger a drag cancellation animation.

This function is called by the drag source, and should be the last call before dropping the reference to the drag.

The GdkDrag will only take the first Drag.drop_done call as effective, if this function is called multiple times, all subsequent calls will be ignored.

Parameters:

  • success — whether the drag was ultimatively successful

get_actions

def get_actions(self) -> DragAction

Determines the bitmask of possible actions proposed by the source.

get_content

def get_content(self) -> ContentProvider

Returns the GdkContentProvider associated to the GdkDrag object.

get_device

def get_device(self) -> Device

Returns the GdkDevice associated to the GdkDrag object.

get_display

def get_display(self) -> Display

Gets the GdkDisplay that the drag object was created for.

get_drag_surface

def get_drag_surface(self) -> Surface | None

Returns the surface on which the drag icon should be rendered during the drag operation.

Note that the surface may not be available until the drag operation has begun. GDK will move the surface in accordance with the ongoing drag operation. The surface is owned by drag and will be destroyed when the drag operation is over.

get_formats

def get_formats(self) -> ContentFormats

Retrieves the formats supported by this GdkDrag object.

get_selected_action

def get_selected_action(self) -> DragAction

Determines the action chosen by the drag destination.

get_surface

def get_surface(self) -> Surface

Returns the GdkSurface where the drag originates.

set_hotspot

def set_hotspot(self, hot_x: int, hot_y: int) -> None

Sets the position of the drag surface that will be kept under the cursor hotspot.

Initially, the hotspot is at the top left corner of the drag surface.

Parameters:

  • hot_x — x coordinate of the drag surface hotspot
  • hot_y — y coordinate of the drag surface hotspot

Static functions

begin

@staticmethod
def begin(surface: Surface, device: Device, content: ContentProvider, actions: DragAction | int, dx: float, dy: float) -> Drag | None

Starts a drag and creates a new drag context for it.

This function is called by the drag source. After this call, you probably want to set up the drag icon using the surface returned by Drag.get_drag_surface.

This function returns a reference to the Drag object, but GTK keeps its own reference as well, as long as the DND operation is going on.

Note: if actions include DragAction.MOVE, you need to listen for the Drag.dnd-finished signal and delete the data at the source if Drag.get_selected_action returns DragAction.MOVE.

Parameters:

  • surface — the source surface for this drag
  • device — the device that controls this drag
  • content — the offered content
  • actions — the actions supported by this drag
  • dx — the x offset to device's position where the drag nominally started
  • dy — the y offset to device's position where the drag nominally started

Properties

actions

actions: DragAction | int  # read/write

The possible actions of this drag.

content

content: ContentProvider  # read/write

The GdkContentProvider.

device

device: Device  # read/write

The GdkDevice that is performing the drag.

display

display: Display  # read-only

The GdkDisplay that the drag belongs to.

formats

formats: ContentFormats  # read/write

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

selected_action

selected_action: DragAction | int  # read/write

The currently selected action of the drag.

surface

surface: Surface  # read/write

The surface where the drag originates.

Signals

cancel

def on_cancel(self, reason: DragCancelReason) -> None: ...

Emitted when the drag operation is cancelled.

dnd-finished

def on_dnd_finished(self) -> None: ...

Emitted when the destination side has finished reading all data.

The drag object can now free all miscellaneous data.

drop-performed

def on_drop_performed(self) -> None: ...

Emitted when the drop operation is performed on an accepting client.