-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_launcher.py
More file actions
124 lines (102 loc) · 3.89 KB
/
app_launcher.py
File metadata and controls
124 lines (102 loc) · 3.89 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Imports
import tkinter as tk
import json
import sys
import os
import time
import ctypes
import keyboard
try:
# Get file data
file_custom = "C:\\Folder\\example.json"
file_base = os.path.basename(sys.argv[0])
if (os.path.exists(file_custom)):
file_name = file_custom
elif (os.path.exists(file_base)):
file_name = os.path.splitext(file_base)[0]+".json"
# Open & load JSON
json_file = open(f"{file_name}")
json_data = json.load(json_file)
config = json_data["config"];
executables = json_data["executables"];
# Main window
window = tk.Tk()
window.title(config["title"])
# Console window
os.system(f"title {config["title"]} - Console")
# Show hide windows
def on_window(window, action):
if (action == "minimize"):
ctypes.windll.user32.ShowWindow(window, 6)
else:
ctypes.windll.user32.ShowWindow(window, 3)
# Launch function
def on_launch(target, params):
path, binary = os.path.split(target)
name, ext = os.path.splitext(binary)
if not ext:
binary = False
path = target
if not path:
path = False
if not isinstance(params, str):
params = ''
print(f'\nExecutable: {binary}')
print(f'Path: {path}')
print(f'Params: {params if params else False}')
if ("steam://" in target):
os.system(f'start "" "{target}{'//'+params if params else ''}"')
elif ("://" in target):
os.system(f'start "" "{target}{params}"')
elif (path and binary):
os.system(f'start "" /D "{path}" "{binary}" {params}')
else:
os.system(f'start "" "{target}" {params}')
if (config["closeOnLaunch"]):
quit()
elif not target == file_name:
on_window(ctypes.windll.user32.FindWindowW(None, config["title"]), "minimize")
# Reload app function
def on_reload():
print(f'\nReloading {file_base} ...')
time.sleep(1)
os.system("cls")
python = sys.executable
os.execl(python, python, * sys.argv)
# Main frame and labels
frame = tk.Frame()
frame.pack(padx=15, pady=15, fill="x")
label_title = tk.Label(master=frame, text=f'{config["title"]}', font=("Helvetica", 14, "bold"))
label_title.pack()
label_desc = tk.Label(master=frame, text=f'{config["description"]}')
label_desc.pack()
# Show buttons
for val in executables:
button_launch=tk.Button(master=frame, text=val["name"], cursor="hand2", command=lambda target=val["target"], params=val["params"]:on_launch(target, params))
button_launch.pack(pady=(5, 0), fill="x")
# Edit data button
button_launch=tk.Button(master=frame, text="Edit", cursor="hand2", width=5, command=lambda target=file_name, params=False:on_launch(target, params))
button_launch.pack(side="left", padx=(0, 5/2), pady=(5, 0), fill="x")
# Reload app button
button_launch=tk.Button(master=frame, text="Reload", cursor="hand2", width=5, command=on_reload)
button_launch.pack(side="right", padx=(5/2, 0), pady=(5, 0), fill="x")
# Minimize console
if (config["minimizeConsole"]):
on_window(ctypes.windll.kernel32.GetConsoleWindow(), "minimize")
# Console info
print(f'{config["title"]}\n{"-" * len(config["title"])}')
print(f'Total: {len(executables)} buttons')
print(f'minimizeConsole: {config["minimizeConsole"]}')
print(f'closeOnLaunch: {config["closeOnLaunch"]}')
# Close JSON file
json_file.close()
# Run app
window.eval("tk::PlaceWindow . center")
window.mainloop()
except Exception as e:
# Show error
error_title = "Unable to execute the program"
print(f'{error_title}\n{"-" * len(error_title)}')
print(f'{e}')
print("Press any key to continue...")
keyboard.read_key()