Skip to content

Commit

Permalink
Merge pull request #131 from pyiron/validate_io
Browse files Browse the repository at this point in the history
Validate IO
  • Loading branch information
liamhuber authored Nov 28, 2022
2 parents 571d952 + c40bca1 commit 3c76ae1
Show file tree
Hide file tree
Showing 31 changed files with 1,218 additions and 560 deletions.
3 changes: 2 additions & 1 deletion ironflow/custom_nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"""

import ironflow.custom_nodes.input_widgets
from ironflow.model import dtypes, NodeInputBP, NodeOutputBP
from ironflow.model import dtypes, NodeInputBP
from ironflow.model.node import Node
from ironflow.model.port import NodeOutputBP
19 changes: 16 additions & 3 deletions ironflow/gui/workflows/boxes/node_interface/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,41 @@ def input_field_list(self) -> list[list[widgets.Widget]]:
if dtype == "Integer":
inp_widget = widgets.IntText(
value=inp.val,
disabled=False,
description="",
continuous_update=False,
disabled=len(inp.connections) > 0,
)
elif dtype == "Float":
inp_widget = widgets.FloatText(
value=inp.val,
description="",
continuous_update=False,
disabled=len(inp.connections) > 0,
)
elif dtype == "Boolean":
inp_widget = widgets.Checkbox(
value=inp.val,
indent=False,
description="",
disabled=len(inp.connections) > 0,
)
elif dtype == "Choice":
inp_widget = widgets.Dropdown(
value=inp.val,
options=inp.dtype.items,
description="",
ensure_option=True,
disabled=len(inp.connections) > 0,
)

else:
elif dtype == "String" or dtype == "Char":
inp_widget = widgets.Text(
value=str(inp.val),
continuous_update=False,
disabled=len(inp.connections) > 0,
)
else:
inp_widget = widgets.Text(
value=str(inp.val), continuous_update=False, disabled=True
)
description = inp.label_str
elif inp.label_str != "":
Expand Down
2 changes: 1 addition & 1 deletion ironflow/gui/workflows/canvas_widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if TYPE_CHECKING:
from ironflow.gui.workflows.canvas_widgets.flow import FlowCanvas
from ironflow.gui.workflows.screen import WorkflowsGUI
from ironflow.model import Flow
from ironflow.model.flow import Flow


class CanvasWidget(ABC):
Expand Down
2 changes: 1 addition & 1 deletion ironflow/gui/workflows/canvas_widgets/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Optional

from ironflow.model.port import NodeInput, NodeOutput
from ironflow.gui.workflows.canvas_widgets.base import CanvasWidget, HideableWidget
from ironflow.gui.workflows.canvas_widgets.layouts import ButtonLayout
from ironflow.model import NodeInput, NodeOutput

if TYPE_CHECKING:
from ironflow.gui.workflows.canvas_widgets.base import Number
Expand Down
2 changes: 1 addition & 1 deletion ironflow/gui/workflows/canvas_widgets/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if TYPE_CHECKING:
from ironflow.gui.workflows.canvas_widgets.base import Number
from ironflow.gui.workflows.screen import WorkflowsGUI
from ironflow.model import Flow
from ironflow.model.flow import Flow
from ironflow.model.node import Node


Expand Down
11 changes: 7 additions & 4 deletions ironflow/gui/workflows/canvas_widgets/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ class PortLayout(Layout, ABC):

@dataclass
class DataPortLayout(PortLayout):
background_color: str = "lightgreen"
selected_color: str = "darkgreen"
valid_color: str = "lightgreen"
valid_selected_color: str = "darkgreen"
invalid_color: str = "red"
invalid_selected_color: str = "darkred"


@dataclass
class ExecPortLayout(PortLayout):
background_color: str = "lightblue"
selected_color: str = "darkblue"
# Exec ports have no data, so are always valid
valid_color: str = "lightblue"
valid_selected_color: str = "darkblue"


@dataclass
Expand Down
24 changes: 17 additions & 7 deletions ironflow/gui/workflows/canvas_widgets/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if TYPE_CHECKING:
from ironflow.gui.workflows.canvas_widgets.flow import FlowCanvas
from ironflow.gui.workflows.canvas_widgets.base import Number
from ironflow.model import NodePort
from ironflow.model.port import NodeInput, NodeOutput


class PortWidget(HideableWidget):
Expand All @@ -25,7 +25,7 @@ def __init__(
y: Number,
parent: FlowCanvas | CanvasWidget,
layout: PortLayout,
port: NodePort,
port: NodeInput | NodeOutput,
selected: bool = False,
title: Optional[str] = None,
hidden_x: Optional[Number] = None,
Expand Down Expand Up @@ -64,12 +64,22 @@ def on_click(
self.select()
return self

@property
def _current_color(self):
if self.port.valid_val:
if self.selected:
color = self.layout.valid_selected_color
else:
color = self.layout.valid_color
else:
if self.selected:
color = self.layout.invalid_selected_color
else:
color = self.layout.invalid_color
return color

def draw_shape(self) -> None:
self.canvas.fill_style = (
self.layout.selected_color
if self.selected
else self.layout.background_color
)
self.canvas.fill_style = self._current_color
self.canvas.fill_circle(self.x, self.y, self.radius)

def draw_title(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ironflow/gui/workflows/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if TYPE_CHECKING:
from ironflow.model.model import HasSession
from ironflow.gui.workflows.canvas_widgets.nodes import NodeWidget
from ironflow.model import Flow
from ironflow.model.flow import Flow
from ironflow.model.node import Node


Expand Down
14 changes: 8 additions & 6 deletions ironflow/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Distributed under the terms of "New BSD License", see the LICENSE file.
"""
Wrappers and extensions of the underlying ryven model.
The `model.HasSession` class provides the main interface between ironflow and ryven.
The rest of these modules revolve mostly around the `DType` class -- namely, ensuring
that each port has a `dtype` attribute (`None` values are handled fine to describe
un-typed ports) and that these dtypes can be used for meaningful type checking when
making connections.
"""

from ryvencore import (
Flow,
NodeInputBP,
NodeOutputBP,
)
from ryvencore.NodePort import NodePort, NodeInput, NodeOutput
from ryvencore import NodeInputBP
from ryvencore.NodePort import NodePort
Loading

0 comments on commit 3c76ae1

Please sign in to comment.