-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (38 loc) · 1.15 KB
/
main.py
File metadata and controls
48 lines (38 loc) · 1.15 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
# main.py
import logging
import sys
import threading
import tkinter as tk
import traceback
from src.HkMgr import HotkeyManager
from src.GUI import MainGUI
from src.MCtrl import MainController
def main():
hkmgr = HotkeyManager()
root = tk.Tk()
gui = MainGUI(root=root, hkmgr=hkmgr, level=log_level)
root.protocol("WM_DELETE_WINDOW", gui.on_closing)
try:
mctrl = MainController(hkmgr=hkmgr)
except Exception:
traceback.print_exc()
sys.exit(1)
thread_hkmgr = threading.Thread(target=hkmgr.start_listener, daemon=True)
thread_hkmgr.start()
logging.getLogger(__name__).info("App started.")
thread_mctrl = threading.Thread(target=mctrl.run, daemon=True)
thread_mctrl.start()
try:
root.mainloop()
except KeyboardInterrupt:
logging.getLogger(__name__).info("App stopped.")
hkmgr.script_exit()
sys.exit(0)
finally:
if thread_hkmgr.is_alive():
thread_hkmgr.join(timeout=0)
if thread_mctrl.is_alive():
thread_mctrl.join(timeout=0)
if __name__ == "__main__":
log_level = "DEBUG" if len(sys.argv) > 1 else "INFO"
main()