-
Notifications
You must be signed in to change notification settings - Fork 11
/
Coordinate_Calibration.py
96 lines (79 loc) · 3.02 KB
/
Coordinate_Calibration.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ctypes
import json
import logging
import subprocess
import sys
import time
from tkinter import *
from common import setup_logger, is_window_active
try:
import pyautogui
from PIL import Image, ImageGrab
except ModuleNotFoundError:
print(f'Please execute the following line and run the script again:\n'
f'{sys.executable} -m pip install -U PyAutoGUI')
# Ask the user to install all the necessary packages automatically
if input("Proceed to run the command automatically? [yes/no] ").find("yes") != -1:
subprocess.call(f"{sys.executable} -m pip install -U PyAutoGUI")
exit()
InputField = None
DoneButton = None
ctypes.windll.shcore.SetProcessDpiAwareness(2)
def coordinate_selection():
global InputField, DoneButton
def init_window() -> Tk:
# Initialize the Tk window; Alpha: 0.1, Fullscreen: True
win_ = Tk()
win_.attributes('-alpha', 0.05)
win_.attributes('-fullscreen', True)
win_.attributes("-topmost", True)
return win_
def set_coords(e):
# Triggers when `Left Mouse Button` is pressed on the window
global InputField, DoneButton
if not InputField:
print(f"Clicked Input field on {e.x}x{e.y}")
InputField = (e.x, e.y)
elif not DoneButton:
print(f"Clicked Done Button on {e.x}x{e.y}")
DoneButton = (e.x, e.y)
win.destroy()
input('\n'
' COORDINATE COORDINATION\n'
'Not everyone has the same monitor size. You will be prompted to first click on the "Value" box, '
'and then the two arrows facing away from each-other ↕.\n'
'If you dont do this correctly, the importing script will not work\n'
'You can look on the GitHub page for a video tutorial.\n'
'Press enter to continue.\n'
'> ')
for num in range(2):
if num == 0:
input('Press ENTER, open RecRoom and press on the "Value" box (TOP-LEFT corner).\n'
'(look at the GitHub tutorial for reference).\n'
'> ')
else:
input('Press ENTER, open RecRoom and press the two arrows facing away from each-other ↕.\n'
'(look at the GitHub tutorial for reference).\n'
'> ')
win = init_window()
win.bind('<Button-1>', set_coords)
is_window_active()
time.sleep(0.1)
win.mainloop()
time.sleep(0.1)
print(f"Input button: {InputField}\nDone Button (arrows ↕): {DoneButton}")
with open("coordinates.json", "w") as coords_file:
json.dump({
"InputField": InputField,
"DoneButton": DoneButton
}, coords_file, indent=4)
log: logging.Logger = setup_logger()
if __name__ == '__main__':
try:
coordinate_selection()
exit(input("\n"
"Coordinate calibration done!\n"
"Press ENTER to exit\n"
"> "))
except (Exception, KeyboardInterrupt):
log.exception("ERROR", exc_info=True)