76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
# switch_path_lazy.py
|
|
|
|
from server import PromptServer
|
|
|
|
class AnyType(str):
|
|
"""Wildcard type to accept any input/output type"""
|
|
def __ne__(self, __value: object) -> bool:
|
|
return False
|
|
def __eq__(self, __value: object) -> bool:
|
|
return True
|
|
def __str__(self):
|
|
return "*"
|
|
|
|
ANY_TYPE = AnyType("*")
|
|
|
|
|
|
class SwitchPathLazy:
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"state": ("BOOLEAN", {"default": False}),
|
|
"on_true": (ANY_TYPE, {"lazy": True}),
|
|
"on_false": (ANY_TYPE, {"lazy": True}),
|
|
},
|
|
"hidden": {"unique_id": "UNIQUE_ID"},
|
|
}
|
|
|
|
RETURN_TYPES = (ANY_TYPE,)
|
|
RETURN_NAMES = ("output",)
|
|
FUNCTION = "execute"
|
|
CATEGORY = "flow control"
|
|
|
|
def check_lazy_status(self, state, on_true=None, on_false=None, **kwargs):
|
|
"""Tell ComfyUI which lazy input is required"""
|
|
if state:
|
|
return ["on_true"]
|
|
else:
|
|
return ["on_false"]
|
|
|
|
def execute(self, state, on_true=None, on_false=None, unique_id=None, **kwargs):
|
|
# Determine active path
|
|
active_path = "on_true" if state else "on_false"
|
|
|
|
# --- Live display under the node (white text, like your example) ---
|
|
if unique_id:
|
|
try:
|
|
html_text = (
|
|
f"<b style='color:white;'>State:</b> <b style='color:#a0ffa0;'>{str(state).upper()}</b><br>"
|
|
f"<b style='color:white;'>Active Path:</b> <b style='color:#a0ffa0;'>{active_path}</b><br>"
|
|
f"<b style='color:white;'>Lazy Skip:</b> <span style='color:#a0ffa0;'>inactive branch skipped</span>"
|
|
)
|
|
PromptServer.instance.send_progress_text(html_text, unique_id)
|
|
except Exception:
|
|
pass # Silent fail if send_progress_text not available
|
|
|
|
# Return selected branch
|
|
if state:
|
|
return (on_true,)
|
|
else:
|
|
return (on_false,)
|
|
|
|
|
|
# Node registration
|
|
NODE_CLASS_MAPPINGS = {
|
|
"SwitchPathLazy": SwitchPathLazy
|
|
}
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"SwitchPathLazy": "Switch Path (Lazy + Info)"
|
|
}
|
|
|
|
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
|
|
|