Skip to content

Commit

Permalink
Implement support for node category.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jan 3, 2025
1 parent f179638 commit ffb5eae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
56 changes: 45 additions & 11 deletions colour/utilities/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ class PortNode(TreeNode, MixinLogging):
- :attr:`~colour.utilities.PortNode.dirty`
- :attr:`~colour.utilities.PortNode.edges`
- :attr:`~colour.utilities.PortNode.description`
- :attr:`~colour.utilities.PortNode.category`
Methods
-------
Expand Down Expand Up @@ -1047,13 +1048,16 @@ class PortNode(TreeNode, MixinLogging):
2
"""

def __init__(self, name: str | None = None, description: str = "") -> None:
def __init__(
self, name: str | None = None, description: str = "", category: str = "Default"
) -> None:
super().__init__(name)
self.description = description
self.category = category

self._input_ports = {}
self._output_ports = {}
self._dirty = True
self._input_ports: Dict = {}
self._output_ports: Dict = {}
self._dirty: bool = True

self.on_connected: Delegate = Delegate()
self.on_disconnected: Delegate = Delegate()
Expand Down Expand Up @@ -1175,6 +1179,36 @@ def description(self, value: str) -> None:

self._description = value

@property
def category(self) -> str:
"""
Getter and setter property for the node category.
Parameters
----------
value
Value to set the node category with.
Returns
-------
:class:`str` or None
Node category.
"""

return self._category

@category.setter
def category(self, value: str) -> None:
"""Setter for the **self.category** property."""

attest(
value is None or isinstance(value, str),
f'"category" property: "{value}" is not "None" or '
f'its type is not "str"!',
)

self._category = value

def add_input_port(
self,
name: str,
Expand Down Expand Up @@ -1690,9 +1724,9 @@ def __init__(self, name: str | None = None, description: str = "") -> None:

self._name: str = self.__class__.__name__
self.name = optional(name, self._name)
self.description = description
self.description: str = description

self._nodes = {}
self._nodes: dict = {}

@property
def nodes(self) -> Dict[str, PortNode]:
Expand Down Expand Up @@ -2112,7 +2146,7 @@ class ControlFlowNode(ExecutionNode):
"""Define a class inherited by control flow nodes."""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
super().__init__(*args, **{"category": "ControlFlow", **kwargs})


class For(ControlFlowNode):
Expand Down Expand Up @@ -2548,7 +2582,7 @@ class NodePassthrough(PortNode):
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
super().__init__(*args, **{"category": "Utilities", **kwargs})

self.description = "Pass the input data through"

Expand Down Expand Up @@ -2577,7 +2611,7 @@ class NodeLog(ExecutionNode):
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
super().__init__(*args, **{"category": "Verbose", **kwargs})

self.description = "Log the input data"

Expand Down Expand Up @@ -2606,7 +2640,7 @@ class NodeSleep(ExecutionNode):
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
super().__init__(*args, **{"category": "Time", **kwargs})

self.description = "Sleep for given duration in seconds"

Expand Down Expand Up @@ -2634,7 +2668,7 @@ class NodeSetGraphOutputPort(ExecutionNode):
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
super().__init__(*args, **{"category": "Graph", **kwargs})

self.description = (
"Set the parent graph output port with given name with given value"
Expand Down
1 change: 1 addition & 0 deletions colour/utilities/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def test_required_attributes(self) -> None:
"dirty",
"edges",
"description",
"category",
)

for attribute in required_attributes:
Expand Down

0 comments on commit ffb5eae

Please sign in to comment.