From 106bc9b32ab8ed422afb80a6328591ad0fc3dc03 Mon Sep 17 00:00:00 2001 From: bigcat88 Date: Wed, 16 Jul 2025 11:25:02 +0300 Subject: [PATCH] V3: PreviewAny node --- comfy_extras/v3/nodes_preview_any.py | 47 ++++++++++++++++++++++++++++ nodes.py | 1 + 2 files changed, 48 insertions(+) create mode 100644 comfy_extras/v3/nodes_preview_any.py diff --git a/comfy_extras/v3/nodes_preview_any.py b/comfy_extras/v3/nodes_preview_any.py new file mode 100644 index 000000000..76b461ad9 --- /dev/null +++ b/comfy_extras/v3/nodes_preview_any.py @@ -0,0 +1,47 @@ +from __future__ import annotations + +import json + +from comfy_api.v3 import io, ui + + +class PreviewAny(io.ComfyNodeV3): + """Originally implement from https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py + + upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes""" + + @classmethod + def define_schema(cls): + return io.SchemaV3( + node_id="PreviewAny_V3", # frontend expects "PreviewAny" to work + display_name="Preview Any _V3", # frontend ignores "display_name" for this node + description="Preview any type of data by converting it to a readable text format.", + category="utils", + inputs=[ + io.AnyType.Input("source"), # TODO: does not work currently, as `io.AnyType` does not define __ne__ + ], + is_output_node=True, + ) + + @classmethod + def execute(cls, source=None) -> io.NodeOutput: + value = "None" + if isinstance(source, str): + value = source + elif isinstance(source, (int, float, bool)): + value = str(source) + elif source is not None: + try: + value = json.dumps(source) + except Exception: + try: + value = str(source) + except Exception: + value = "source exists, but could not be serialized." + + return io.NodeOutput(ui=ui.PreviewText(value)) + + +NODES_LIST: list[type[io.ComfyNodeV3]] = [ + PreviewAny, +] diff --git a/nodes.py b/nodes.py index 11a1b85cb..51d423053 100644 --- a/nodes.py +++ b/nodes.py @@ -2303,6 +2303,7 @@ def init_builtin_extra_nodes(): "v3/nodes_controlnet.py", "v3/nodes_images.py", "v3/nodes_mask.py", + "v3/nodes_preview_any.py", "v3/nodes_primitive.py", "v3/nodes_webcam.py", "v3/nodes_stable_cascade.py",