| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- """
- Entry point for the unified LF-MRI GUI.
- Run from the repo root (MRI-testing/):
- python lf_mri_gui/app.py
- Or with optional pre-loads:
- python lf_mri_gui/app.py path/to/sequence.seq \\
- --hw-config lf_mri_gui/cfg/hw_config.json \\
- --output-dir /tmp/mri_output
- """
- from __future__ import annotations
- import os
- import sys
- # ── sys.path setup ────────────────────────────────────────────────────────────
- # _here = lf_mri_gui/ → enables: from src.xxx import ...
- # _repo_root = MRI-testing/ → enables: from LF_scanner.pypulseq import ...
- _here = os.path.dirname(os.path.abspath(__file__))
- _repo_root = os.path.dirname(_here)
- for _p in (_here, _repo_root):
- if _p not in sys.path:
- sys.path.insert(0, _p)
- import argparse
- from PySide6.QtWidgets import QApplication
- from src.app_window import LFMRIWindow
- def main() -> None:
- parser = argparse.ArgumentParser(
- description="LF-MRI System — unified scanner GUI"
- )
- parser.add_argument(
- "seq_file", nargs="?", default=None,
- help="Optional .seq file to pre-load in the Sequence tab",
- )
- parser.add_argument(
- "--hw-config", default=None,
- help="Optional hardware config JSON to load on startup",
- )
- parser.add_argument(
- "--output-dir", default=None,
- help="Optional output directory for exports",
- )
- args = parser.parse_args()
- app = QApplication(sys.argv)
- app.setApplicationName("LF-MRI System")
- app.setOrganizationName("LF-MRI")
- hw_config = os.path.abspath(args.hw_config) if args.hw_config and os.path.isfile(args.hw_config) else None
- output_dir = os.path.abspath(args.output_dir) if args.output_dir else None
- seq_file = os.path.abspath(args.seq_file) if args.seq_file and os.path.isfile(args.seq_file) else None
- # Load service URLs from bundled config (fallback to defaults)
- _cfg_path = os.path.join(_here, "cfg", "server_config.json")
- orchestrator_url = "http://localhost:1717"
- seq_interp_url = "http://localhost:7475"
- spectroscopy_url = "http://localhost:8002"
- try:
- import json as _json
- with open(_cfg_path, encoding="utf-8") as _f:
- _cfg = _json.load(_f)
- orchestrator_url = _cfg.get("orchestrator_url", orchestrator_url)
- seq_interp_url = _cfg.get("seq_interp_url", seq_interp_url)
- spectroscopy_url = _cfg.get("spectroscopy_url", spectroscopy_url)
- except Exception:
- pass
- win = LFMRIWindow(
- hw_config_path=hw_config,
- output_dir=output_dir,
- seq_file=seq_file,
- orchestrator_url=orchestrator_url,
- seq_interp_url=seq_interp_url,
- spectroscopy_url=spectroscopy_url,
- )
- win.show()
- sys.exit(app.exec())
- if __name__ == "__main__":
- main()
|