-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupButtonDetection.py
More file actions
49 lines (42 loc) · 1.84 KB
/
backupButtonDetection.py
File metadata and controls
49 lines (42 loc) · 1.84 KB
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
import pyautogui
import logging
import time
import constants
import os
def getLocalScreenshotArea(backupButtonDetectionData):
localScreenshotArea = constants.BUTTON_DETECTION_SCREENSHOT_AREA
differenceInHeight = backupButtonDetectionData.offsetY - localScreenshotArea[1]
localScreenshotArea = list(localScreenshotArea)
localScreenshotArea[1] = backupButtonDetectionData.offsetY
localScreenshotArea[3] -= differenceInHeight
localScreenshotArea = tuple(localScreenshotArea)
return localScreenshotArea
def shiftScreenshot(backupButtonDetectionData):
backupButtonDetectionData.offsetY += 30
def getButtonCoord(backupButtonDetectionData):
topButton = pyautogui.locate('bubble.png', constants.BUTTON_DETECTION_SCREENSHOT_NAME)
logging.info("Got location at "+str(pyautogui.center(topButton)))
return pyautogui.center(topButton)
def hasButton(backupButtonDetectionData) -> bool:
if not backupButtonDetectionData.active:
return False
else:
localScreenshotArea = getLocalScreenshotArea(backupButtonDetectionData)
try:
os.remove(constants.BUTTON_DETECTION_SCREENSHOT_NAME)
except Exception:
pass
pyautogui.screenshot(constants.BUTTON_DETECTION_SCREENSHOT_NAME, region=localScreenshotArea)
topButton = pyautogui.locate('bubble.png', constants.BUTTON_DETECTION_SCREENSHOT_NAME)
if topButton:
logging.info("Backup button detection: found button")
return True
else:
return False
def clickButton(backupButtonDetectionData):
topButton = pyautogui.locate('bubble.png', constants.BUTTON_DETECTION_SCREENSHOT_NAME)
centered = pyautogui.center(topButton)
y = centered.y + backupButtonDetectionData.offsetY
x = centered.x + backupButtonDetectionData.offsetX
pyautogui.moveTo(x, y)
pyautogui.click()