-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathIFDisplayTextNode.py
69 lines (57 loc) · 2.28 KB
/
IFDisplayTextNode.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
63
64
65
66
67
68
69
import sys
import logging
from typing import Optional
# Initialize logger
logger = logging.getLogger(__name__)
class IFDisplayText:
def __init__(self):
self.type = "output"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": ("STRING", {"forceInput": True}),
"select": ("INT", {
"default": 0,
"min": 0,
"max": sys.maxsize, # No practical upper limit
"step": 1,
"tooltip": "Select which line to output (cycles through available lines)"
}),
},
"hidden": {},
}
RETURN_TYPES = ("STRING", "STRING", "INT", "STRING")
RETURN_NAMES = ("text", "text_list", "count", "selected")
OUTPUT_IS_LIST = (False, True, False, False)
FUNCTION = "display_text"
OUTPUT_NODE = True
CATEGORY = "ImpactFrames💥🎞️/IF_tools"
def display_text(self, text: Optional[str], select):
if text is None:
logger.error("Received None for text input in display_text.")
return "" # Or handle appropriately
print("==================")
print("IF_AI_tool_output:")
print("==================")
print(text)
# Split text into lines and filter out empty lines
text_list = [line.strip() for line in text.split('\n') if line.strip()]
count = len(text_list)
# Select line using modulo to handle cycling
if count == 0:
selected = text # If no valid lines, return original text
else:
selected = text_list[select % count]
# Return both UI update and the multiple outputs
return {
"ui": {"string": [text]},
"result": (
text, # complete text
text_list, # list of individual lines as separate string outputs
count, # number of lines
selected # selected line based on select input
)
}
NODE_CLASS_MAPPINGS = {"IF_DisplayText": IFDisplayText}
NODE_DISPLAY_NAME_MAPPINGS = {"IF_DisplayText": "IF Display Text📟"}