-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (44 loc) · 1.68 KB
/
main.py
File metadata and controls
61 lines (44 loc) · 1.68 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
"""Main entry point for MoBI-View application.
Discovers LSL streams, creates DataInlets and MainAppPresenter, then starts
the WebSocket server with browser interface.
"""
import logging
import threading
import webbrowser
from MoBI_View.core import discovery
from MoBI_View.presenters import main_app_presenter
from MoBI_View.web import server as web_server
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger("MoBI-View.main")
def schedule_browser_launch() -> None:
"""Opens browser to application URL after short delay."""
def _launch() -> None:
host = "localhost"
port = 8765
url = f"http://{host}:{port}"
try:
webbrowser.open(url, new=2, autoraise=True)
except webbrowser.Error as exc: # pragma: no cover
logger.warning("Browser launch failed: %s", exc)
timer = threading.Timer(0.5, _launch)
timer.daemon = True
timer.start()
def main() -> None:
"""Discovers LSL streams, creates presenter, and starts the web server."""
logger.info("Discovering LSL streams...")
inlets = discovery.discover_and_create_inlets()
if not inlets:
logger.info("No LSL streams found.")
logger.info("Use 'Discover Streams' button in web UI to search for streams.")
else:
logger.info("Found %d stream(s)", len(inlets))
presenter = main_app_presenter.MainAppPresenter(data_inlets=inlets)
logger.info("Created presenter with %d inlet(s)", len(presenter.data_inlets))
schedule_browser_launch()
web_server.run_server(presenter)
if __name__ == "__main__":
main()