app.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """
  2. Entry point for the unified LF-MRI GUI.
  3. Run from the repo root (MRI-testing/):
  4. python lf_mri_gui/app.py
  5. Or with optional pre-loads:
  6. python lf_mri_gui/app.py path/to/sequence.seq \\
  7. --hw-config lf_mri_gui/cfg/hw_config.json \\
  8. --output-dir /tmp/mri_output
  9. """
  10. from __future__ import annotations
  11. import os
  12. import sys
  13. # ── sys.path setup ────────────────────────────────────────────────────────────
  14. # _here = lf_mri_gui/ → enables: from src.xxx import ...
  15. # _repo_root = MRI-testing/ → enables: from LF_scanner.pypulseq import ...
  16. _here = os.path.dirname(os.path.abspath(__file__))
  17. _repo_root = os.path.dirname(_here)
  18. for _p in (_here, _repo_root):
  19. if _p not in sys.path:
  20. sys.path.insert(0, _p)
  21. import argparse
  22. from PySide6.QtWidgets import QApplication
  23. from src.app_window import LFMRIWindow
  24. def main() -> None:
  25. parser = argparse.ArgumentParser(
  26. description="LF-MRI System — unified scanner GUI"
  27. )
  28. parser.add_argument(
  29. "seq_file", nargs="?", default=None,
  30. help="Optional .seq file to pre-load in the Sequence tab",
  31. )
  32. parser.add_argument(
  33. "--hw-config", default=None,
  34. help="Optional hardware config JSON to load on startup",
  35. )
  36. parser.add_argument(
  37. "--output-dir", default=None,
  38. help="Optional output directory for exports",
  39. )
  40. args = parser.parse_args()
  41. app = QApplication(sys.argv)
  42. app.setApplicationName("LF-MRI System")
  43. app.setOrganizationName("LF-MRI")
  44. hw_config = os.path.abspath(args.hw_config) if args.hw_config and os.path.isfile(args.hw_config) else None
  45. output_dir = os.path.abspath(args.output_dir) if args.output_dir else None
  46. seq_file = os.path.abspath(args.seq_file) if args.seq_file and os.path.isfile(args.seq_file) else None
  47. # Load service URLs from bundled config (fallback to defaults)
  48. _cfg_path = os.path.join(_here, "cfg", "server_config.json")
  49. orchestrator_url = "http://localhost:1717"
  50. seq_interp_url = "http://localhost:7475"
  51. spectroscopy_url = "http://localhost:8002"
  52. try:
  53. import json as _json
  54. with open(_cfg_path, encoding="utf-8") as _f:
  55. _cfg = _json.load(_f)
  56. orchestrator_url = _cfg.get("orchestrator_url", orchestrator_url)
  57. seq_interp_url = _cfg.get("seq_interp_url", seq_interp_url)
  58. spectroscopy_url = _cfg.get("spectroscopy_url", spectroscopy_url)
  59. except Exception:
  60. pass
  61. win = LFMRIWindow(
  62. hw_config_path=hw_config,
  63. output_dir=output_dir,
  64. seq_file=seq_file,
  65. orchestrator_url=orchestrator_url,
  66. seq_interp_url=seq_interp_url,
  67. spectroscopy_url=spectroscopy_url,
  68. )
  69. win.show()
  70. sys.exit(app.exec())
  71. if __name__ == "__main__":
  72. main()