handle widget too

This commit is contained in:
MaraScott 2024-05-21 23:28:34 +02:00
parent 2831e1fb0d
commit ffd49186de
6 changed files with 41 additions and 31 deletions

View File

@ -47,8 +47,10 @@ MAX_RESOLUTION=16384
class CLIPTextEncode: class CLIPTextEncode:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": {"text": ("STRING", {"multiline": True, "dynamicPrompts": True}), "clip": ("CLIP", )}} return {"required": {"text": ("STRING", {"multiline": True, "dynamicPrompts": True, "label": "text"}), "clip": ("CLIP", {"label": "text"})}}
RETURN_TYPES = ("CONDITIONING",) RETURN_TYPES = ("CONDITIONING",)
RETURN_NAMES = ("CONDITIONING",)
RETURN_LABELS = ("conditioning",)
FUNCTION = "encode" FUNCTION = "encode"
CATEGORY = "conditioning" CATEGORY = "conditioning"
@ -258,8 +260,10 @@ class ConditioningSetTimestepRange:
class VAEDecode: class VAEDecode:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { "samples": ("LATENT", ), "vae": ("VAE", )}} return {"required": { "samples": ("LATENT", { "label": "latent"}), "vae": ("VAE", {"label": "vae"})}}
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("IMAGE",)
RETURN_LABELS = ("image",)
FUNCTION = "decode" FUNCTION = "decode"
CATEGORY = "latent" CATEGORY = "latent"
@ -492,6 +496,8 @@ class CheckpointLoader:
return {"required": { "config_name": (folder_paths.get_filename_list("configs"), ), return {"required": { "config_name": (folder_paths.get_filename_list("configs"), ),
"ckpt_name": (folder_paths.get_filename_list("checkpoints"), )}} "ckpt_name": (folder_paths.get_filename_list("checkpoints"), )}}
RETURN_TYPES = ("MODEL", "CLIP", "VAE") RETURN_TYPES = ("MODEL", "CLIP", "VAE")
RETURN_NAMES = ("MODEL", "CLIP", "VAE")
RETURN_LABELS = ("model", "clip", "vae")
FUNCTION = "load_checkpoint" FUNCTION = "load_checkpoint"
CATEGORY = "advanced/loaders" CATEGORY = "advanced/loaders"
@ -504,9 +510,11 @@ class CheckpointLoader:
class CheckpointLoaderSimple: class CheckpointLoaderSimple:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ), return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), { "label": "model name"}),
}} }}
RETURN_TYPES = ("MODEL", "CLIP", "VAE") RETURN_TYPES = ("MODEL", "CLIP", "VAE")
RETURN_NAMES = ("MODEL", "CLIP", "VAE")
RETURN_LABELS = ("model", "clip", "vae")
FUNCTION = "load_checkpoint" FUNCTION = "load_checkpoint"
CATEGORY = "loaders" CATEGORY = "loaders"
@ -999,8 +1007,10 @@ class EmptyLatentImage:
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { "width": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}), return {"required": { "width": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}),
"height": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}), "height": ("INT", {"default": 512, "min": 16, "max": MAX_RESOLUTION, "step": 8}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 4096})}} "batch_size": ("INT", {"default": 1, "min": 1, "max": 4096, "label": "batch size"})}}
RETURN_TYPES = ("LATENT",) RETURN_TYPES = ("LATENT",)
RETURN_NAMES = ("LATENT",)
RETURN_LABELS = ("latent",)
FUNCTION = "generate" FUNCTION = "generate"
CATEGORY = "latent" CATEGORY = "latent"
@ -1322,20 +1332,22 @@ class KSampler:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": return {"required":
{"model": ("MODEL",), {"model": ("MODEL", { "label": "model" }),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "label": "seed"}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}), "steps": ("INT", {"default": 20, "min": 1, "max": 10000, "label": "steps"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.1, "round": 0.01}), "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.1, "round": 0.01, "label": "steps"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ), "sampler_name": (comfy.samplers.KSampler.SAMPLERS, { "label": "sampler name" } ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ), "scheduler": (comfy.samplers.KSampler.SCHEDULERS, { "label": "scheduler" } ),
"positive": ("CONDITIONING", ), "positive": ("CONDITIONING", { "label": "positive" }),
"negative": ("CONDITIONING", ), "negative": ("CONDITIONING", { "label": "negative" }),
"latent_image": ("LATENT", ), "latent_image": ("LATENT", {"label": "latent"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}), "denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "label": "denoise"}),
} }
} }
RETURN_TYPES = ("LATENT",) RETURN_TYPES = ("LATENT",)
RETURN_NAMES = ("LATENT",)
RETURN_LABELS = ("latent",)
FUNCTION = "sample" FUNCTION = "sample"
CATEGORY = "sampling" CATEGORY = "sampling"
@ -1437,7 +1449,7 @@ class PreviewImage(SaveImage):
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": return {"required":
{"images": ("IMAGE", ), }, {"images": ("IMAGE", {"label": "image"}), },
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"}, "hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
} }

View File

