36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
|
"""
|
||
|
|
An example of a custom node definition.
|
||
|
|
"""
|
||
|
|
from pytrace.core.node_base import TraceNode, input_port, output_port, parameter, register_node
|
||
|
|
from pytrace.core.io import NodeIO
|
||
|
|
from pytrace.core.context import TraceContext
|
||
|
|
|
||
|
|
@register_node
|
||
|
|
class StringConcatNode(TraceNode):
|
||
|
|
"""A simple node that concatenates two strings with a separator."""
|
||
|
|
|
||
|
|
NAME = "Concatenate Strings"
|
||
|
|
CATEGORY = "Custom/String"
|
||
|
|
|
||
|
|
@input_port(name="string_a", label="String A", type="str")
|
||
|
|
@input_port(name="string_b", label="String B", type="str")
|
||
|
|
@output_port(name="result", label="Result", type="str")
|
||
|
|
@parameter(name="separator", label="Separator", type="str", default=" ")
|
||
|
|
def process(self, io: NodeIO, context: TraceContext) -> None:
|
||
|
|
# Get parameters
|
||
|
|
separator = io.get_param("separator", " ")
|
||
|
|
|
||
|
|
# Get inputs
|
||
|
|
str_a = io.get_input("string_a", "")
|
||
|
|
str_b = io.get_input("string_b", "")
|
||
|
|
|
||
|
|
# The actual logic
|
||
|
|
result = f"{str_a}{separator}{str_b}"
|
||
|
|
|
||
|
|
# Set the output
|
||
|
|
io.set_output("result", result)
|
||
|
|
|
||
|
|
context.log(f"Concatenated strings: {result}")
|
||
|
|
|
||
|
|
|