-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
125 lines (110 loc) · 3.56 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from multiprocessing import Process
import PySimpleGUI as sg
from PIL import Image
from src.config import edit_config, load_config
from src.core import load_sources, process
from src.utils import (
RectangleSelection,
get_all_classes_specs,
get_key_mapping,
take_screenshot,
update_key,
)
def set_process_state(is_running, window):
window.Element("F3").Update(
("PAUSED", "RUNNING")[is_running],
button_color=(("white", ("red", "green")[is_running])),
)
return is_running
def make_layout(config):
class_spec = config["Class"]
spells_key = get_key_mapping()[class_spec]
col1 = [[sg.Text(f"{s}", key=f"ability_{s}")] for s in spells_key]
col2 = [
[sg.Input(f"{spells_key[s]}", key=f"{s}", enable_events=True)]
for s in spells_key
]
layout = [
[
[sg.Text("AUTO Hekili")],
[
sg.Combo(
get_all_classes_specs(),
default_value=class_spec,
enable_events=True,
key="Class",
readonly=True,
)
],
[sg.Button("Set Hekili spellbox square", key="-POS-")],
[sg.Button("Run", key="F3")],
[
sg.Col(col1, k="-SPELL NAMES-"),
sg.Col(col2, k="-BINDING-"),
],
]
]
return layout
def make_window(config):
window = sg.Window("Auto Hekili", make_layout(config), finalize=True, location=config["location"])
window.bind("<Key-F3>", "F3")
return window
def main_gui():
config = load_config()
# Create the window
window = make_window(config)
down_f3 = False
p = None
# Create an event loop
while True:
event, values = window.read()
class_spec = values["Class"]
print(class_spec)
spells_key = get_key_mapping()[class_spec]
imgs_src, file_names = load_sources(class_spec)
spell_names = [f.split(".jpg")[0] for f in file_names]
mapping = get_key_mapping()
print(f"Event is : {event}")
if event in spells_key.keys():
print(values[event])
mapping = update_key(class_spec, mapping, event, values[event])
if event == "Exit" or event == sg.WIN_CLOSED:
break
if event == "-POS-":
if p:
p.terminate()
down_f3 = set_process_state(False, window)
img = Image.fromarray(take_screenshot(True))
selector = RectangleSelection(img)
while not selector.done:
pass
selector.close()
edit_config("spellbox_rectangle", selector.rectangle, config)
if event == "F3":
down_f3 = set_process_state(not down_f3, window)
if event == "Class":
win_posX, win_posY = window.CurrentLocation()
edit_config("location", (win_posX, win_posY), config)
window.close()
edit_config("Class", values["Class"], config)
window = make_window(config)
if down_f3:
print("Starting process")
print(config["spellbox_rectangle"])
p = Process(
target=process,
args=(
1,
imgs_src,
spell_names,
spells_key,
config["spellbox_rectangle"],
),
)
p.start()
else:
if p:
p.terminate()
window.close()
if __name__ == "__main__":
main_gui()