1212
1313class _RecognizeImages (object ):
1414
15+ dflt_timeout = 0
16+
1517 def __normalize (self , path ):
1618 if (not self .reference_folder or
1719 not isinstance (self .reference_folder , str ) or
@@ -28,13 +30,15 @@ def __normalize(self, path):
2830 raise InvalidImageException ('Image path not found: "%s".' % path )
2931 return path
3032
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.
3335
3436 ``reference_image`` is automatically normalized as described in the
3537 `Reference image names`.
38+
39+ ``timeout`` optional value, in whole seconds. default is 0
3640 '''
37- center_location = self .locate (reference_image )
41+ center_location = self .wait_for (reference_image , timeout )
3842 LOGGER .info ('Clicking image "%s" in position %s' % (reference_image ,
3943 center_location ))
4044 ag .click (center_location )
@@ -45,13 +49,13 @@ def _click_to_the_direction_of(self, direction, location, offset,
4549 raise NotImplementedError ('This is defined in the main class.' )
4650
4751 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 )
5054 self ._click_to_the_direction_of (direction , location , offset , clicks ,
5155 button , interval )
5256
5357 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 ):
5559 '''Clicks above of reference image by given offset.
5660
5761 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,
6064 image.
6165
6266 ``clicks`` and ``button`` are documented in `Click To The Above Of`.
67+
68+ ``timeout`` optional value, in whole seconds. default is 0
6369 '''
6470 self ._locate_and_click_direction ('up' , reference_image , offset ,
65- clicks , button , interval )
71+ clicks , button , interval , timeout )
6672
6773 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 ):
6975 '''Clicks below of reference image by given offset.
7076
7177 See argument documentation in `Click To The Above Of Image`.
7278 '''
7379 self ._locate_and_click_direction ('down' , reference_image , offset ,
74- clicks , button , interval )
80+ clicks , button , interval , timeout )
7581
7682 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 ):
7884 '''Clicks left of reference image by given offset.
7985
8086 See argument documentation in `Click To The Above Of Image`.
8187 '''
8288 self ._locate_and_click_direction ('left' , reference_image , offset ,
83- clicks , button , interval )
89+ clicks , button , interval , timeout )
8490
8591 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 ):
8793 '''Clicks right of reference image by given offset.
8894
8995 See argument documentation in `Click To The Above Of Image`.
9096 '''
9197 self ._locate_and_click_direction ('right' , reference_image , offset ,
92- clicks , button , interval )
98+ clicks , button , interval , timeout )
9399
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 ):
95101 '''Clicks three times above of reference image by given offset and
96102 copies.
97103
@@ -101,39 +107,41 @@ def copy_from_the_above_of(self, reference_image, offset):
101107
102108 Copy is done by pressing ``Ctrl+C`` on Windows and Linux and ``⌘+C``
103109 on OS X.
110+
111+ ``timeout`` optional value, in whole seconds. default is 0
104112 '''
105113 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 )
107115 return self .copy ()
108116
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 ):
110118 '''Clicks three times below of reference image by given offset and
111119 copies.
112120
113121 See argument documentation in `Copy From The Above Of`.
114122 '''
115123 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 )
117125 return self .copy ()
118126
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 ):
120128 '''Clicks three times left of reference image by given offset and
121129 copies.
122130
123131 See argument documentation in `Copy From The Above Of`.
124132 '''
125133 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 )
127135 return self .copy ()
128136
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 ):
130138 '''Clicks three times right of reference image by given offset and
131139 copies.
132140
133141 See argument documentation in `Copy From The Above Of`.
134142 '''
135143 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 )
137145 return self .copy ()
138146
139147 @contextmanager
@@ -237,7 +245,7 @@ def wait_for(self, reference_image, timeout=10):
237245
238246 See `Reference image names` for documentation for ``reference_image``.
239247
240- ``timeout`` is given in seconds.
248+ ``timeout`` is given in whole seconds.
241249
242250 Returns Python tuple ``(x, y)`` of the coordinates.
243251 '''
0 commit comments