funcnodes-basic 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- funcnodes_basic/__init__.py +19 -0
- funcnodes_basic/lists.py +66 -0
- funcnodes_basic/logic.py +114 -0
- funcnodes_basic/math.py +684 -0
- funcnodes_basic/strings.py +740 -0
- funcnodes_basic-0.1.0.dist-info/METADATA +15 -0
- funcnodes_basic-0.1.0.dist-info/RECORD +8 -0
- funcnodes_basic-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
from funcnodes import Shelf
|
2
|
+
from .logic import NODE_SHELF as logic_shelf
|
3
|
+
from .math import NODE_SHELF as math_shelf
|
4
|
+
from .lists import NODE_SHELF as lists_shelf
|
5
|
+
from .strings import NODE_SHELF as strings_shelf
|
6
|
+
|
7
|
+
__version__ = "0.1.0"
|
8
|
+
|
9
|
+
NODE_SHELF = Shelf(
|
10
|
+
nodes=[],
|
11
|
+
subshelves=[
|
12
|
+
lists_shelf,
|
13
|
+
strings_shelf,
|
14
|
+
math_shelf,
|
15
|
+
logic_shelf,
|
16
|
+
],
|
17
|
+
name="basics",
|
18
|
+
description="basic functionalities",
|
19
|
+
)
|
funcnodes_basic/lists.py
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
from typing import List, Union, Any
|
2
|
+
import funcnodes as fn
|
3
|
+
|
4
|
+
|
5
|
+
@fn.NodeDecorator(
|
6
|
+
id="contains_node",
|
7
|
+
name="Contains",
|
8
|
+
)
|
9
|
+
def contains(collection: List[Union[str, Any]], item: Union[str, Any]) -> bool:
|
10
|
+
return item in collection
|
11
|
+
|
12
|
+
|
13
|
+
class GetIndexNode(fn.Node):
|
14
|
+
node_id = "list.get"
|
15
|
+
node_name = "Get Element"
|
16
|
+
description = "Gets an element from a list."
|
17
|
+
inputlist = fn.NodeInput(
|
18
|
+
name="List",
|
19
|
+
type=List[Union[str, Any]],
|
20
|
+
uuid="inputlist",
|
21
|
+
)
|
22
|
+
|
23
|
+
index = fn.NodeInput(
|
24
|
+
name="Index",
|
25
|
+
type=int,
|
26
|
+
uuid="index",
|
27
|
+
)
|
28
|
+
|
29
|
+
element = fn.NodeOutput(
|
30
|
+
name="Element",
|
31
|
+
type=Any,
|
32
|
+
uuid="element",
|
33
|
+
)
|
34
|
+
|
35
|
+
def __init__(self):
|
36
|
+
super().__init__()
|
37
|
+
self.get_input("inputlist").on("after_set_value", self._update_indices)
|
38
|
+
|
39
|
+
def _update_indices(self, **kwargs):
|
40
|
+
try:
|
41
|
+
lst = self.get_input("inputlist").value
|
42
|
+
index = self.get_input("index")
|
43
|
+
except KeyError:
|
44
|
+
return
|
45
|
+
try:
|
46
|
+
index.update_value_options(min=0, max=len(lst) - 1)
|
47
|
+
except Exception:
|
48
|
+
index.update_value_options(min=0, max=0)
|
49
|
+
|
50
|
+
async def func(
|
51
|
+
self,
|
52
|
+
inputlist: List[Any],
|
53
|
+
index: int,
|
54
|
+
) -> Any:
|
55
|
+
index = int(index)
|
56
|
+
ele = inputlist[index]
|
57
|
+
self.get_output("element").value = ele
|
58
|
+
return ele
|
59
|
+
|
60
|
+
|
61
|
+
NODE_SHELF = fn.Shelf(
|
62
|
+
nodes=[contains, GetIndexNode],
|
63
|
+
subshelves=[],
|
64
|
+
name="Logic",
|
65
|
+
description="Control flow and decision making nodes.",
|
66
|
+
)
|
funcnodes_basic/logic.py
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
"""Logic Nodes for control flow and decision making."""
|
2
|
+
|
3
|
+
from funcnodes.node import Node, TriggerStack
|
4
|
+
from typing import Any, List, Optional, Union
|
5
|
+
from funcnodes.io import NodeInput, NodeOutput, NoValue
|
6
|
+
import asyncio
|
7
|
+
|
8
|
+
import funcnodes as fn
|
9
|
+
|
10
|
+
|
11
|
+
class IfNode(Node):
|
12
|
+
node_id = "if_node"
|
13
|
+
node_name = "If"
|
14
|
+
on_true = NodeOutput(id="on_true", type=Any)
|
15
|
+
on_false = NodeOutput(id="on_false", type=Any)
|
16
|
+
condition = NodeInput(id="condition", type=bool)
|
17
|
+
input = NodeInput(id="input", type=Any)
|
18
|
+
|
19
|
+
async def func(self, condition: bool, input: Any) -> None:
|
20
|
+
if condition:
|
21
|
+
self.outputs["on_true"].value = input
|
22
|
+
else:
|
23
|
+
self.outputs["on_false"].value = input
|
24
|
+
|
25
|
+
|
26
|
+
class WhileNode(Node):
|
27
|
+
node_id = "while_node"
|
28
|
+
node_name = "While"
|
29
|
+
condition = NodeInput(id="condition", type=bool)
|
30
|
+
input = NodeInput(id="input", type=Any)
|
31
|
+
do = NodeOutput(id="do", type=Any)
|
32
|
+
done = NodeOutput(id="done", type=Any)
|
33
|
+
|
34
|
+
async def func(self, condition: bool, input: Any) -> None:
|
35
|
+
if condition:
|
36
|
+
self.outputs["do"].value = input
|
37
|
+
self.request_trigger()
|
38
|
+
else:
|
39
|
+
self.outputs["done"].value = input
|
40
|
+
|
41
|
+
|
42
|
+
class WaitNode(Node):
|
43
|
+
node_id = "wait_node"
|
44
|
+
node_name = "Wait"
|
45
|
+
delay = NodeInput(
|
46
|
+
id="delay",
|
47
|
+
type=float,
|
48
|
+
required=True,
|
49
|
+
default=1.0,
|
50
|
+
does_trigger=False,
|
51
|
+
render_options={"step": "0.1"},
|
52
|
+
value_options={"min": 0.0},
|
53
|
+
)
|
54
|
+
input = NodeInput(id="input", type=Any)
|
55
|
+
output = NodeOutput(id="output", type=Any)
|
56
|
+
|
57
|
+
async def func(self, delay: float, input: Any) -> None:
|
58
|
+
await asyncio.sleep(delay)
|
59
|
+
self.outputs["output"].value = input
|
60
|
+
|
61
|
+
|
62
|
+
class ForNode(Node):
|
63
|
+
node_id = "for_node"
|
64
|
+
node_name = "For"
|
65
|
+
input = NodeInput(id="input", type=List[Any])
|
66
|
+
do = NodeOutput(id="do", type=Any)
|
67
|
+
collector = NodeInput(id="collector", type=Any, does_trigger=False, required=False)
|
68
|
+
done = NodeOutput(id="done", type=List[Any])
|
69
|
+
|
70
|
+
async def func(self, input: list, collector: Optional[Any] = None) -> None:
|
71
|
+
results = []
|
72
|
+
for i in input:
|
73
|
+
self.outputs["do"].set_value(i, does_trigger=False)
|
74
|
+
triggerstack = TriggerStack()
|
75
|
+
try:
|
76
|
+
await self.outputs["do"].trigger(triggerstack)
|
77
|
+
await triggerstack
|
78
|
+
except Exception as e:
|
79
|
+
pass
|
80
|
+
v = self.inputs["collector"].value
|
81
|
+
if v is not NoValue:
|
82
|
+
results.append(v)
|
83
|
+
self.inputs["collector"].value = NoValue
|
84
|
+
self.outputs["done"].value = results
|
85
|
+
|
86
|
+
|
87
|
+
class CollectorNode(Node):
|
88
|
+
node_id = "collector_node"
|
89
|
+
node_name = "Collector"
|
90
|
+
|
91
|
+
reset = NodeInput(id="reset", type=Any, does_trigger=True, required=False)
|
92
|
+
input = NodeInput(id="input", type=Any)
|
93
|
+
|
94
|
+
output = NodeOutput(id="output", type=List[Any])
|
95
|
+
default_reset_inputs_on_trigger = True
|
96
|
+
|
97
|
+
def __init__(self, *args, **kwargs):
|
98
|
+
super().__init__(*args, **kwargs)
|
99
|
+
self.collection = []
|
100
|
+
|
101
|
+
async def func(self, input: Any, reset: Any = NoValue) -> None:
|
102
|
+
if reset != NoValue:
|
103
|
+
self.collection = []
|
104
|
+
|
105
|
+
self.collection.append(input)
|
106
|
+
self.outputs["output"].value = self.collection
|
107
|
+
|
108
|
+
|
109
|
+
NODE_SHELF = fn.Shelf(
|
110
|
+
nodes=[IfNode, WhileNode, WaitNode, ForNode, CollectorNode],
|
111
|
+
subshelves=[],
|
112
|
+
name="Logic",
|
113
|
+
description="Control flow and decision making nodes.",
|
114
|
+
)
|