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