Files
0velia-ComfyUI-Dynamic-Drop…/__init__.py
T
2026-07-11 01:55:15 +07:00

72 lines
2.7 KiB
Python

import os
NODE_DIR = os.path.dirname(os.path.abspath(__file__))
LISTS_DIR = os.path.join(NODE_DIR, "lists")
class ComfyUIDynamicDropdownsPro:
@classmethod
def INPUT_TYPES(cls):
# Default fallback options if text files aren't parsed yet
styles = ["Amateur Candid", "Studio Cinematic", "Vintage Film"]
lighting = ["Soft Natural", "Harsh Neon", "Golden Hour"]
return {
"required": {
"demo_style": (styles,),
"demo_lighting": (lighting,),
},
"optional": {
"input_string": ("STRING", {"forceInput": True}),
"clip": ("CLIP",),
}
}
RETURN_TYPES = ("STRING", "CONDITIONING")
RETURN_NAMES = ("PROMPT_STRING", "CONDITIONING")
FUNCTION = "process_prompt"
CATEGORY = "Custom Selection"
def process_prompt(self, demo_style, demo_lighting, input_string="", clip=None, **kwargs):
clean_choices = []
# 1. Inject the daisy-chained input string first if present
if input_string and str(input_string).strip():
clean_choices.append(str(input_string).strip())
# 2. Add the base required dropdown values
if demo_style and demo_style != "Select...":
clean_choices.append(str(demo_style).strip())
if demo_lighting and demo_lighting != "Select...":
clean_choices.append(str(demo_lighting).strip())
# 3. Dynamically append any extra custom slots generated by the frontend JS buttons
for key in sorted(kwargs.keys()):
value = kwargs[key]
if value and str(value).strip() and value != "Select...":
clean_choices.append(str(value).strip())
# 4. Concatenate everything with clean single commas
final_prompt = ", ".join([c for c in clean_choices if c])
# 5. Handle the optional CLIP conditioning safely without crashing if unlinked
if clip is not None:
tokens = clip.tokenize(final_prompt)
cond, pooled = clip.encode_from_tokens(tokens, return_pooled=True)
conditioning_output = [[cond, {"pooled_output": pooled}]]
else:
conditioning_output = None
return (final_prompt, conditioning_output)
# --- REGISTRATION CONFIGURATION ---
# Crucial link that tells ComfyUI to look inside the /js folder for UI overrides
WEB_DIRECTORY = "./js"
NODE_CLASS_MAPPINGS = {
"ComfyUI_Dynamic_Dropdowns_Demo": ComfyUIDynamicDropdownsPro
}
NODE_DISPLAY_NAME_MAPPINGS = {
"ComfyUI_Dynamic_Dropdowns_Demo": "🎭 Dynamic Dropdowns (Pro Mode)"