added stub simulation entry and logs

This commit is contained in:
2026-07-20 15:26:18 +02:00
parent 495edd42f4
commit 9ed8e371ef
20 changed files with 1047 additions and 123 deletions

View File

@@ -13,7 +13,9 @@ from PySide6.QtWidgets import (
)
from bedit.core.model import Component, Parameter
from bedit.core.application_log import get_logger
from bedit.core.serializer import JsonDocumentSerializer
from bedit.core.simulation import Simulation
from bedit.gui.controllers.document import DocumentController
from bedit.gui.dialogs.component_options import ComponentOptionsDialog
from bedit.gui.dialogs.item_options import ItemOptionsDialog
@@ -27,8 +29,10 @@ from bedit.gui.models.library_tree import (
)
from bedit.gui.dialogs.settings import SettingsDialog
from bedit.gui.dialogs.port_options import PortOptionsDialog
from bedit.gui.dialogs.simulation_settings import SimulationSettingsDialog
from bedit.gui.preferences import application_settings
from bedit.gui.generated.ui_main_window import Ui_MainWindow
from bedit.gui.application_log import ApplicationLogHandler
class MainWindow(QMainWindow):
@@ -38,11 +42,19 @@ class MainWindow(QMainWindow):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.application_logger = get_logger()
self.log = get_logger("ui")
self.log_handler = ApplicationLogHandler(self.ui.logOutput)
self.application_logger.addHandler(self.log_handler)
self.application_logger.setLevel("INFO")
self.ui.workspaceVerticalSplitter.setSizes([580, 160])
self.log.info("BEdit started")
self.settings = application_settings()
self._applying_text_definition = False
self.libraries = LibraryRepository(self)
self.document_controller = DocumentController(self)
self.simulation = Simulation()
self.document_controller = DocumentController(self, simulation=self.simulation)
self.library_tree_model = LibraryTreeModel(
self.libraries,
self.document_controller,
@@ -141,6 +153,10 @@ class MainWindow(QMainWindow):
self.ui.actionZoomIn.triggered.connect(self.ui.graphView.zoom_in)
self.ui.actionZoomOut.triggered.connect(self.ui.graphView.zoom_out)
self.ui.actionCenterView.triggered.connect(self.ui.graphView.center_workspace)
self.ui.actionSimulationSettings.triggered.connect(
self.show_simulation_settings
)
self.ui.actionCompile.triggered.connect(self.compile_active_graph)
self.document_controller.undo_stack.canUndoChanged.connect(self.ui.actionUndo.setEnabled)
self.document_controller.undo_stack.canRedoChanged.connect(self.ui.actionRedo.setEnabled)
self.document_controller.modifiedChanged.connect(lambda _modified: self._update_title())
@@ -158,19 +174,40 @@ class MainWindow(QMainWindow):
self.ui.fileToolbar,
self.ui.editToolbar,
self.ui.cameraToolbar,
self.ui.simulationToolbar,
):
self.ui.menuToolbars.addAction(toolbar.toggleViewAction())
def reload_libraries(self) -> None:
self.libraries.load_paths(SettingsDialog.library_paths(self.settings))
self.ui.treeView.expandAll()
self.log.info("Reloaded %d libraries", len(self.libraries.libraries))
if self.libraries.load_warnings:
for warning in self.libraries.load_warnings:
self.log.warning("Library load failed: %s", warning)
QMessageBox.warning(
self,
"Some libraries could not be loaded",
"\n".join(self.libraries.load_warnings),
)
@Slot()
def show_simulation_settings(self) -> None:
component = self.document_controller.active_component
if component is None or component.implementation_kind != "graph":
return
dialog = SimulationSettingsDialog(component.graph.simulation_settings, self)
if dialog.exec() == dialog.DialogCode.Accepted:
self.document_controller.edit_simulation_settings(dialog.settings)
@Slot()
def compile_active_graph(self) -> None:
try:
self.document_controller.compile_active_graph()
except ValueError as error:
self.log.error("Compile failed: %s", error)
QMessageBox.warning(self, "Cannot compile", str(error))
def _restore_window_geometry(self) -> None:
geometry = self.settings.value("window/geometry")
if geometry is not None:
@@ -196,6 +233,8 @@ class MainWindow(QMainWindow):
self.ui.workspaceModeLabel.setText("")
self.ui.workspaceStack.setCurrentWidget(self.ui.emptyPage)
self._set_graph_controls_visible(False)
self.ui.actionSimulationSettings.setEnabled(False)
self.ui.actionCompile.setEnabled(False)
self._update_edit_actions()
return
self.ui.graphBreadcrumbLabel.setText(" ".join(self.document_controller.breadcrumb()))
@@ -203,6 +242,8 @@ class MainWindow(QMainWindow):
self.document_controller.document.find_parent(component.id) is not None
)
is_graph = component.implementation_kind == "graph"
self.ui.actionSimulationSettings.setEnabled(is_graph)
self.ui.actionCompile.setEnabled(is_graph)
self.ui.workspaceModeLabel.setText("Graph" if is_graph else "Text")
self.ui.workspaceStack.setCurrentWidget(
self.ui.graphPage if is_graph else self.ui.textPage
@@ -314,6 +355,7 @@ class MainWindow(QMainWindow):
finally:
self._applying_text_definition = False
except (TypeError, ValueError) as error:
self.log.error("Text component update failed: %s", error)
QMessageBox.critical(self, "Invalid text component", str(error))
self._load_text_definition()
return False
@@ -351,11 +393,14 @@ class MainWindow(QMainWindow):
def new_document(self) -> None:
if self._resolve_source_edits() and self._maybe_save():
self.document_controller.new_document()
self.log.info("Created a new document")
@Slot()
def close_document(self) -> None:
if self._resolve_source_edits() and self._maybe_save():
path = self.document_controller.file_path
self.document_controller.close_document()
self.log.info("Closed document%s", f" {path}" if path else "")
@Slot()
def open_document(self) -> None:
@@ -368,7 +413,9 @@ class MainWindow(QMainWindow):
return
try:
self.document_controller.load(Path(filename))
self.log.info("Opened document %s", filename)
except (OSError, ValueError) as error:
self.log.error("Could not open document %s: %s", filename, error)
QMessageBox.critical(self, "Could not open graph", str(error))
@Slot()
@@ -378,8 +425,10 @@ class MainWindow(QMainWindow):
if self.document_controller.file_path is None:
return self.save_document_as()
try:
self.document_controller.save()
path = self.document_controller.save()
self.log.info("Saved document %s", path)
except OSError as error:
self.log.error("Could not save document: %s", error)
QMessageBox.critical(self, "Could not save graph", str(error))
return False
return True
@@ -397,8 +446,10 @@ class MainWindow(QMainWindow):
if not filename:
return False
try:
self.document_controller.save(Path(filename))
path = self.document_controller.save(Path(filename))
self.log.info("Saved document %s", path)
except OSError as error:
self.log.error("Could not save document %s: %s", filename, error)
QMessageBox.critical(self, "Could not save graph", str(error))
return False
return True
@@ -509,6 +560,7 @@ class MainWindow(QMainWindow):
JsonDocumentSerializer.save(library.document, Path(library.source_path))
except (OSError, ValueError) as error:
component.inputs, component.outputs = old_inputs, old_outputs
self.log.error("Could not change library ports: %s", error)
QMessageBox.warning(self, "Cannot change library ports", str(error))
self.library_tree_model.rebuild()
@@ -526,6 +578,7 @@ class MainWindow(QMainWindow):
component_id, dialog.inputs, dialog.outputs
)
except ValueError as error:
self.log.error("Could not change component ports: %s", error)
QMessageBox.warning(self, "Cannot change ports", str(error))
@Slot(str)
@@ -547,6 +600,7 @@ class MainWindow(QMainWindow):
dialog.ui.showNameCheckBox.isChecked(),
)
except ValueError as error:
self.log.error("Could not rename component: %s", error)
QMessageBox.warning(self, "Cannot rename component", str(error))
@Slot(str, str)
@@ -595,4 +649,6 @@ class MainWindow(QMainWindow):
event.ignore()
return
self.settings.setValue("window/geometry", self.saveGeometry())
self.log.info("BEdit closed")
self.application_logger.removeHandler(self.log_handler)
event.accept()