forked from chaiNNer-org/chaiNNer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.py
More file actions
73 lines (65 loc) · 2 KB
/
switch.py
File metadata and controls
73 lines (65 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import annotations
from enum import Enum
from api import KeyInfo
from nodes.groups import optional_list_group
from nodes.properties.inputs import AnyInput, EnumInput
from nodes.properties.outputs import BaseOutput
from nodes.utils.utils import ALPHABET
from .. import value_group
class ValueIndex(Enum):
A = 0
B = 1
C = 2
D = 3
E = 4
F = 5
G = 6
H = 7
I = 8
J = 9
@value_group.register(
schema_id="chainner:utility:switch",
name="Switch",
description="Allows you to pass in multiple inputs and then change which one passes through to the output.",
icon="BsShuffle",
inputs=[
EnumInput(ValueIndex).with_id(0),
AnyInput("Value A").make_optional(),
AnyInput("Value B").make_optional(),
optional_list_group(
*[AnyInput(f"Value {letter}").make_optional() for letter in ALPHABET[2:10]],
),
],
outputs=[
BaseOutput(
output_type="""
let value = match Input0 {
ValueIndex::A => Input1,
ValueIndex::B => Input2,
ValueIndex::C => Input3,
ValueIndex::D => Input4,
ValueIndex::E => Input5,
ValueIndex::F => Input6,
ValueIndex::G => Input7,
ValueIndex::H => Input8,
ValueIndex::I => Input9,
ValueIndex::J => Input10,
_ => never
};
match value {
null => never,
_ => value
}
""",
label="Value",
).with_never_reason("The selected value should have a connection.")
],
key_info=KeyInfo.enum(0),
see_also=["chainner:utility:pass_through"],
)
def switch_node(selection: ValueIndex, *args: object | None) -> object:
if args[selection.value] is not None:
return args[selection.value]
raise RuntimeError(
"Invalid value selected. The selected value should have a connection."
)