-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcornerUI.py
73 lines (49 loc) · 1.56 KB
/
cornerUI.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
import pystray
import PIL.Image
from PIL import Image
import os
import sys
from threading import Thread
from cornerTriggers import monitor_cursor
running = False
monitor_thread = None
stop_flag = {'isRunning' : False}
def start_monitoring():
global running, stop_flag, monitor_thread
if not running:
stop_flag['isRunning'] = False
running = True
print("Starting cursor monitoring.....")
monitor_thread = Thread(target=run_monitor, daemon=True)
monitor_thread.start()
def stop_monitoring():
global running, stop_flag
stop_flag['isRunning'] = True
running = False
print("Stopping cursor monitoring.....")
def on_clicked(icon, item):
if str(item) == "Start":
start_monitoring()
elif str(item) == "Stop":
stop_monitoring()
elif str(item) == "Exit":
stop_monitoring()
print("Program exiting................")
icon.stop()
def run_monitor():
monitor_cursor(stop_flag)
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
logo_path = resource_path("images/logo.png")
image = Image.open(logo_path)
def run_ui():
print("Program running................")
start_monitoring()
icon = pystray.Icon("QuickCorners", image,title="QuickCorners", menu=pystray.Menu(
pystray.MenuItem("Start", on_clicked),
pystray.MenuItem("Stop", on_clicked),
pystray.MenuItem("Exit", on_clicked)
))
icon.run()