Skip to content

Commit

Permalink
Merge branch 'main' into fix-timer-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
s-simoncelli authored Feb 19, 2024
2 parents e099e2e + 104e23d commit 731766a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pywr_editor/dialogs/metadata/metadata_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions pywr_editor/dialogs/node/node_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
33 changes: 17 additions & 16 deletions pywr_editor/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion pywr_editor/node_shapes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pywr_editor/node_shapes/custom/ground_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
1 change: 1 addition & 0 deletions pywr_editor/node_shapes/custom/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions pywr_editor/schematic/abstract_schematic_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pywr_editor/schematic/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pywr_editor/schematic/schematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pywr_editor/schematic/zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
1 change: 0 additions & 1 deletion tests/dialogs/test_dialog_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions tests/json_models/model_to_run.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
}
Expand Down

0 comments on commit 731766a

Please sign in to comment.