-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcengrum.pyw
More file actions
84 lines (61 loc) · 1.97 KB
/
cengrum.pyw
File metadata and controls
84 lines (61 loc) · 1.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
import subprocess
import os
import sys
import pystray
import json
import PIL
import PIL.Image
import pyautogui as pag
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW("Cengrum")
def restart_program_fromSysTray(icon, item):
icon.stop()
os.execl(sys.executable, sys.executable, *sys.argv)
def quit_program_fromSysTray(icon, item):
icon.stop()
os._exit(0)
iconpath = "favicon.ico"
im = PIL.Image.open(iconpath)
def run_program_in_new_window(icon, filepath):
def real_run_program_in_new_window_func(icon):
try:
subprocess.Popen([filepath], shell=True, cwd = os.path.dirname(filepath))
except Exception as e:
print(e)
if type(e).__name__ == "FileNotFoundError":
pag.alert(text = f"{filepath} not found.", title = "Cengrum")
else:
pag.alert(text = e, title = "Cengrum - Error")
return real_run_program_in_new_window_func
def update_paths():
if not os.path.isfile("paths.json"):
f = open("paths.json",'w')
f.write('{\n\n\n}')
f = open("paths.json",'r')
filepaths = json.loads(f.read())
return filepaths
def build_submenu(filepaths):
menu = tuple()
for program_name in list(filepaths.keys()):
menu = pystray.Menu(*menu, pystray.MenuItem(program_name, run_program_in_new_window(iconpath, filepaths[program_name])))
return menu
filepaths_dict = update_paths()
submenu = build_submenu(filepaths_dict)
print(submenu)
def open_pathsjsonfile():
subprocess.check_output(["notepad.exe", "paths.json"])
restart_program_fromSysTray(icon, None)
icon_menu = pystray.Menu(
pystray.MenuItem(
'Run programs',
submenu),
pystray.MenuItem(
'Add programs',
open_pathsjsonfile),
pystray.MenuItem('Restart',
restart_program_fromSysTray),
pystray.MenuItem(
'Quit',
quit_program_fromSysTray))
icon = pystray.Icon("cengrum-icon",im,"Cengrum", menu=icon_menu)
icon.run()