-
Notifications
You must be signed in to change notification settings - Fork 0
/
routine.py
49 lines (36 loc) · 1.37 KB
/
routine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pyautogui
class Routine:
_command_retries_ = 3
def execute(self) -> int:
pass
def _clickOn_(self, path, confidence = 0.9):
location = self._disablePauseFor_(
lambda: pyautogui.locateCenterOnScreen(path, confidence = confidence)
)
if (location != None):
pyautogui.click(location)
return location
def _disablePauseFor_(self, fun) -> any:
tmp = pyautogui.PAUSE
pyautogui.PAUSE = 0
val = fun()
pyautogui.PAUSE = tmp
return val
def _locateClickWhileTesting_(self, path, confidence, name):
location = self._disablePauseFor_(
lambda: pyautogui.locateCenterOnScreen(path, confidence=confidence)
)
if (location == None):
raise RoutineException("Could not find the " + name)
tmp = pyautogui.PAUSE
for i in range(Routine._command_retries_):
pyautogui.click(location)
_location = self._disablePauseFor_(
lambda: pyautogui.locateCenterOnScreen(path, confidence=confidence)
)
if(_location == None):
break
elif(i == Routine._command_retries_ - 1):
raise RoutineException("Could not click the " + name)
class RoutineException(Exception):
pass