diff --git a/pywr_editor/dialogs/metadata/metadata_dialog.py b/pywr_editor/dialogs/metadata/metadata_dialog.py index 62681024..ecc9dcc9 100644 --- a/pywr_editor/dialogs/metadata/metadata_dialog.py +++ b/pywr_editor/dialogs/metadata/metadata_dialog.py @@ -65,5 +65,5 @@ def on_form_save(self) -> None: Save the form and close the dialog. :return: None """ - self.form.on_save() - self.close() + if self.form.on_save(): + self.close() diff --git a/pywr_editor/dialogs/node/node_dialog.py b/pywr_editor/dialogs/node/node_dialog.py index 3f232da0..0b37a98b 100644 --- a/pywr_editor/dialogs/node/node_dialog.py +++ b/pywr_editor/dialogs/node/node_dialog.py @@ -75,8 +75,8 @@ def on_form_save(self) -> None: Save the form and close the dialog. :return: None """ - self.form.save() - self.close() + if self.form.save(): + self.close() class NodeDialogTitle(QWidget): diff --git a/pywr_editor/main_window.py b/pywr_editor/main_window.py index cb7d3e3f..70208a76 100644 --- a/pywr_editor/main_window.py +++ b/pywr_editor/main_window.py @@ -23,7 +23,7 @@ TablesDialog, ) from pywr_editor.model import ModelConfig -from pywr_editor.schematic import Schematic, scaling_factor +from pywr_editor.schematic import Schematic, get_scaling_factor from pywr_editor.style import AppStylesheet from pywr_editor.toolbar import RunWidget, SchematicItemsLibrary, ToolbarWidget from pywr_editor.toolbar.run_controls.timestepper import TimeStepperWidget @@ -169,6 +169,8 @@ def closeEvent(self, event: PySide6.QtGui.QCloseEvent) -> None: else: event.ignore() + self.timer.stop() + # check if the run worker is still running try: if self.run_widget.worker: @@ -610,19 +612,7 @@ def setup_toolbar(self) -> None: self.app_actions.get("find-orphaned-parameters"), is_large=False ) - # Run tab - run = self.toolbar.add_tab("Run") - time_stepper_panel = run.add_panel("Time-stepper") - time_stepper_panel.add_widget(TimeStepperWidget(self)) - - nodes_panel = run.add_panel("Controls") - nodes_panel.add_widget(RunWidget(self)) - - results_panel = run.add_panel("Results") - results_panel.add_button(self.app_actions.get("run-inspector")) - # results_panel.add_button(self.app_actions.get("plot-data")) - - # Schematic tab + # Operation tab operation_tab = self.toolbar.add_tab("Operations") nodes_panel = operation_tab.add_panel("Undo", layout="vertical") nodes_panel.add_button(self.app_actions.get("undo"), is_large=False) @@ -641,6 +631,17 @@ def setup_toolbar(self) -> None: nodes_panel = operation_tab.add_panel("Nodes Library", show_name=False) nodes_panel.add_widget(SchematicItemsLibrary(self)) + # Run tab + run = self.toolbar.add_tab("Run") + time_stepper_panel = run.add_panel("Time-stepper") + time_stepper_panel.add_widget(TimeStepperWidget(self)) + + nodes_panel = run.add_panel("Controls") + nodes_panel.add_widget(RunWidget(self)) + + results_panel = run.add_panel("Results") + results_panel.add_button(self.app_actions.get("run-inspector")) + # View tab schematic_tab = self.toolbar.add_tab("Schematic") zoom_panel = schematic_tab.add_panel("Zoom") @@ -742,14 +743,14 @@ def zoom_in(self) -> None: Zooms in on the schematic. :return: None """ - self.set_zoom(scaling_factor("zoom-in")) + self.set_zoom(get_scaling_factor("zoom-in")) def zoom_out(self) -> None: """ Zooms out on the schematic. :return: None """ - self.set_zoom(scaling_factor("zoom-out")) + self.set_zoom(get_scaling_factor("zoom-out")) def zoom_100(self) -> None: """ diff --git a/pywr_editor/node_shapes/base_node.py b/pywr_editor/node_shapes/base_node.py index 101a63d4..0c2a2c38 100644 --- a/pywr_editor/node_shapes/base_node.py +++ b/pywr_editor/node_shapes/base_node.py @@ -39,7 +39,7 @@ def __init__( self.y = parent.y self.parent = parent - self.outline_width = 1 + self.outline_width = 1.5 self.fill = fill self.outline = outline self.label = label diff --git a/pywr_editor/node_shapes/custom/ground_water.py b/pywr_editor/node_shapes/custom/ground_water.py index b5cff363..2389a728 100644 --- a/pywr_editor/node_shapes/custom/ground_water.py +++ b/pywr_editor/node_shapes/custom/ground_water.py @@ -55,7 +55,7 @@ def paint( painter.setPen(pen) painter.setBrush(fill.qcolor) painter.drawEllipse(QPointF(0, 0), self.radius, self.radius) - l1 = -(self.radius - self.outline_width) - l2 = self.radius - self.outline_width + l1 = -self.radius + l2 = self.radius painter.drawLine(QPointF(l1, 0), QPointF(l2, 0)) painter.drawLine(QPointF(0, l1), QPointF(0, l2)) diff --git a/pywr_editor/node_shapes/custom/works.py b/pywr_editor/node_shapes/custom/works.py index b333fef9..7a64dd3c 100644 --- a/pywr_editor/node_shapes/custom/works.py +++ b/pywr_editor/node_shapes/custom/works.py @@ -28,6 +28,7 @@ def __init__(self, parent: "SchematicNode"): self.size = [22, 22] self.radius = self.size[0] / 2 + self.outline_width = 1 def paint( self, diff --git a/pywr_editor/schematic/abstract_schematic_item.py b/pywr_editor/schematic/abstract_schematic_item.py index 871d254b..cd32baf0 100644 --- a/pywr_editor/schematic/abstract_schematic_item.py +++ b/pywr_editor/schematic/abstract_schematic_item.py @@ -111,12 +111,12 @@ def draw_outline( # width line_width = pen.width() - self: QGraphicsItem - rect = self.boundingRect() - rect.setX(rect.x() + line_width) - rect.setY(rect.y() + line_width) - rect.setWidth(rect.width() - line_width) - rect.setHeight(rect.height() - line_width) - painter.drawRoundedRect(rect, 4, 4) - # remove default outline - option.state = QStyle.StateFlag.State_None + if isinstance(self, QGraphicsItem): + rect = self.boundingRect() + rect.setX(rect.x() + line_width) + rect.setY(rect.y() + line_width) + rect.setWidth(rect.width() - line_width) + rect.setHeight(rect.height() - line_width) + painter.drawRoundedRect(rect, 10, 10) + # remove default outline + option.state = QStyle.StateFlag.State_None diff --git a/pywr_editor/schematic/canvas.py b/pywr_editor/schematic/canvas.py index ec23d36f..53976214 100644 --- a/pywr_editor/schematic/canvas.py +++ b/pywr_editor/schematic/canvas.py @@ -49,7 +49,7 @@ def paint( """ painter.setPen(QPen(Color("gray", 400).hex)) painter.setBrush(Qt.GlobalColor.white) - painter.drawRoundedRect(self.boundingRect(), 4, 4) + painter.drawRoundedRect(self.boundingRect(), 8, 8) @property def shadow(self) -> QGraphicsDropShadowEffect: diff --git a/pywr_editor/schematic/schematic.py b/pywr_editor/schematic/schematic.py index cf67a810..e5221a0c 100644 --- a/pywr_editor/schematic/schematic.py +++ b/pywr_editor/schematic/schematic.py @@ -39,7 +39,7 @@ SchematicNode, SchematicRectangle, SchematicText, - scaling_factor, + get_scaling_factor, units_to_factor, ) from pywr_editor.style import Color, stylesheet_dict_to_str @@ -64,9 +64,9 @@ class Schematic(QGraphicsView): """ event emitted when schematic is moved """ connect_node_event = Signal(SchematicNode) """ event emitted when a node is being connected to another """ - min_zoom = scaling_factor("zoom-out", 3) + min_zoom = get_scaling_factor("zoom-out", 3) """ min zoom factor""" - max_zoom = scaling_factor("zoom-in", 3) + max_zoom = get_scaling_factor("zoom-in", 3) """ max zoom factor""" shape_class_map = { "TextShape": SchematicText, diff --git a/pywr_editor/schematic/zoom.py b/pywr_editor/schematic/zoom.py index cc5f0ea0..1fb8b4a9 100644 --- a/pywr_editor/schematic/zoom.py +++ b/pywr_editor/schematic/zoom.py @@ -12,7 +12,7 @@ def units_to_factor(units: float) -> float: return pow(2, -units / 240) -def scaling_factor( +def get_scaling_factor( scroll_type: Literal["zoom-in", "zoom-out"], scroll_count: int = 1 ) -> float: """ diff --git a/tests/dialogs/test_dialog_includes.py b/tests/dialogs/test_dialog_includes.py index 134d22de..8c68b9a9 100644 --- a/tests/dialogs/test_dialog_includes.py +++ b/tests/dialogs/test_dialog_includes.py @@ -101,7 +101,6 @@ def test_add_files(self, qtbot, file, added_to_model, error_message): all_files.insert(0, "model_2.json") assert model_config.has_changes is True - assert dialog.save_button.isEnabled() is False assert model_config.json["includes"] == all_files # check that the node library is updated diff --git a/tests/json_models/model_to_run.json b/tests/json_models/model_to_run.json index f5d3e55f..10bd2cdc 100644 --- a/tests/json_models/model_to_run.json +++ b/tests/json_models/model_to_run.json @@ -9,21 +9,20 @@ "model_version": "2.1" }, "timestepper": {"start": "2015-01-01", "end": "2015-12-31", "timestep": 1}, - "includes": ["files/custom_parameter.py"], "nodes": [ { "name": "Input", "type": "Input", "position": { "editor_position": [ - 134.18168, - 117.18473 + 434.18168, + 417.18473 ] } }, { "name": "Output", "type": "Output", "position": { "editor_position": [ - 34.18168, - 17.18473 + 304.18168, + 170.18473 ] } }