@ -394,6 +394,7 @@ class PromptServer():
info['output'] = obj_class.RETURN_TYPES info['output'] = obj_class.RETURN_TYPES
info['output_is_list'] = obj_class.OUTPUT_IS_LIST if hasattr(obj_class, 'OUTPUT_IS_LIST') else [False] * len(obj_class.RETURN_TYPES) info['output_is_list'] = obj_class.OUTPUT_IS_LIST if hasattr(obj_class, 'OUTPUT_IS_LIST') else [False] * len(obj_class.RETURN_TYPES)
info['output_name'] = obj_class.RETURN_NAMES if hasattr(obj_class, 'RETURN_NAMES') else info['output'] info['output_name'] = obj_class.RETURN_NAMES if hasattr(obj_class, 'RETURN_NAMES') else info['output']
info['output_label'] = obj_class.RETURN_LABELS if hasattr(obj_class, 'RETURN_LABELS') else info['output_name']
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 ''

View File

@ -75,7 +75,7 @@ function convertToInput(node, widget, config) {
const sz = node.size; const sz = node.size;
node.addInput(widget.name, type, { node.addInput(widget.name, type, {
widget: { name: widget.name, [GET_CONFIG]: () => config }, widget: { name: widget.name, [GET_CONFIG]: () => config },
label: widget.element?.placeholder ? widget.element?.placeholder : widget.name label: widget.element?.placeholder || widget?.label || widget.name
}); });
for (const widget of node.widgets) { for (const widget of node.widgets) {
@ -290,14 +290,14 @@ app.registerExtension({
} }
if (w.type === CONVERTED_TYPE) { if (w.type === CONVERTED_TYPE) {
toWidget.push({ toWidget.push({
content: `Convert ${w.name} to widget`, content: `Convert '${w?.label || w.name}' to widget`,
callback: () => convertToWidget(this, w), callback: () => convertToWidget(this, w),
}); });
} else { } else {
const config = getConfig.call(this, w.name) ?? [w.type, w.options || {}]; const config = getConfig.call(this, w.name) ?? [w.type, w.options || {}];
if (isConvertableWidget(w, config)) { if (isConvertableWidget(w, config)) {
toInput.push({ toInput.push({
content: `Convert ${w.name} to input`, content: `Convert '${w?.label || w.name}' to input`,
callback: () => convertToInput(this, w, config), callback: () => convertToInput(this, w, config),
}); });
} }

View File

@ -3758,6 +3758,7 @@
var w = { var w = {
type: type.toLowerCase(), type: type.toLowerCase(),
name: name, name: name,
label: options?.label || name,
value: value, value: value,
callback: callback, callback: callback,
options: options || {} options: options || {}

View File

@ -1676,15 +1676,8 @@ export class ComfyApp {
for (const o in nodeData["output"]) { for (const o in nodeData["output"]) {
let output = nodeData["output"][o]; let output = nodeData["output"][o];
if(output instanceof Array) output = "COMBO"; if(output instanceof Array) output = "COMBO";
let outputName = output; const outputName = nodeData["output_name"][o] || output;
let outputLabel = outputName; const outputLabel = nodeData["output_label"][o] || outputName;
if(nodeData["output_name"][o] instanceof Array) {
outputName = nodeData["output_name"][o][0] || output;
outputLabel = nodeData["output_name"][o][1]
} else {
outputName = nodeData["output_name"][o] || output;
outputLabel = outputName
}
const outputShape = nodeData["output_is_list"][o] ? LiteGraph.GRID_SHAPE : LiteGraph.CIRCLE_SHAPE ; const outputShape = nodeData["output_is_list"][o] ? LiteGraph.GRID_SHAPE : LiteGraph.CIRCLE_SHAPE ;
this.addOutput(outputName, output, { shape: outputShape, label: outputLabel }); this.addOutput(outputName, output, { shape: outputShape, label: outputLabel });
} }

View File

@ -8,7 +8,7 @@ export function updateControlWidgetLabel(widget) {
if (controlValueRunBefore) { if (controlValueRunBefore) {
[find, replacement] = [replacement, find] [find, replacement] = [replacement, find]
} }
widget.label = (widget.label ?? widget.name).replace(find, replacement); widget.label = (widget.label ?? widget.name).replace(find, replacement).replace(/_/g, " ");
} }
const IS_CONTROL_WIDGET = Symbol(); const IS_CONTROL_WIDGET = Symbol();
@ -222,6 +222,8 @@ function createIntWidget(node, inputName, inputData, app, isSeedInput) {
let widgetType = isSlider(inputData[1]["display"], app); let widgetType = isSlider(inputData[1]["display"], app);
const { val, config } = getNumberDefaults(inputData, 1, 0, true); const { val, config } = getNumberDefaults(inputData, 1, 0, true);
Object.assign(config, { precision: 0 }); Object.assign(config, { precision: 0 });
const inputLabel = inputData[1]?.label || inputName;
Object.assign(config, { label: inputLabel });
return { return {
widget: node.addWidget( widget: node.addWidget(
widgetType, widgetType,
@ -366,7 +368,8 @@ export const ComfyWidgets = {
if (inputData[1] && inputData[1].default) { if (inputData[1] && inputData[1].default) {
defaultValue = inputData[1].default; defaultValue = inputData[1].default;
} }
const res = { widget: node.addWidget("combo", inputName, defaultValue, () => {}, { values: type }) }; const inputLabel = inputData[1]?.label || inputName
const res = { widget: node.addWidget("combo", inputName, defaultValue, () => {}, { values: type, label: inputLabel }) };
if (inputData[1]?.control_after_generate) { if (inputData[1]?.control_after_generate) {
res.widget.linkedWidgets = addValueControlWidgets(node, res.widget, undefined, undefined, inputData); res.widget.linkedWidgets = addValueControlWidgets(node, res.widget, undefined, undefined, inputData);
} }