61 lines
2.7 KiB
Python
61 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
from PySide6.QtWidgets import QApplication, QMessageBox
|
|
|
|
from bedit_gui.controllers.simulation_file_controller import SimulationFileController
|
|
from bedit_gui.controllers.log_controller import LogController
|
|
from bedit_gui.controllers.simulation_run_controller import SimulationRunController
|
|
from bedit_gui.simulation_models import CompiledModel
|
|
from bedit_gui.services.application_settings import SimulationApplicationSettings
|
|
from bedit_gui.views.simulation_window import SimulationWindow
|
|
|
|
|
|
def parse_arguments(arguments: list[str] | None = None) -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description="Open and run BEdit simulations")
|
|
parser.add_argument("file", nargs="?", help="BEdit (.beb/.json) or simulation (.bes/.json) file")
|
|
parser.add_argument("-f", "--file", dest="file_option", help=argparse.SUPPRESS)
|
|
parser.add_argument("--handoff", action="store_true", help=argparse.SUPPRESS)
|
|
parser.add_argument("--model-name", help=argparse.SUPPRESS)
|
|
parser.add_argument("--executable", help=argparse.SUPPRESS)
|
|
parser.add_argument("--working-directory", help=argparse.SUPPRESS)
|
|
target = parser.add_mutually_exclusive_group()
|
|
target.add_argument("-c", "--component", help="Component ID or dotted path in a BEdit file")
|
|
target.add_argument("-s", "--simulation", help="Simulation settings name or ID in a BEdit file")
|
|
args = parser.parse_args(arguments)
|
|
args.file = args.file_option or args.file
|
|
if args.handoff and not all((args.model_name, args.executable, args.working_directory)):
|
|
parser.error("a simulator handoff requires compiled-model arguments")
|
|
return args
|
|
|
|
|
|
def main(arguments: list[str] | None = None) -> int:
|
|
args = parse_arguments(arguments)
|
|
app = QApplication(sys.argv if arguments is None else [sys.argv[0], *arguments])
|
|
|
|
app.setOrganizationName("BEsim")
|
|
app.setApplicationName("BEsim")
|
|
|
|
window = SimulationWindow()
|
|
controller = SimulationFileController(window)
|
|
|
|
settings = SimulationApplicationSettings()
|
|
LogController(window, settings.log_level)
|
|
SimulationRunController(window, controller)
|
|
|
|
window.showMaximized()
|
|
|
|
if args.file:
|
|
try:
|
|
compiled_model = CompiledModel(args.model_name, args.executable, args.working_directory) if args.handoff else None
|
|
controller.open(args.file, component=args.component, simulation=args.simulation, backed_by_file=not args.handoff, compiled_model=compiled_model)
|
|
except (OSError, ValueError, RuntimeError) as exc:
|
|
QMessageBox.critical(window, "Could not open simulation", str(exc))
|
|
return app.exec()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|