~ubuntu-branches/ubuntu/saucy/autopilot/saucy-proposed

« back to all changes in this revision

Viewing changes to autopilot/gestures.py

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2013-06-07 13:33:46 UTC
  • mfrom: (57.1.1 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130607133346-42zvbl1h2k1v54ac
Tags: 1.3daily13.06.05-0ubuntu2
autopilot-touch only suggests python-ubuntu-platform-api for now.
It's not in distro and we need that requirement to be fulfilled to
have unity 7, 100 scopes and the touch stack to distro.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Autopilot Functional Test Tool
 
4
# Copyright (C) 2012-2013 Canonical
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
#
 
19
 
 
20
 
 
21
"""Gestural support for autopilot.
 
22
 
 
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!
 
26
 
 
27
"""
 
28
 
 
29
from autopilot.input import Touch
 
30
from time import sleep
 
31
 
 
32
 
 
33
def pinch(center, vector_start, vector_end):
 
34
    """Perform a two finger pinch (zoom) gesture.
 
35
 
 
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.
 
39
 
 
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
 
42
    will zoom out.
 
43
 
 
44
    """
 
45
 
 
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]]
 
50
 
 
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
 
53
 
 
54
    finger_1 = Touch.create()
 
55
    finger_2 = Touch.create()
 
56
 
 
57
    finger_1.press(*finger_1_start)
 
58
    finger_2.press(*finger_2_start)
 
59
 
 
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]
 
62
 
 
63
    for i in range(0, 100):
 
64
        finger_1.move(*finger_1_cur)
 
65
        finger_2.move(*finger_2_cur)
 
66
        sleep(0.005)
 
67
 
 
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]
 
70
 
 
71
    finger_1.move(*finger_1_end)
 
72
    finger_2.move(*finger_2_end)
 
73
    finger_1.release()
 
74
    finger_2.release()