From 657aa805f3e255ac8181e3f41cf9156b17638d32 Mon Sep 17 00:00:00 2001 From: Stefano Simonelli <16114781+s-simoncelli@users.noreply.github.com> Date: Sun, 18 Feb 2024 07:45:26 +0000 Subject: [PATCH 1/5] Changed outline width --- pywr_editor/main_window.py | 6 +++--- pywr_editor/node_shapes/base_node.py | 2 +- pywr_editor/node_shapes/custom/ground_water.py | 4 ++-- pywr_editor/node_shapes/custom/works.py | 1 + .../schematic/abstract_schematic_item.py | 18 +++++++++--------- pywr_editor/schematic/canvas.py | 2 +- pywr_editor/schematic/schematic.py | 6 +++--- pywr_editor/schematic/zoom.py | 2 +- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/pywr_editor/main_window.py b/pywr_editor/main_window.py index cb7d3e3f..2832d61d 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 @@ -742,14 +742,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..58e2d363 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(), 10, 10) @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: """ From a7e4cc6aa12604e01335f6b9ffd803f5b2d3003b Mon Sep 17 00:00:00 2001 From: Stefano Simonelli <16114781+s-simoncelli@users.noreply.github.com> Date: Sun, 18 Feb 2024 09:11:27 +0000 Subject: [PATCH 2/5] Fixed tests --- pywr_editor/main_window.py | 2 ++ tests/dialogs/test_dialog_includes.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pywr_editor/main_window.py b/pywr_editor/main_window.py index 2832d61d..69e655ce 100644 --- a/pywr_editor/main_window.py +++ b/pywr_editor/main_window.py @@ -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: 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 From e11a010414fd388c9224c138a16de56f6753d6b1 Mon Sep 17 00:00:00 2001 From: Stefano Simonelli <16114781+s-simoncelli@users.noreply.github.com> Date: Sun, 18 Feb 2024 10:22:14 +0000 Subject: [PATCH 3/5] Fixed run model test --- tests/json_models/model_to_run.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 ] } } From efe8d8a0788273e306a6f268746d3b6ee7482a9b Mon Sep 17 00:00:00 2001 From: Stefano Simonelli <16114781+s-simoncelli@users.noreply.github.com> Date: Sun, 18 Feb 2024 10:26:45 +0000 Subject: [PATCH 4/5] Change tab order --- pywr_editor/main_window.py | 25 ++++++++++++------------- pywr_editor/schematic/canvas.py | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pywr_editor/main_window.py b/pywr_editor/main_window.py index 69e655ce..70208a76 100644 --- a/pywr_editor/main_window.py +++ b/pywr_editor/main_window.py @@ -612,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) @@ -643,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") diff --git a/pywr_editor/schematic/canvas.py b/pywr_editor/schematic/canvas.py index 58e2d363..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(), 10, 10) + painter.drawRoundedRect(self.boundingRect(), 8, 8) @property def shadow(self) -> QGraphicsDropShadowEffect: From 104e23d237ad3d301ff6f890dbf9a701127cfbb9 Mon Sep 17 00:00:00 2001 From: Stefano Simonelli <16114781+s-simoncelli@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:24:09 +0000 Subject: [PATCH 5/5] Do not close the dialog if the form validation fails --- pywr_editor/dialogs/metadata/metadata_dialog.py | 4 ++-- pywr_editor/dialogs/node/node_dialog.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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):