Launching of simulation application

This commit is contained in:
2026-07-31 12:24:52 +02:00
parent 66737e323b
commit 89ac2d8ff8
17 changed files with 555 additions and 36 deletions

View File

@@ -1,31 +1,49 @@
from __future__ import annotations
import sys
import argparse
import sys
def parse_arguments():
parser = argparse.ArgumentParser(exit_on_error=False)
from PySide6.QtWidgets import QApplication, QMessageBox
parser.add_argument(
"-f", "--file", type=str, help="Path to a BEditor BEsim file to open", default=None, required=False
)
parser.add_argument(
"-c", "--component", type=str, help="Component path in BEdit file to simulate", default=None, required=False
)
parser.add_argument(
"-s", "--simulation", type=str, help="Simulation name in BEdit file to simulate", default=None, required=False
)
from bedit_gui.controllers.simulation_file_controller import SimulationFileController
from bedit_gui.simulation_models import CompiledModel
from bedit_gui.views.simulation_window import SimulationWindow
return parser.parse_args(), parser
def main() -> int:
try:
args, parser = parse_arguments()
# TODO check if file is a BEditor file (.beb or .json)
if args.file and not (args.component or args.simulation):
parser.error("Component or Simulation required when opening a BEdit file")
except argparse.ArgumentError as e:
print(e.message)
return 1
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
return 0
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("BEdit")
app.setApplicationName("BEdit Simulator")
window = SimulationWindow()
controller = SimulationFileController(window)
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())