# Copyright (C) 2007-2013 various contributors (see AUTHORS)
#
# This file is part of Python-EFL.
#
# Python-EFL is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# Python-EFL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this Python-EFL. If not, see .
#
"""
.. image:: /images/gesturelayer-preview.png
Widget description
------------------
Use the GestureLayer to detect gestures. The advantage is that you don't
have to implement gesture detection, just set callbacks for gesture states.
In order to use Gesture Layer you start with instantiating this class
with a parent object parameter. Next 'activate' gesture layer with a
:py:meth:`GestureLayer.attach` call. Usually with same object as target (2nd
parameter).
Now you need to tell gesture layer what gestures you follow. This is done with
:py:meth:`GestureLayer.cb_set` call. By setting the callback you actually saying
to gesture layer: I would like to know when the gesture ``Elm_Gesture_Type``
switches to state ``Elm_Gesture_State``.
Next, you need to implement the actual action that follows the input in
your callback.
Note that if you like to stop being reported about a gesture, just set
all callbacks referring this gesture to None. (again with
:py:meth:`GestureLayer.cb_set`)
The information reported by gesture layer to your callback is depending
on ``Elm_Gesture_Type``:
- ``Elm_Gesture_Taps_Info`` is the info reported for tap gestures:
- ``ELM_GESTURE_N_TAPS``
- ``ELM_GESTURE_N_LONG_TAPS``
- ``ELM_GESTURE_N_DOUBLE_TAPS``
- ``ELM_GESTURE_N_TRIPLE_TAPS``
- ``Elm_Gesture_Momentum_Info`` is info reported for momentum gestures:
- ``ELM_GESTURE_MOMENTUM``
- ``Elm_Gesture_Line_Info`` is the info reported for line gestures
(this also contains ``Elm_Gesture_Momentum_Info`` internal structure):
- ``ELM_GESTURE_N_LINES``
- ``ELM_GESTURE_N_FLICKS``
Note that we consider a flick as a line-gesture that should be completed
in flick-time-limit as defined in
:py:class:`~efl.elementary.configuration.Configuration`.
``Elm_Gesture_Zoom_Info`` is the info reported for ``ELM_GESTURE_ZOOM``
gesture.
``Elm_Gesture_Rotate_Info`` is the info reported for
``ELM_GESTURE_ROTATE`` gesture.
Gesture Layer Tweaks:
Note that line, flick, gestures can start without the need to remove
fingers from surface. When user fingers rests on same-spot gesture is
ended and starts again when fingers moved.
Setting glayer_continues_enable to false in
:py:class:`~efl.elementary.configuration.Configuration` will change this
behavior so gesture starts when user touches (a *DOWN* event)
touch-surface and ends when no fingers touches surface (a *UP* event).
Enumerations
------------
.. _Elm_Gesture_State:
Gesture states
==============
.. data:: ELM_GESTURE_STATE_UNDEFINED
Gesture not started
.. data:: ELM_GESTURE_STATE_START
Gesture started
.. data:: ELM_GESTURE_STATE_MOVE
Gesture is ongoing
.. data:: ELM_GESTURE_STATE_END
Gesture completed
.. data:: ELM_GESTURE_STATE_ABORT
Ongoing gesture was aborted
.. _Elm_Gesture_Type:
Gesture types
=============
.. data:: ELM_GESTURE_N_TAPS
N fingers single taps
.. data:: ELM_GESTURE_N_LONG_TAPS
N fingers single long-taps
.. data:: ELM_GESTURE_N_DOUBLE_TAPS
N fingers double-single taps
.. data:: ELM_GESTURE_N_TRIPLE_TAPS
N fingers triple-single taps
.. data:: ELM_GESTURE_MOMENTUM
Reports momentum in the direction of move
.. data:: ELM_GESTURE_N_LINES
N fingers line gesture
.. data:: ELM_GESTURE_N_FLICKS
N fingers flick gesture
.. data:: ELM_GESTURE_ZOOM
Zoom
.. data:: ELM_GESTURE_ROTATE
Rotate
"""
from cpython cimport PyUnicode_AsUTF8String, Py_INCREF
from efl.eo cimport _object_mapping_register
from efl.utils.conversions cimport _ctouni
from efl.evas cimport Object as evasObject
from object cimport Object
import traceback
from efl.evas import EVAS_EVENT_FLAG_NONE
cimport enums
ELM_GESTURE_STATE_UNDEFINED = enums.ELM_GESTURE_STATE_UNDEFINED
ELM_GESTURE_STATE_START = enums.ELM_GESTURE_STATE_START
ELM_GESTURE_STATE_MOVE = enums.ELM_GESTURE_STATE_MOVE
ELM_GESTURE_STATE_END = enums.ELM_GESTURE_STATE_END
ELM_GESTURE_STATE_ABORT = enums.ELM_GESTURE_STATE_ABORT
ELM_GESTURE_FIRST = enums.ELM_GESTURE_FIRST
ELM_GESTURE_N_TAPS = enums.ELM_GESTURE_N_TAPS
ELM_GESTURE_N_LONG_TAPS = enums.ELM_GESTURE_N_LONG_TAPS
ELM_GESTURE_N_DOUBLE_TAPS = enums.ELM_GESTURE_N_DOUBLE_TAPS
ELM_GESTURE_N_TRIPLE_TAPS = enums.ELM_GESTURE_N_TRIPLE_TAPS
ELM_GESTURE_MOMENTUM = enums.ELM_GESTURE_MOMENTUM
ELM_GESTURE_N_LINES = enums.ELM_GESTURE_N_LINES
ELM_GESTURE_N_FLICKS = enums.ELM_GESTURE_N_FLICKS
ELM_GESTURE_ZOOM = enums.ELM_GESTURE_ZOOM
ELM_GESTURE_ROTATE = enums.ELM_GESTURE_ROTATE
ELM_GESTURE_LAST = enums.ELM_GESTURE_LAST
cdef class GestureTapsInfo(object):
"""Holds taps info for user"""
cdef Elm_Gesture_Taps_Info *info
property x:
"""Holds center point between fingers
:type: int
"""
def __get__(self):
return self.info.x
property y:
"""Holds center point between fingers
:type: int
"""
def __get__(self):
return self.info.y
property n:
"""Number of fingers tapped
:type: int
"""
def __get__(self):
return self.info.n
property timestamp:
"""Event timestamp
:type: int
"""
def __get__(self):
return self.info.timestamp
cdef class GestureMomentumInfo(object):
"""
Holds momentum info for user
x1 and y1 are not necessarily in sync
x1 holds x value of x direction starting point
and same holds for y1.
This is noticeable when doing V-shape movement
"""
cdef Elm_Gesture_Momentum_Info *info
property x1:
"""Final-swipe direction starting point on X
:type: int
"""
def __get__(self):
return self.info.x1
property y1:
"""Final-swipe direction starting point on Y
:type: int
"""
def __get__(self):
return self.info.y1
property x2:
"""Final-swipe direction ending point on X
:type: int
"""
def __get__(self):
return self.info.x2
property y2:
"""Final-swipe direction ending point on Y
:type: int
"""
def __get__(self):
return self.info.y2
property tx:
"""Timestamp of start of final x-swipe
:type: int
"""
def __get__(self):
return self.info.tx
property ty:
"""Timestamp of start of final y-swipe
:type: int
"""
def __get__(self):
return self.info.ty
property mx:
"""Momentum on X
:type: int
"""
def __get__(self):
return self.info.mx
property my:
"""Momentum on Y
:type: int
"""
def __get__(self):
return self.info.my
property n:
"""Number of fingers
:type: int
"""
def __get__(self):
return self.info.n
cdef class GestureLineInfo(object):
"""Holds line info for user"""
cdef Elm_Gesture_Line_Info *info
property momentum:
"""Line momentum info
:type: GestureMomentumInfo
"""
def __get__(self):
cdef GestureMomentumInfo ret = GestureMomentumInfo.__new__(GestureMomentumInfo)
ret.info = &self.info.momentum
return ret
property angle:
"""Angle (direction) of lines
:type: double
"""
def __get__(self):
return self.info.angle
cdef class GestureZoomInfo(object):
"""Holds zoom info for user"""
cdef Elm_Gesture_Zoom_Info *info
property x:
"""Holds zoom center point reported to user
:type: int
"""
def __get__(self):
return self.info.x
property y:
"""Holds zoom center point reported to user
:type: int
"""
def __get__(self):
return self.info.y
property radius:
"""Holds radius between fingers reported to user
:type: int
"""
def __get__(self):
return self.info.radius
property zoom:
"""Zoom value: 1.0 means no zoom
:type: double
"""
def __get__(self):
return self.info.zoom
property momentum:
"""Zoom momentum: zoom growth per second (NOT YET SUPPORTED)
:type: double
"""
def __get__(self):
return self.info.momentum
cdef class GestureRotateInfo(object):
"""Holds rotation info for user"""
cdef Elm_Gesture_Rotate_Info *info
property x:
"""Holds zoom center point reported to user
:type: int
"""
def __get__(self):
return self.info.x
property y:
"""Holds zoom center point reported to user
:type: int
"""
def __get__(self):
return self.info.y
property radius:
"""Holds radius between fingers reported to user
:type: int
"""
def __get__(self):
return self.info.radius
property base_angle:
"""Holds start-angle
:type: double
"""
def __get__(self):
return self.info.base_angle
property angle:
"""Rotation value: 0.0 means no rotation
:type: double
"""
def __get__(self):
return self.info.angle
property momentum:
"""Rotation momentum: rotation done per second (NOT YET SUPPORTED)
:type: double
"""
def __get__(self):
return self.info.momentum
cdef Evas_Event_Flags _gesture_layer_taps_event_cb(void *data, void *event_info) with gil:
callback, args, kwargs =