forked from skai2/EDAutopilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_tray.py
79 lines (66 loc) · 1.78 KB
/
dev_tray.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
from pystray import Icon, MenuItem, Menu
from PIL import Image # big
from dev_autopilot import autopilot, resource_path, get_bindings, clear_input, set_scanner, RELEASE
from src.directinput import *
import threading
import kthread
import keyboard
STATE = 0
def setup(icon):
icon.visible = True
def exit_action():
stop_action()
icon.visible = False
icon.stop()
def start_action():
stop_action()
kthread.KThread(target = autopilot, name = "EDAutopilot").start()
def stop_action():
for thread in threading.enumerate():
if thread.getName() == 'EDAutopilot':
thread.kill()
clear_input(get_bindings())
def set_state(v):
def inner(icon, item):
global STATE
STATE = v
set_scanner(STATE)
return inner
def get_state(v):
def inner(item):
return STATE == v
return inner
def tray():
global icon, thread
icon = None
thread = None
name = 'ED - Autopilot'
icon = Icon(name=name, title=name)
logo = Image.open(resource_path('src/logo.png'))
icon.icon = logo
icon.menu = Menu(
MenuItem(
'Scan Off',
set_state(0),
checked=get_state(0),
radio=True
),
MenuItem(
'Scan on Primary Fire',
set_state(1),
checked=get_state(1),
radio=True
),
MenuItem(
'Scan on Secondary Fire',
set_state(2),
checked=get_state(2),
radio=True
),
MenuItem('Exit', lambda : exit_action())
)
keyboard.add_hotkey('home', start_action)
keyboard.add_hotkey('end', stop_action)
icon.run(setup)
if __name__ == '__main__':
tray()