-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (55 loc) · 2.19 KB
/
Copy pathmain.py
File metadata and controls
71 lines (55 loc) · 2.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os, sys, multiprocessing
from ui import mk_config_dir, get_config_dir, get_local_dir, MainWindow
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QMenu
from PyQt6.QtGui import QAction, QIcon
from PyQt6.QtCore import QCoreApplication
from handler import handler
mk_config_dir()
def log(*args):
print(" ".join([str(x) for x in list(args)]),"\n")
with open(os.path.join(get_config_dir(),"latest.log"),"a") as f:
f.write("\n")
for x in list(args):
f.write(" "+str(x))
CDIR = os.path.abspath("./") if not hasattr(sys,"_MEIPASS") else sys._MEIPASS
log(f"CDIR={CDIR}")
if __name__ == "__main__":
multiprocessing.freeze_support()
if os.path.exists(os.path.join(CDIR,"__LOCK__")):
os.remove(os.path.join(CDIR,"__LOCK__"))
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
# tray = QSystemTrayIcon(QIcon(os.path.join(CDIR,"icons","PyCutsTrayIcon.png" if sys.platform != "darwin" else "PyCutsTrayIconMono.png")),parent=app)
tray_icon = QIcon(os.path.join(CDIR,"icons","PyCutsTrayIconMono.png") if sys.platform == "darwin" else os.path.join(get_local_dir(),"icon.png"))
tray = QSystemTrayIcon(tray_icon,parent=app)
tray.setToolTip("PyCuts")
def close():
with open(os.path.join(CDIR,"__BREAK__"),"w") as f:
f.write("")
tray.hide()
QCoreApplication.quit()
tray_menu = QMenu()
win = None
def run():
global win
if not win: win = MainWindow()
win.show()
win.raise_()
win.activateWindow()
open_ui = QAction("Open UI")
open_ui.triggered.connect(run)
tray_menu.addAction(open_ui)
exit_act = QAction("Exit" if sys.platform != "darwin" else "Quit PyCuts")
exit_act.triggered.connect(close)
tray_menu.addAction(exit_act)
tray.setContextMenu(tray_menu)
tray.show()
process = multiprocessing.Process(target=handler)
process.start()
app.exec()
log("Exitting main...")
process.join()
if os.path.exists(os.path.join(CDIR,"__LOCK__")):
os.remove(os.path.join(CDIR,"__LOCK__"))
if os.path.exists(os.path.join(CDIR,"__BREAK__")):
os.remove(os.path.join(CDIR,"__BREAK__"))