mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-14 23:34:35 +08:00
Merge pull request #99 from sn0w12/main
Update WidgetToString to use 'any_input' link if no id or title provided.
This commit is contained in:
commit
9bb1e47ba7
@ -717,9 +717,9 @@ class WidgetToString:
|
|||||||
"any_input": (any, {}),
|
"any_input": (any, {}),
|
||||||
"node_title": ("STRING", {"multiline": False}),
|
"node_title": ("STRING", {"multiline": False}),
|
||||||
},
|
},
|
||||||
|
|
||||||
"hidden": {"extra_pnginfo": "EXTRA_PNGINFO",
|
"hidden": {"extra_pnginfo": "EXTRA_PNGINFO",
|
||||||
"prompt": "PROMPT"},
|
"prompt": "PROMPT",
|
||||||
|
"unique_id": "UNIQUE_ID",},
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_TYPES = ("STRING", )
|
RETURN_TYPES = ("STRING", )
|
||||||
@ -727,18 +727,20 @@ class WidgetToString:
|
|||||||
CATEGORY = "KJNodes/text"
|
CATEGORY = "KJNodes/text"
|
||||||
DESCRIPTION = """
|
DESCRIPTION = """
|
||||||
Selects a node and it's specified widget and outputs the value as a string.
|
Selects a node and it's specified widget and outputs the value as a string.
|
||||||
|
If no node id or title is provided it will use the 'any_input' link and use that node.
|
||||||
To see node id's, enable node id display from Manager badge menu.
|
To see node id's, enable node id display from Manager badge menu.
|
||||||
Alternatively you can search with the node title. Node titles ONLY exist if they
|
Alternatively you can search with the node title. Node titles ONLY exist if they
|
||||||
are manually edited!
|
are manually edited!
|
||||||
The 'any_input' is purely for making sure the node you want the value from exists in the workflow,
|
The 'any_input' is required for making sure the node you want the value from exists in the workflow.
|
||||||
it has no other function than place this node at right spot in the workflow execution order.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_widget_value(self, id, widget_name, extra_pnginfo, prompt, return_all=False, any_input=None, node_title=""):
|
def get_widget_value(self, id, widget_name, extra_pnginfo, prompt, unique_id, return_all=False, any_input=None, node_title=""):
|
||||||
workflow = extra_pnginfo["workflow"]
|
workflow = extra_pnginfo["workflow"]
|
||||||
#print(json.dumps(workflow, indent=4))
|
#print(json.dumps(workflow, indent=4))
|
||||||
results = []
|
results = []
|
||||||
node_id = None # Initialize node_id to handle cases where no match is found
|
node_id = None # Initialize node_id to handle cases where no match is found
|
||||||
|
link_id = None
|
||||||
|
link_to_node_map = {}
|
||||||
|
|
||||||
for node in workflow["nodes"]:
|
for node in workflow["nodes"]:
|
||||||
if node_title:
|
if node_title:
|
||||||
@ -748,9 +750,30 @@ it has no other function than place this node at right spot in the workflow exec
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Node title not found.")
|
print("Node title not found.")
|
||||||
elif node["id"] == id:
|
elif id != 0:
|
||||||
|
if node["id"] == id:
|
||||||
node_id = id
|
node_id = id
|
||||||
break
|
break
|
||||||
|
elif any_input is not None:
|
||||||
|
if node["type"] == "WidgetToString" and node["id"] == int(unique_id) and not link_id:
|
||||||
|
for node_input in node["inputs"]:
|
||||||
|
link_id = node_input["link"]
|
||||||
|
|
||||||
|
# Construct a map of links to node IDs for future reference
|
||||||
|
node_outputs = node.get("outputs", None)
|
||||||
|
if not node_outputs:
|
||||||
|
continue
|
||||||
|
for output in node_outputs:
|
||||||
|
node_links = output.get("links", None)
|
||||||
|
if not node_links:
|
||||||
|
continue
|
||||||
|
for link in node_links:
|
||||||
|
link_to_node_map[link] = node["id"]
|
||||||
|
if link_id and link == link_id:
|
||||||
|
break
|
||||||
|
|
||||||
|
if link_id:
|
||||||
|
node_id = link_to_node_map.get(link_id, None)
|
||||||
|
|
||||||
if node_id is None:
|
if node_id is None:
|
||||||
raise ValueError("No matching node found for the given title or id")
|
raise ValueError("No matching node found for the given title or id")
|
||||||
@ -763,9 +786,9 @@ it has no other function than place this node at right spot in the workflow exec
|
|||||||
v = str(values["inputs"][widget_name]) # Convert to string here
|
v = str(values["inputs"][widget_name]) # Convert to string here
|
||||||
return (v, )
|
return (v, )
|
||||||
else:
|
else:
|
||||||
raise NameError(f"Widget not found: {id}.{widget_name}")
|
raise NameError(f"Widget not found: {node_id}.{widget_name}")
|
||||||
if not results:
|
if not results:
|
||||||
raise NameError(f"Node not found: {id}")
|
raise NameError(f"Node not found: {node_id}")
|
||||||
return (', '.join(results).strip(', '), )
|
return (', '.join(results).strip(', '), )
|
||||||
|
|
||||||
class DummyOut:
|
class DummyOut:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user