Gesture
Superclasses: EventController
, Object
Subclasses: GestureRotate
, GestureSingle
, GestureZoom
- Constructors:
Gesture(**properties)
Methods
- class Gesture
- get_bounding_box() tuple[bool, Rectangle]
If there are touch sequences being currently handled by
gesture
, returnsTrue
and fills inrect
with the bounding box containing all active touches.Otherwise,
False
will be returned.Note: This function will yield unexpected results on touchpad gestures. Since there is no correlation between physical and pixel distances, these will look as if constrained in an infinitely small area,
rect
width and height will thus be 0 regardless of the number of touchpoints.
- get_bounding_box_center() tuple[bool, float, float]
If there are touch sequences being currently handled by
gesture
, returnsTrue
and fills inx
andy
with the center of the bounding box containing all active touches.Otherwise,
False
will be returned.
- get_device() Device | None
Returns the logical
GdkDevice
that is currently operating ongesture
.This returns
None
if the gesture is not being interacted.
- get_last_event(sequence: EventSequence | None = None) Event | None
Returns the last event that was processed for
sequence
.Note that the returned pointer is only valid as long as the
sequence
is still interpreted by thegesture
. If in doubt, you should make a copy of the event.- Parameters:
sequence – a
GdkEventSequence
- get_last_updated_sequence() EventSequence | None
Returns the
GdkEventSequence
that was last updated ongesture
.
- get_point(sequence: EventSequence | None = None) tuple[bool, float, float]
If
sequence
is currently being interpreted bygesture
, returnsTrue
and fills inx
andy
with the last coordinates stored for that event sequence.The coordinates are always relative to the widget allocation.
- Parameters:
sequence – a
GdkEventSequence
, orNone
for pointer events
- get_sequence_state(sequence: EventSequence) EventSequenceState
Returns the
sequence
state, as seen bygesture
.- Parameters:
sequence – a
GdkEventSequence
- get_sequences() list[EventSequence]
Returns the list of
GdkEventSequences
currently being interpreted bygesture
.
- group(gesture: Gesture) None
Adds
gesture
to the same group thangroup_gesture
.Gestures are by default isolated in their own groups.
Both gestures must have been added to the same widget before they can be grouped.
When gestures are grouped, the state of
GdkEventSequences
is kept in sync for all of those, so callingset_sequence_state
, on one will transfer the same value to the others.Groups also perform an “implicit grabbing” of sequences, if a
GdkEventSequence
state is set toCLAIMED
on one group, every other gesture group attached to the sameGtkWidget
will switch the state for that sequence toDENIED
.- Parameters:
gesture – a
GtkGesture
- handles_sequence(sequence: EventSequence | None = None) bool
Returns
True
ifgesture
is currently handling events corresponding tosequence
.- Parameters:
sequence – a
GdkEventSequence
- is_active() bool
Returns
True
if the gesture is currently active.A gesture is active while there are touch sequences interacting with it.
- is_grouped_with(other: Gesture) bool
Returns
True
if both gestures pertain to the same group.- Parameters:
other – another
GtkGesture
- is_recognized() bool
Returns
True
if the gesture is currently recognized.A gesture is recognized if there are as many interacting touch sequences as required by
gesture
.
- set_sequence_state(sequence: EventSequence, state: EventSequenceState) bool
Sets the state of
sequence
ingesture
.Sequences start in state
NONE
, and whenever they change state, they can never go back to that state. Likewise, sequences in stateDENIED
cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:None
None → Denied
None → Claimed
None → Claimed → Denied
Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a
begin
signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:static void first_gesture_begin_cb (GtkGesture *first_gesture, GdkEventSequence *sequence, gpointer user_data) { gtk_gesture_set_sequence_state (first_gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED); gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED); } static void second_gesture_begin_cb (GtkGesture *second_gesture, GdkEventSequence *sequence, gpointer user_data) { if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED) gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED); }
If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group’s global state when the second gesture processes the event.
Deprecated since version 4.10.: Use
set_state
- Parameters:
sequence – a
GdkEventSequence
state – the sequence state
- set_state(state: EventSequenceState) bool
Sets the state of all sequences that
gesture
is currently interacting with.Sequences start in state
NONE
, and whenever they change state, they can never go back to that state. Likewise, sequences in stateDENIED
cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:None
None → Denied
None → Claimed
None → Claimed → Denied
Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a
begin
signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:static void first_gesture_begin_cb (GtkGesture *first_gesture, GdkEventSequence *sequence, gpointer user_data) { gtk_gesture_set_state (first_gesture, GTK_EVENT_SEQUENCE_CLAIMED); gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED); } static void second_gesture_begin_cb (GtkGesture *second_gesture, GdkEventSequence *sequence, gpointer user_data) { if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED) gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED); }
If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group’s global state when the second gesture processes the event.
- Parameters:
state – the sequence state
Properties
Signals
- class Gesture.signals
- begin(sequence: EventSequence | None = None) None
Emitted when the gesture is recognized.
This means the number of touch sequences matches
n_points
.Note: These conditions may also happen when an extra touch (eg. a third touch on a 2-touches gesture) is lifted, in that situation
sequence
won’t pertain to the current set of active touches, so don’t rely on this being true.- Parameters:
sequence – the
GdkEventSequence
that made the gesture to be recognized
- cancel(sequence: EventSequence | None = None) None
Emitted whenever a sequence is cancelled.
This usually happens on active touches when
reset
is called ongesture
(manually, due to grabs…), or the individualsequence
was claimed by parent widgets’ controllers (seeset_sequence_state
).gesture
must forget everything aboutsequence
as in response to this signal.- Parameters:
sequence – the
GdkEventSequence
that was cancelled
- end(sequence: EventSequence | None = None) None
Emitted when
gesture
either stopped recognizing the event sequences as something to be handled, or the number of touch sequences became higher or lower thann_points
.Note:
sequence
might not pertain to the group of sequences that were previously triggering recognition ongesture
(ie. a just pressed touch sequence that exceedsn_points
). This situation may be detected by checking throughhandles_sequence
.- Parameters:
sequence – the
GdkEventSequence
that made gesture recognition to finish
- sequence_state_changed(sequence: EventSequence | None, state: EventSequenceState) None
Emitted whenever a sequence state changes.
See
set_sequence_state
to know more about the expectable sequence lifetimes.- Parameters:
sequence – the
GdkEventSequence
that was cancelledstate – the new sequence state
- update(sequence: EventSequence | None = None) None
Emitted whenever an event is handled while the gesture is recognized.
sequence
is guaranteed to pertain to the set of active touches.- Parameters:
sequence – the
GdkEventSequence
that was updated