~ubuntu-branches/ubuntu/utopic/sikuli/utopic

« back to all changes in this revision

Viewing changes to docs/source/tutorials/sliders/sliders.rst

  • Committer: Bazaar Package Importer
  • Author(s): Gilles Filippini
  • Date: 2011-04-16 00:23:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110416002353-cn79cto3c03z5jx1
Tags: 1.0~x~rc2-dfsg1-1
* New upstream release:
  + Redesigned user interface for Sikuli-IDE
  + Support for extensions for Sikuli Script

* debian/control, debian/copyright:
  The package is now maintained by the Debian Java maintainers Team

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Working with Sliders
 
2
====================
 
3
 
 
4
In this tutorial, we will learn how to use :py:meth:`dragDrop() <Region.dragDrop>`
 
5
and :ref:`spatial operators <ExtendingaRegion>` by writing a number of scripts to
 
6
manipulate sliders.
 
7
 
 
8
Suppose we wish to lower the speaking rate of the Text to Speech function. We want
 
9
to drag the slider to the slow side in the Speech preferences window shown below. 
 
10
 
 
11
.. image:: speech.png
 
12
 
 
13
The function that can perform the dragging is :py:meth:`dragDrop()
 
14
<Region.dragDrop>`. This function takes two images as arguments. The first image
 
15
describes the source GUI object to drag and the second image describes the
 
16
appearance of the destination location where the GUI object should be dragged to and
 
17
dropped.
 
18
 
 
19
Let us capture the source and destination images respectively.
 
20
 
 
21
.. sikulicode::
 
22
 
 
23
        dragDrop("thumb.png", "slow.png")
 
24
 
 
25
What happen if there are more than two sliders. How can we make sure the right
 
26
slider is dragged? The above example works because the particular window only has
 
27
one slider. How can we deal with cases when there are several instances of similar
 
28
looking GUI components? Let us consider the Sound preferences window shown below. 
 
29
 
 
30
.. image:: sound.png
 
31
 
 
32
Suppose we wish to lower the Alert volume. To make sure Sikuli Script drags the
 
33
right slider, we need a way to tell Sikuli Script to look for the one that is to the
 
34
right of the Alert volume label, not the one next to the Output volume label. Sikuli
 
35
Script provides a set of spatial operators to do exactly this. Here we will apply
 
36
the :py:meth:`right() <Region.right>` operator as follows.
 
37
 
 
38
.. sikulicode::
 
39
 
 
40
        t = find("alert.png").right().find("thumb.png")
 
41
 
 
42
This statement tells Sikuli Script to first find the Alert volume label and then
 
43
find the slider thumb only within the region strictly to the right of the result of
 
44
the first find. The slider thumb found is then stored in the variable t. Now that we
 
45
have identified the desired slider thumb, we can call :py:meth:`dragDrop()
 
46
<Region.dragDrop>` to drag it to the left by giving the image of the Alter volume as
 
47
the target.
 
48
 
 
49
.. sikulicode::
 
50
 
 
51
        dragDrop(t, "alert.png")
 
52
 
 
53
In the above example, we use the image of the Alert volume label to implicitly guide
 
54
the direction of dragging to the left. It is also possible to use relative
 
55
coordinates to explicitly drag to the left, as shown below. 
 
56
 
 
57
.. sikulicode::
 
58
 
 
59
        dragDrop(t, [t.x - 200, t.y])
 
60
 
 
61
Here, the (x,y) coordinates of the slider thumb are accessible as the attributes of
 
62
t. We can thus calculate the position 200 pixels to the left of t and ask Sikuli
 
63
Script to drag the thumb to that position. 
 
64
 
 
65