Drop#
Superclasses: Object
The GdkDrop 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 DRAG_ENTER, DRAG_LEAVE,
DRAG_MOTION and DROP_START. The GdkDrop object can be obtained
from these Event types using 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:
read_async or 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#
- class Drop
- finish(action: DragAction) None#
Ends the drag operation after a drop.
The
actionmust be a single action selected from the actions available viaget_actions.- Parameters:
action – the action performed by the destination or 0 if the drop failed
- get_actions() DragAction#
Returns the possible actions for this
GdkDrop.If this value contains multiple actions - i.e.
is_uniquereturnsFalsefor the result -finishmust choose the action to use when accepting the drop. This will only happen if you passedASKas one of the possible actions instatus.ASKitself will not be included in the actions returned by this function.This value may change over the lifetime of the
Dropboth as a response to source side actions as well as to calls tostatusorfinish. The source side will not change this value anymore once a drop has started.
- get_drag() Drag | None#
If this is an in-app drag-and-drop operation, returns the
GdkDragthat corresponds to this drop.If it is not,
Noneis returned.
- get_formats() ContentFormats#
Returns the
GdkContentFormatsthat the drop offers the data to be read in.
- async read_async(self, mime_types: list[str], io_priority: int) tuple[InputStream | None, str]#
This is the awaitable version of
read_async().- Parameters:
mime_types – pointer to an array of mime types
io_priority – the I/O priority for the read operation
- read_async(mime_types: list[str], io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#
Asynchronously read the dropped data from a
GdkDropin 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
GCancellableobjectcallback – a
GAsyncReadyCallbackto call when the request is satisfieduser_data – the data to pass to
callback
- read_finish(result: AsyncResult) tuple[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
read_bytes_async().See
read_async.- Parameters:
result – a
GAsyncResult
- async read_value_async(self, type: GType, io_priority: int) Value#
This is the awaitable version of
read_value_async().- Parameters:
type – a
GTypeto readio_priority – the I/O priority of the request.
- read_value_async(type: GType, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = 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 usecontent_deserialize_asyncto convert the data.- Parameters:
type – a
GTypeto readio_priority – the I/O priority of the request.
cancellable – optional
GCancellableobject,Noneto ignore.callback – callback to call when the request is satisfied
user_data – the data to pass to callback function
- read_value_finish(result: AsyncResult) Value#
Finishes an async drop read.
See
read_value_async.- Parameters:
result – a
GAsyncResult
- status(actions: DragAction, preferred: DragAction) 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
get_actions. Those actions may change in the future, even depending on the actions you provide here.The
preferredaction 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
DRAG_ENTERorDRAG_MOTIONevents. 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 0 to indicate that a drop will not be accepted
preferred – A unique action that’s a member of
actionsindicating the preferred action
Properties#
- class Drop
- props.actions: DragAction#
The type of the None singleton.
- props.formats: ContentFormats#
The type of the None singleton.