DropTarget
Superclasses: EventController
, Object
- Constructors:
DropTarget(**properties)
new(type:GType, actions:Gdk.DragAction) -> Gtk.DropTarget
Constructors
- class DropTarget
- classmethod new(type: type, actions: DragAction) DropTarget
Creates a new
GtkDropTarget
object.If the drop target should support more than 1 type, pass
Invalid
fortype
and then callset_gtypes
.- Parameters:
type – The supported type or
Invalid
actions – the supported actions
Methods
- class DropTarget
- get_actions() DragAction
Gets the actions that this drop target supports.
- get_current_drop() Drop | None
Gets the currently handled drop operation.
If no drop operation is going on,
None
is returned.Added in version 4.4.
- get_drop() Drop | None
Gets the currently handled drop operation.
If no drop operation is going on,
None
is returned.Deprecated since version 4.4: Use
get_current_drop
instead
- get_formats() ContentFormats | None
Gets the data formats that this drop target accepts.
If the result is
None
, all formats are expected to be supported.
- get_gtypes() list[type] | None
Gets the list of supported
GType
’s that can be dropped on the target.If no types have been set,
NULL
will be returned.
- reject() None
Rejects the ongoing drop operation.
If no drop operation is ongoing, i.e when
current_drop
isNone
, this function does nothing.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: DragAction) None
Sets the actions that this drop target supports.
- Parameters:
actions – the supported actions
Properties
- class DropTarget
- props.actions: DragAction
The
GdkDragActions
that this drop target supports.
- props.formats: ContentFormats
The
GdkContentFormats
that determine the supported data formats.
- props.preload: bool
Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.
Setting this property allows finer grained reaction to an ongoing drop at the cost of loading more data.
The default value for this property is
False
to avoid downloading huge amounts of data by accident.For example, if somebody drags a full document of gigabytes of text from a text editor across a widget with a preloading drop target, this data will be downloaded, even if the data is ultimately dropped elsewhere.
For a lot of data formats, the amount of data is very small (like
%GDK_TYPE_RGBA
), so enabling this property does not hurt at all. And for local-only Drag-and-Drop operations, no data transfer is done, so enabling it there is free.
- props.value: Any
The value for this drop operation.
This is
None
if the data has not been loaded yet or no drop operation is going on.Data may be available before the
drop
signal gets emitted - for example when thepreload
property is set. You can use the ::notify signal to be notified of available data.
Signals
- class DropTarget.signals
- accept(drop: Drop) 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. IfTrue
is returned, the drop is accepted for now but may be rejected later via a call toreject
or ultimately by returningFalse
from adrop
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 depends on the data, this function should return
True
, thepreload
property should be set and the value should be inspected via the ::notify:value signal, callingreject
if required.- Parameters:
drop – the
GdkDrop
- drop(value: Any, x: float, y: float) 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 is responsible for using the givenvalue
and performing the drop operation.- Parameters:
value – the
GValue
being droppedx – the x coordinate of the current pointer position
y – the y coordinate of the current pointer position
- enter(x: float, y: float) DragAction
Emitted on the drop site when the pointer enters the widget.
It can be used to set up custom highlighting.
- Parameters:
x – the x coordinate of the current pointer position
y – the y coordinate of the current pointer position
- leave() None
Emitted on the drop site when the pointer leaves the widget.
Its main purpose it to undo things done in
enter
.
- motion(x: float, y: float) DragAction
Emitted while the pointer is moving over the drop target.
- Parameters:
x – the x coordinate of the current pointer position
y – the y coordinate of the current pointer position