-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_nodes.py
More file actions
116 lines (97 loc) · 2.81 KB
/
debug_nodes.py
File metadata and controls
116 lines (97 loc) · 2.81 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
from .utils import MakeSmartType
class DisplayAnyNoOutputNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"value": ((MakeSmartType("*"), {})),
"mode": (["raw value", "json", "tensor shape"],),
},
}
@classmethod
def VALIDATE_INPUTS(s, input_types):
return True
RETURN_TYPES = (
MakeSmartType("*"),
"STRING",
)
RETURN_NAMES = (
"value",
"text",
)
FUNCTION = "to_string"
CATEGORY = "Power Flow/Utilities"
def to_string(self, value, mode):
def _value_to_string(value, mode):
if mode == "tensor shape":
text = []
def tensorShape(tensor):
if isinstance(tensor, dict):
for k in tensor:
tensorShape(tensor[k])
elif isinstance(tensor, list):
for i in range(len(tensor)):
tensorShape(tensor[i])
elif hasattr(tensor, "shape"):
text.append(list(tensor.shape))
tensorShape(value)
return text
elif mode == "json":
return json.dumps(value, indent=4)
else:
return str(value)
text = _value_to_string(value, mode)
return {
"ui": {"text": text},
"result": (
value,
text,
),
}
class DisplayAnyNode(DisplayAnyNoOutputNode):
OUTPUT_NODE = True
_ANSI_COLORS = {
"default": "0",
"black": "30",
"red": "31",
"green": "32",
"yellow": "33",
"blue": "34",
"magenta": "35",
"cyan": "36",
"white": "37",
"dark gray": "90",
"bright red": "91",
"bright green": "92",
"bright yellow": "93",
"bright blue": "94",
"bright magenta": "95",
"bright cyan": "96",
"bright white": "97",
}
class ConsolePrintNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"value": (MakeSmartType("*"),),
},
"optional": {
"prefix": ("STRING", {"multiline": False, "default": "Value:"}),
"color": (list(_ANSI_COLORS.keys()), {"default": "default"}),
},
}
@classmethod
def VALIDATE_INPUTS(s, input_types):
return True
RETURN_TYPES = (MakeSmartType("*"),)
RETURN_NAMES = ("value",)
FUNCTION = "print_to_console"
CATEGORY = "Power Flow/Utilities"
def print_to_console(self, value, prefix, color):
if color == "default":
print(f"{prefix} {value}")
else:
print(f"\033[{_ANSI_COLORS[color]}m{prefix} {value}\033[0m")
return (value,)