mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
Merge branch 'node-ui-enhancements'
This commit is contained in:
parent
0e4395a8a3
commit
c8e01b0d8b
42
comfy_extras/ui_decorator.py
Normal file
42
comfy_extras/ui_decorator.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
def ui_signal(signals:str|list[str]):
|
||||||
|
"""
|
||||||
|
Return a decorator for Node classes.
|
||||||
|
@param signals - a list of strings that name the signals to be sent to the UI.
|
||||||
|
(For convenience, a string gets converted to a list of length 1)
|
||||||
|
|
||||||
|
The decorator performs the following:
|
||||||
|
The class has OUTPUT_NODE set to True.
|
||||||
|
The class UI_OUTPUT is appended (or created) with a comma separated list of these signals
|
||||||
|
The class FUNCTION is wrapped such that the last len(signals) are removed, and added to the
|
||||||
|
ui dictionary using signals as keys.
|
||||||
|
|
||||||
|
So ui_signals(["first","second"]) will wrap a function returning (something, somethingelse, first_signal, second_signal)
|
||||||
|
and will return { "ui": {"first":first_signal, "second":second_signal}, "result":(something, somethingelse) }
|
||||||
|
"""
|
||||||
|
signals:iter = [signals,] if isinstance(signals,str) else signals
|
||||||
|
def decorator(clazz):
|
||||||
|
internal_function_name = getattr(clazz,'FUNCTION')
|
||||||
|
if internal_function_name=='_ui_signal_decorated_function':
|
||||||
|
raise Exception("Can't nest ui_signal decorators")
|
||||||
|
def _ui_signal_decorated_function(self, **kwargs):
|
||||||
|
returns = getattr(self,internal_function_name)(**kwargs)
|
||||||
|
returns_tuple = returns['result'] if isinstance(returns,dict) else returns
|
||||||
|
returns_ui = returns.get('ui',{}) if isinstance(returns,dict) else {}
|
||||||
|
|
||||||
|
popped_returns = returns_tuple[-len(signals):]
|
||||||
|
returns_tuple = returns_tuple[:-len(signals)]
|
||||||
|
|
||||||
|
for i,key in enumerate(signals):
|
||||||
|
returns_ui['key'] = popped_returns[i]
|
||||||
|
|
||||||
|
return { "ui":returns_ui, "result": returns_tuple }
|
||||||
|
clazz._ui_signal_decorated_function = _ui_signal_decorated_function
|
||||||
|
clazz.FUNCTION = '_ui_signal_decorated_function'
|
||||||
|
clazz.OUTPUT_NODE = True
|
||||||
|
clazz.UI_OUTPUT = clazz.UI_OUTPUT+"," if hasattr(clazz, 'UI_OUTPUT') else ""
|
||||||
|
clazz.UI_OUTPUT += ",".join(signals)
|
||||||
|
return clazz
|
||||||
|
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
@ -399,6 +399,7 @@ class PromptServer():
|
|||||||
info['name'] = node_class
|
info['name'] = node_class
|
||||||
info['display_name'] = nodes.NODE_DISPLAY_NAME_MAPPINGS[node_class] if node_class in nodes.NODE_DISPLAY_NAME_MAPPINGS.keys() else node_class
|
info['display_name'] = nodes.NODE_DISPLAY_NAME_MAPPINGS[node_class] if node_class in nodes.NODE_DISPLAY_NAME_MAPPINGS.keys() else node_class
|
||||||
info['description'] = obj_class.DESCRIPTION if hasattr(obj_class,'DESCRIPTION') else ''
|
info['description'] = obj_class.DESCRIPTION if hasattr(obj_class,'DESCRIPTION') else ''
|
||||||
|
info['ui_output'] = obj_class.UI_OUTPUT if hasattr(obj_class, 'UI_OUTPUT') else ''
|
||||||
info['category'] = 'sd'
|
info['category'] = 'sd'
|
||||||
if hasattr(obj_class, 'OUTPUT_NODE') and obj_class.OUTPUT_NODE == True:
|
if hasattr(obj_class, 'OUTPUT_NODE') and obj_class.OUTPUT_NODE == True:
|
||||||
info['output_node'] = True
|
info['output_node'] = True
|
||||||
|
|||||||
@ -1277,6 +1277,7 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
node.prototype.comfyClass = nodeData.name;
|
node.prototype.comfyClass = nodeData.name;
|
||||||
|
node.prototype.ui_output = nodeData.ui_output;
|
||||||
|
|
||||||
this.#addNodeContextMenuHandler(node);
|
this.#addNodeContextMenuHandler(node);
|
||||||
this.#addDrawBackgroundHandler(node, app);
|
this.#addDrawBackgroundHandler(node, app);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user