From 6db26caba1b878198a7e9ca6f86d8c85c5ee5b32 Mon Sep 17 00:00:00 2001 From: Thomas Ward Date: Thu, 27 Jun 2024 16:41:57 -0400 Subject: [PATCH 1/4] Add constant primitive datatype nodes --- comfy_extras/nodes_constant_values,.py | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 comfy_extras/nodes_constant_values,.py diff --git a/comfy_extras/nodes_constant_values,.py b/comfy_extras/nodes_constant_values,.py new file mode 100644 index 000000000..f5dc30413 --- /dev/null +++ b/comfy_extras/nodes_constant_values,.py @@ -0,0 +1,79 @@ +class _CONSTANT_BASE: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s) -> dict: + raise NotImplementedError + + RETURN_TYPES: tuple = () + RETURN_NAMES: tuple = () + + CATEGORY: str = "constants" + + FUNCTION: str = "process" + + OUTPUT_NODE: bool = False + + def process(self, value) -> tuple: + return (value,) + + +class ConstantFloat(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("FLOAT", {"default": 0.0}) + } + } + + RETURN_TYPES = ("FLOAT",) + RETURN_NAMES = ("float",) + + +class ConstantInteger(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("INT", {"default": 0}) + } + } + + RETURN_TYPES = ("INT",) + RETURN_NAMES = ("int",) + + +class ConstantString(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required" : { + "value": ("STRING", {"multiline": False}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +class ConstantStringMultiline(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("STRING", {"multiline": True}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +NODE_CLASS_MAPPINGS = { + "ConstantFloat": ConstantFloat, + "ConstantInteger": ConstantInteger, + "ConstantString": ConstantString, + "ConstantStringMultiline": ConstantStringMultiline, +} From 44fd5f2cbe07e5ff3489c62693cb81d21597b207 Mon Sep 17 00:00:00 2001 From: Thomas Ward Date: Thu, 27 Jun 2024 16:43:27 -0400 Subject: [PATCH 2/4] Add constant values nodes to comfy_extras importer --- nodes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nodes.py b/nodes.py index 99645b81c..e360bb08c 100644 --- a/nodes.py +++ b/nodes.py @@ -1992,6 +1992,7 @@ def init_custom_nodes(): "nodes_audio.py", "nodes_sd3.py", "nodes_gits.py", + "nodes_constant_values.py" ] import_failed = [] From 691caa0529411a0e503a7954bba65efbe255dc80 Mon Sep 17 00:00:00 2001 From: Thomas Ward Date: Tue, 24 Sep 2024 11:41:46 -0400 Subject: [PATCH 3/4] Rename nodes_constant_values,.py to nodes_constant_values.py Typos in original branch --- .../{nodes_constant_values,.py => nodes_constant_values.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename comfy_extras/{nodes_constant_values,.py => nodes_constant_values.py} (100%) diff --git a/comfy_extras/nodes_constant_values,.py b/comfy_extras/nodes_constant_values.py similarity index 100% rename from comfy_extras/nodes_constant_values,.py rename to comfy_extras/nodes_constant_values.py From 6bfe8ba1f826eba98e2d1c51bc8bb4fe0f306855 Mon Sep 17 00:00:00 2001 From: Thomas Ward Date: Tue, 24 Sep 2024 12:24:08 -0400 Subject: [PATCH 4/4] Add dynamicInputs = FALSE nodes The comments on the original PR suggested it'd be nice to have nodes with dynamicInputs set to False for both of the String nodes. As such, I've created a dedicated node, and set the other string constants to dynamicInputs = True. --- comfy_extras/nodes_constant_values.py | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/comfy_extras/nodes_constant_values.py b/comfy_extras/nodes_constant_values.py index f5dc30413..259d23697 100644 --- a/comfy_extras/nodes_constant_values.py +++ b/comfy_extras/nodes_constant_values.py @@ -50,7 +50,7 @@ class ConstantString(_CONSTANT_BASE): def INPUT_TYPES(s) -> dict: return { "required" : { - "value": ("STRING", {"multiline": False}) + "value": ("STRING", {"multiline": False, "dynamicPrompts": True}) } } @@ -63,7 +63,33 @@ class ConstantStringMultiline(_CONSTANT_BASE): def INPUT_TYPES(s) -> dict: return { "required": { - "value": ("STRING", {"multiline": True}) + "value": ("STRING", {"multiline": True, "dynamicPrompts": True}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +class ConstantNonDynamicString(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required" : { + "value": ("STRING", {"multiline": False, "dynamicPrompts": False}) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("string",) + + +class ConstantNonDynamicStringMultiline(_CONSTANT_BASE): + @classmethod + def INPUT_TYPES(s) -> dict: + return { + "required": { + "value": ("STRING", {"multiline": True, "dynamicPrompts": False}) } } @@ -76,4 +102,6 @@ NODE_CLASS_MAPPINGS = { "ConstantInteger": ConstantInteger, "ConstantString": ConstantString, "ConstantStringMultiline": ConstantStringMultiline, + "ConstantNonDynamicString": ConstantNonDynamicString, + "ConstantNonDynamicStringMultiline": ConstantNonDynamicStringMultiline }