Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (78 loc) · 3.17 KB
/
Copy pathmain.py
File metadata and controls
94 lines (78 loc) · 3.17 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
import sys
import builtins
from core.load_env import CONTROLLER_INPUT, CONTROLLER_OUTPUT, INPUT_DEVICES, COMBINED_OUTPUT_SINK, get_output_devices
from core.bluetoothctl import bluetooth_connect_speakers, bluetoothctl_remove_devices
from core.audio_manager import AudioManager
from core.audio_sinks import is_combined_sink_active, build_speaker_list
from core.bluetooth_scanner import BluetoothScanner, scan_queue
from core.reset import factory_reset, delete_speaker_state_file, delete_selected_devices_state_file, unload_audio_modules
from core.connect_and_combine import connect_and_combine_all
import core.load_env
from interfaces.tui.presenter import build_app_config
from interfaces.tui.engine import start_app, log, non_blocking, get_active_menu
from interfaces.tui.device_menu import DeviceSelectionMenu
# INSTANTIATE AUDIOMANAGER // LOADS JSON STATE FILE AND BUILDS SPEAKER OBJECTS FROM SPEAKER CLASS
audio_mgr = AudioManager()
def tui_connect_and_combine_all():
"""Thin wrapper: runs the use case, then tells the TUI to refresh."""
connect_and_combine_all(
audio_mgr,
CONTROLLER_OUTPUT,
core.load_env.OUTPUT_DEVICES,
COMBINED_OUTPUT_SINK)
get_active_menu().update_config(tui_config())
return "Connect and combine complete!"
# COMBINED FACTORY RESET FUNCTION TO WORK WITHIN CLI_APP
def tui_factory_reset():
factory_reset()
audio_mgr.speakers = []
get_active_menu().update_config(tui_config())
return "Factory reset complete."
## PASS IN FUNCTIONS TO BE USED WITHIN TUI > interfaces/tui/presenter.py
def tui_config():
#submenu for scanner
scanner = BluetoothScanner(scan_queue)
device_menu = DeviceSelectionMenu(scanner, on_saved=refresh_tui_after_scan)
return build_app_config(
audio_mgr,
device_menu,
tui_connect_and_combine_all,
tui_factory_reset,
unload_audio_modules,
bluetoothctl_remove_devices,
delete_speaker_state_file,
delete_selected_devices_state_file,
)
def refresh_tui_after_scan():
unload_audio_modules()
core.load_env.OUTPUT_DEVICES = get_output_devices()
get_active_menu().update_config(tui_config())
# START TERMINAL USER INTERFACE
def tui():
if is_combined_sink_active(audio_mgr.combined_sink_name) and not audio_mgr.speakers:
audio_mgr.speakers = build_speaker_list()
audio_mgr.persist_state()
else:
audio_mgr.reconcile()
start_app(title="OPEN SPEAKER MULTI CONNECT", menu_config=tui_config())
# START WEB USER INTERFACE
def web():
print("I have to be built still..")
# TESTING AREA
def test():
print("Testing environment:")
# DECIDE WHICH APP TO LAUNCH
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "--tui":
## HIJACKING PRINT STATEMENTS HACK GLOBALLY ACROSS ALL IMPORTED MODULES FOR RENDERING IN CLI_APP
builtins.print = log
## LAUNCH TUI
tui()
elif len(sys.argv) > 1 and sys.argv[1] == "--web":
## LAUNCH WEBAPP
web()
elif len(sys.argv) > 1 and sys.argv[1] == "--test":
## TESTING ENVIRNOMENT
test()
else:
print("please run this script with either --tui or --web arguments")