12
12
13
13
class _RecognizeImages (object ):
14
14
15
+ dflt_timeout = 0
15
16
pixel_ratio = 0.0
16
17
17
18
def __get_pixel_ratio (self ):
@@ -33,13 +34,15 @@ def __normalize(self, path):
33
34
raise InvalidImageException ('Image path not found: "%s".' % path )
34
35
return path
35
36
36
- def click_image (self , reference_image ):
37
- '''Finds the reference image on screen and clicks it once.
37
+ def click_image (self , reference_image , timeout = dflt_timeout ):
38
+ '''Finds the reference image on screen and clicks it's center point once.
38
39
39
40
``reference_image`` is automatically normalized as described in the
40
41
`Reference image names`.
42
+
43
+ ``timeout`` optional value, in whole seconds. default is 0
41
44
'''
42
- center_location = self .locate (reference_image )
45
+ center_location = self .wait_for (reference_image , timeout )
43
46
LOGGER .info ('Clicking image "%s" in position %s' % (reference_image ,
44
47
center_location ))
45
48
ag .click (center_location )
@@ -50,13 +53,13 @@ def _click_to_the_direction_of(self, direction, location, offset,
50
53
raise NotImplementedError ('This is defined in the main class.' )
51
54
52
55
def _locate_and_click_direction (self , direction , reference_image , offset ,
53
- clicks , button , interval ):
54
- location = self .locate (reference_image )
56
+ clicks , button , interval , timeout = dflt_timeout ):
57
+ location = self .wait_for (reference_image , timeout )
55
58
self ._click_to_the_direction_of (direction , location , offset , clicks ,
56
59
button , interval )
57
60
58
61
def click_to_the_above_of_image (self , reference_image , offset , clicks = 1 ,
59
- button = 'left' , interval = 0.0 ):
62
+ button = 'left' , interval = 0.0 , timeout = dflt_timeout ):
60
63
'''Clicks above of reference image by given offset.
61
64
62
65
See `Reference image names` for documentation for ``reference_image``.
@@ -65,38 +68,40 @@ def click_to_the_above_of_image(self, reference_image, offset, clicks=1,
65
68
image.
66
69
67
70
``clicks`` and ``button`` are documented in `Click To The Above Of`.
71
+
72
+ ``timeout`` optional value, in whole seconds. default is 0
68
73
'''
69
74
self ._locate_and_click_direction ('up' , reference_image , offset ,
70
- clicks , button , interval )
75
+ clicks , button , interval , timeout )
71
76
72
77
def click_to_the_below_of_image (self , reference_image , offset , clicks = 1 ,
73
- button = 'left' , interval = 0.0 ):
78
+ button = 'left' , interval = 0.0 , timeout = dflt_timeout ):
74
79
'''Clicks below of reference image by given offset.
75
80
76
81
See argument documentation in `Click To The Above Of Image`.
77
82
'''
78
83
self ._locate_and_click_direction ('down' , reference_image , offset ,
79
- clicks , button , interval )
84
+ clicks , button , interval , timeout )
80
85
81
86
def click_to_the_left_of_image (self , reference_image , offset , clicks = 1 ,
82
- button = 'left' , interval = 0.0 ):
87
+ button = 'left' , interval = 0.0 , timeout = dflt_timeout ):
83
88
'''Clicks left of reference image by given offset.
84
89
85
90
See argument documentation in `Click To The Above Of Image`.
86
91
'''
87
92
self ._locate_and_click_direction ('left' , reference_image , offset ,
88
- clicks , button , interval )
93
+ clicks , button , interval , timeout )
89
94
90
95
def click_to_the_right_of_image (self , reference_image , offset , clicks = 1 ,
91
- button = 'left' , interval = 0.0 ):
96
+ button = 'left' , interval = 0.0 , timeout = dflt_timeout ):
92
97
'''Clicks right of reference image by given offset.
93
98
94
99
See argument documentation in `Click To The Above Of Image`.
95
100
'''
96
101
self ._locate_and_click_direction ('right' , reference_image , offset ,
97
- clicks , button , interval )
102
+ clicks , button , interval , timeout )
98
103
99
- def copy_from_the_above_of (self , reference_image , offset ):
104
+ def copy_from_the_above_of (self , reference_image , offset , timeout = dflt_timeout ):
100
105
'''Clicks three times above of reference image by given offset and
101
106
copies.
102
107
@@ -106,39 +111,41 @@ def copy_from_the_above_of(self, reference_image, offset):
106
111
107
112
Copy is done by pressing ``Ctrl+C`` on Windows and Linux and ``⌘+C``
108
113
on OS X.
114
+
115
+ ``timeout`` optional value, in whole seconds. default is 0
109
116
'''
110
117
self ._locate_and_click_direction ('up' , reference_image , offset ,
111
- clicks = 3 , button = 'left' , interval = 0.0 )
118
+ clicks = 3 , button = 'left' , interval = 0.0 , timeout = timeout )
112
119
return self .copy ()
113
120
114
- def copy_from_the_below_of (self , reference_image , offset ):
121
+ def copy_from_the_below_of (self , reference_image , offset , timeout = dflt_timeout ):
115
122
'''Clicks three times below of reference image by given offset and
116
123
copies.
117
124
118
125
See argument documentation in `Copy From The Above Of`.
119
126
'''
120
127
self ._locate_and_click_direction ('down' , reference_image , offset ,
121
- clicks = 3 , button = 'left' , interval = 0.0 )
128
+ clicks = 3 , button = 'left' , interval = 0.0 , timeout = timeout )
122
129
return self .copy ()
123
130
124
- def copy_from_the_left_of (self , reference_image , offset ):
131
+ def copy_from_the_left_of (self , reference_image , offset , timeout = dflt_timeout ):
125
132
'''Clicks three times left of reference image by given offset and
126
133
copies.
127
134
128
135
See argument documentation in `Copy From The Above Of`.
129
136
'''
130
137
self ._locate_and_click_direction ('left' , reference_image , offset ,
131
- clicks = 3 , button = 'left' , interval = 0.0 )
138
+ clicks = 3 , button = 'left' , interval = 0.0 , timeout = timeout )
132
139
return self .copy ()
133
140
134
- def copy_from_the_right_of (self , reference_image , offset ):
141
+ def copy_from_the_right_of (self , reference_image , offset , timeout = dflt_timeout ):
135
142
'''Clicks three times right of reference image by given offset and
136
143
copies.
137
144
138
145
See argument documentation in `Copy From The Above Of`.
139
146
'''
140
147
self ._locate_and_click_direction ('right' , reference_image , offset ,
141
- clicks = 3 , button = 'left' , interval = 0.0 )
148
+ clicks = 3 , button = 'left' , interval = 0.0 , timeout = timeout )
142
149
return self .copy ()
143
150
144
151
@contextmanager
@@ -244,7 +251,7 @@ def wait_for(self, reference_image, timeout=10):
244
251
245
252
See `Reference image names` for documentation for ``reference_image``.
246
253
247
- ``timeout`` is given in seconds.
254
+ ``timeout`` is given in whole seconds.
248
255
249
256
Returns Python tuple ``(x, y)`` of the coordinates.
250
257
'''
0 commit comments