Gtk.DropTargetAsync¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
Emitted on the drop site when a drop operation is about to begin. |
|
Emitted on the drop site when the pointer enters the widget. |
|
Emitted on the drop site when the pointer leaves the widget. |
|
Emitted while the pointer is moving over the drop target. |
|
Emitted on the drop site when the user drops the data onto the widget. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.DropTargetAsync(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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
GtkDropTargetdoesn’t provide all the features you need.To use a
GtkDropTargetAsyncto receive drops on a widget, you create aGtkDropTargetAsyncobject, 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
GtkDropTargetAsyncemits 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::acceptsignal 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-enterand::drag-motionhandler return aGdkDragActionto update the status of the ongoing operation. The::drophandler 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-enterand::drag-leavesignals the widget is a current drop target, and will receive theGtk.StateFlags.DROP_ACTIVEstate, which can be used by themes to style the widget as a drop target.- classmethod new(formats, actions)[source]¶
- Parameters:
formats (
Gdk.ContentFormatsorNone) – the supported data formatsactions (
Gdk.DragAction) – the supported actions
- Returns:
the new
GtkDropTargetAsync- Return type:
Creates a new
GtkDropTargetAsyncobject.
- get_actions()[source]¶
- Returns:
the actions that this drop target supports
- Return type:
Gets the actions that this drop target supports.
- get_formats()[source]¶
- Returns:
the supported data formats
- Return type:
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) – theGdkDropof 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.ContentFormatsorNone) – the supported data formats orNonefor 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:
- Parameters:
drop_target_async (
Gtk.DropTargetAsync) – The object which received the signaldrop (
Gdk.Drop) – theGdkDrop
- Returns:
Trueif drop is accepted- Return type:
Emitted on the drop site when a drop operation is about to begin.
If the drop is not accepted,
Falsewill be returned and the drop target will ignore the drop. IfTrueis returned, the drop is accepted for now but may be rejected later via a call to [method`Gtk`.DropTargetAsync.reject_drop] or ultimately by returningFalsefrom 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
Trueand 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:
- Parameters:
drop_target_async (
Gtk.DropTargetAsync) – The object which received the signaldrop (
Gdk.Drop) – theGdkDropx (
float) – the x coordinate of the current pointer positiony (
float) – the y coordinate of the current pointer position
- Returns:
Preferred action for this drag operation.
- Return type:
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:
- Parameters:
drop_target_async (
Gtk.DropTargetAsync) – The object which received the signaldrop (
Gdk.Drop) – theGdkDrop
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:
- Parameters:
drop_target_async (
Gtk.DropTargetAsync) – The object which received the signaldrop (
Gdk.Drop) – theGdkDropx (
float) – the x coordinate of the current pointer positiony (
float) – the y coordinate of the current pointer position
- Returns:
Preferred action for this drag operation.
- Return type:
Emitted while the pointer is moving over the drop target.
- Gtk.DropTargetAsync.signals.drop(drop_target_async, drop, x, y)¶
- Signal Name:
drop- Flags:
- Parameters:
drop_target_async (
Gtk.DropTargetAsync) – The object which received the signaldrop (
Gdk.Drop) – theGdkDropx (
float) – the x coordinate of the current pointer positiony (
float) – the y coordinate of the current pointer position
- Returns:
whether the drop is accepted at the given pointer position
- Return type:
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
Falseand 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:
- Default Value:
0- Flags:
The
GdkDragActionsthat this drop target supports.
- Gtk.DropTargetAsync.props.formats¶
- Name:
formats- Type:
- Default Value:
- Flags:
The
GdkContentFormatsthat determines the supported data formats.