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
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.
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
19
Let us capture the source and destination images respectively.
23
dragDrop("thumb.png", "slow.png")
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.
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.
40
t = find("alert.png").right().find("thumb.png")
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
51
dragDrop(t, "alert.png")
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.
59
dragDrop(t, [t.x - 200, t.y])
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.