-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMultiText.py
62 lines (53 loc) · 1.77 KB
/
MultiText.py
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
class MultiTextNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"separator": ("STRING", {
"default": " ",
"multiline": False,
"hidden": True,
"forceInput": True
}),
"active": ("BOOLEAN", {"default": True, "hidden": True}),
},
"hidden": {
**{f"enabled{i}": ("BOOLEAN", {"default": True})for i in range(1, 21)},
**{f"text{i}": ("STRING", {"multiline": True}) for i in range(1, 21)},
**{f"weight{i}": ("FLOAT", {
"default": 1.0,
"min": 0.0,
"max": 2.0,
"step": 0.1
}) for i in range(1, 21)}
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("*",)
FUNCTION = "combine_text"
CATEGORY = "SKB/text"
def combine_text(self, separator=" ", active=True, **kwargs):
if not active:
return ("",)
texts = []
for i in range(1, 21):
# read enabled{i}
enabled = kwargs.get(f"enabled{i}", True)
if not enabled:
continue # skip if disabled
text = kwargs.get(f"text{i}", "").strip()
weight = kwargs.get(f"weight{i}", 1.0)
if weight is None:
weight = 1.0
if text:
if weight == 1.0:
texts.append(text)
else:
texts.append(f"({text}:{weight:.1f})")
return (separator.join(texts),)
NODE_CLASS_MAPPINGS = {
"MultiTextNode": MultiTextNode
}
NODE_DISPLAY_NAME_MAPPINGS = {
"MultiTextNode": "Multi Text+"
}