-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses_launcher.py
More file actions
158 lines (129 loc) · 5.65 KB
/
Copy pathcurses_launcher.py
File metadata and controls
158 lines (129 loc) · 5.65 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import curses
import subprocess
import time
import os
os.chdir(os.path.dirname(os.path.realpath(__file__))) # set cwd to where the script is
def main(stdscr):
# List of scripts to run
menu_fs = [
# HANDLE FS NOT RUNNING
{"name": "Fluidsynth status", "cmd": "./check_fluidsynth.sh", "sl": True}, # GOOD
{"name": "Toggle Fluidsynth", "cmd": "./toggle_fluidsynth.sh", "sl": True}, # GOOD
{"name": "FS Instruments", "cmd": "python3 curses_fs_instruments.py", "sl": True}, # GOOD
{"name": "FS Soundfonts", "cmd": "python3 curses_fs_fonts.py", "sl": True}, # GOOD
{"name": "FS Mixer", "cmd": "python3 curses_fs_mixer.py", "sl": False}, # GOOD
{"name": "FS mute control", "cmd": "python3 curses_fs_mutes.py", "sl": False}, # FIX ZEROS
{"name": "SQT muter control", "cmd": "python3 curses_sqt_mutes.py", "sl": False}, # GOOD
{"name": "Back", "cmd": "main"}
]
menu_routing = [
{"name": "MIDI routing", "cmd": "python3 curses_midiroute.py", "sl": True}, # NEEDS TESTING
{"name": "Audio routing", "cmd": "python3 curses_audioroute.py", "sl": False}, # NEEDS TON OF WORK
{"name": "Back", "cmd": "main"}
]
menu_ap = [ # REMOVED: bug in NIC means starting the access point again is impossible
{"name": "Back to wifi", "cmd": "sudo accesspopup", "sl": True}, # NEEDS TESTING
{"name": "Start AP", "cmd": "\
sudo systemctl stop NetworkManager && \
sudo modprobe -r brcmfmac_wcc && \
sudo modprobe -r brcmfmac && \
sudo modprobe brcmfmac && \
sudo modprobe brcmfmac_wcc && \
sudo systemctl start NetworkManager && \
sudo accesspopup -a", "sl": True}, # NEEDS TESTING
{"name": "Back", "cmd": "sys", "path": "Sys"},
]
menu_dm = [
{"name": "Toggle LoChord & SyxT", "cmd": "./daemons.sh", "sl": True}, # GOOD
{"name": "LoChord/SyxT log", "cmd": "python3 curses_dlog.py", "sl": False}, # GOOD
{"name": "Toggle SQT muter", "cmd": "./toggle_sqtmuter.sh", "sl": True}, # GOOD
{"name": "Toggle Reaper", "cmd": "./toggle_reaper.sh", "sl": True}, # GOOD
{"name": "Reaper log", "cmd": "python3 curses_rlog.py", "sl": False}, # GOOD
{"name": "Back", "cmd": "main"}
]
menu_sets = [
{"name": "Load set", "cmd": "python3 curses_load_set.py", "sl": True}, # ADD LEVELS
{"name": "Save set", "cmd": "python3 curses_save_set.py", "sl": True}, # GOOD
{"name": "Set log", "cmd": "python3 curses_slog.py", "sl": False},
{"name": "Back", "cmd": "main"}
]
menu_sys = [
{"name": "Brightness", "cmd": "python3 curses_brightness.py", "sl": False}, # GOOD
{"name": "Back to wifi", "cmd": "sudo accesspopup", "sl": True},
{"name": "Reboot", "cmd": "python3 curses_reboot.py", "sl": False}, # GOOD
{"name": "Back", "cmd": "main"}
]
scripts = [
{"name": "Routing...", "cmd": menu_routing, "path": "Rt"},
{"name": "MIDI...", "cmd": menu_fs, "path": "MIDI"},
{"name": "Daemons...", "cmd": menu_dm, "path": "Dmn"}, # GOOD
{"name": "Sets...", "cmd": menu_sets, "path": "Sets"},
{"name": "System...", "cmd": menu_sys, "path": "Sys"},
{"name": "PANIC", "cmd": "python3 curses_panic.py", "sl": False},
#{"name": "Exit", "cmd": None}
]
menu = scripts
current_index = 0
# Curses setup
curses.curs_set(0) # Hide cursor
path = "Main"
while True:
stdscr.clear()
# Draw title
# stdscr.addstr(0, 0, "=== Script Launcher ===", curses.A_BOLD)
# stdscr.addstr(1, 0, "")
# Draw menu
stdscr.addstr(12,32,"L",curses.A_REVERSE)
stdscr.addstr(0, 0, path)
for i, script in enumerate(menu):
if i == current_index:
stdscr.addstr(i+1, 0, f"> {script['name']}", curses.A_REVERSE)
else:
stdscr.addstr(i+1, 0, f" {script['name']}")
# # Instructions
# stdscr.addstr(len(menu) + 3, 0, "")
# stdscr.addstr(len(menu) + 4, 0, "L/R: Navigate | ENTER: Run | q: Quit")
stdscr.refresh()
# Get input
key = stdscr.getch()
if key == curses.KEY_LEFT:
current_index = (current_index - 1) % len(menu)
elif key == curses.KEY_RIGHT:
current_index = (current_index + 1) % len(menu)
elif key == ord('\n'): # Enter key
selected = menu[current_index]
key = "reset"
current_index = 0
if selected['cmd'] == "sys":
selected['cmd'] = menu_sys
if selected['cmd'] is None: # Exit option
break
elif type(selected['cmd']) == list:
menu = selected['cmd']
current_index = 0
path = "Main > " + selected["path"]
continue
elif selected['cmd'] == "main":
menu = scripts
current_index = 0
path = "Main"
continue
# Exit curses temporarily
curses.endwin()
os.system("clear")
# Run the script
#print(f"\nRunning: {selected['name']}\n")
subprocess.run(selected['cmd'], shell=True)
#input("\nPress ENTER to return to menu...")
# Restart curses
if selected["sl"]:
time.sleep(1)
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
curses.curs_set(0)
elif key == ord('q'):
break
if __name__ == "__main__":
curses.wrapper(main)