1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Autopilot Functional Test Tool
4
# Copyright (C) 2012-2013 Canonical
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
"""Gestural support for autopilot.
23
This module contains functions that can generate touch and multi-touch gestures
24
for you. This is a convenience for the test author - there is nothing to prevent
25
you from generating your own gestures!
29
from autopilot.input import Touch
30
from time import sleep
33
def pinch(center, vector_start, vector_end):
34
"""Perform a two finger pinch (zoom) gesture.
36
:param center: The coordinates (x,y) of the center of the pinch gesture.
37
:param vector_start: The (x,y) values to move away from the center for the start.
38
:param vector_end: The (x,y) values to move away from the center for the end.
40
The fingers will move in 100 steps between the start and the end points.
41
If start is smaller than end, the gesture will zoom in, otherwise it
46
finger_1_start = [center[0] - vector_start[0], center[1] - vector_start[1]]
47
finger_2_start = [center[0] + vector_start[0], center[1] + vector_start[1]]
48
finger_1_end = [center[0] - vector_end[0], center[1] - vector_end[1]]
49
finger_2_end = [center[0] + vector_end[0], center[1] + vector_end[1]]
51
dx = 1.0 * (finger_1_end[0] - finger_1_start[0]) / 100
52
dy = 1.0 * (finger_1_end[1] - finger_1_start[1]) / 100
54
finger_1 = Touch.create()
55
finger_2 = Touch.create()
57
finger_1.press(*finger_1_start)
58
finger_2.press(*finger_2_start)
60
finger_1_cur = [finger_1_start[0] + dx, finger_1_start[1] + dy]
61
finger_2_cur = [finger_2_start[0] - dx, finger_2_start[1] - dy]
63
for i in range(0, 100):
64
finger_1.move(*finger_1_cur)
65
finger_2.move(*finger_2_cur)
68
finger_1_cur = [finger_1_cur[0] + dx, finger_1_cur[1] + dy]
69
finger_2_cur = [finger_2_cur[0] - dx, finger_2_cur[1] - dy]
71
finger_1.move(*finger_1_end)
72
finger_2.move(*finger_2_end)