"""PLynx Operations defined as python code. Produce basic types."""
import math
import plynx.node
[docs]def print_any(value):
"""Format string to be html-friendly and print it."""
print(str(type(value)).replace("<", "").replace(">", ""))
print(value)
@plynx.node.output(name='int', var_type=int)
@plynx.node.output(name='str', var_type=str)
@plynx.node.output(name='dict', var_type=dict)
@plynx.node.output(name='float', var_type=float)
@plynx.node.output(name='bool', var_type=bool)
@plynx.node.output(name='color', var_type="color")
@plynx.node.operation(
title="All types",
description="Echo all types",
[docs])
def all_types():
"""Make basic values for each type."""
return {
"int": 42,
"str": "Hello world",
"dict": {"foo": "woo"},
"float": math.pi,
"bool": True,
"color": "#FF0000",
}
@plynx.node.input(name='value', var_type=int)
@plynx.node.operation(
title="Print Int value",
[docs])
def print_int(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type=str)
@plynx.node.operation(
title="Print String value",
[docs])
def print_str(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type=dict)
@plynx.node.operation(
title="Print Dict value",
[docs])
def print_dict(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type=float)
@plynx.node.operation(
title="Print Float value",
[docs])
def print_float(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type=bool)
@plynx.node.operation(
title="Print Bool value",
[docs])
def print_bool(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type="color")
@plynx.node.operation(
title="Print Color value",
[docs])
def print_color(value):
"""Print input value."""
print_any(value)
@plynx.node.input(name='value', var_type="py-json-file")
@plynx.node.output(name='value', var_type=dict)
@plynx.node.operation(
title="File to Dict",
[docs])
def file_to_dict(value):
"""Transform file object to dict"""
return {
"value": value,
}
@plynx.node.input(name='value', var_type=dict)
@plynx.node.output(name='value', var_type="py-json-file")
@plynx.node.operation(
title="Dict to File",
[docs])
def dict_to_file(value):
"""transform dict to file object"""
return {
"value": value,
}
[docs]GROUP = plynx.node.utils.Group(
title="Test Python built-in types",
items=[
all_types,
print_int,
print_str,
print_dict,
print_float,
print_bool,
print_color,
file_to_dict,
dict_to_file,
]
)