From 7f0aa1f35690342d52f2e40479bc888781ccac89 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Wed, 30 Aug 2023 13:22:11 +0100 Subject: [PATCH] Save text to metadata --- py/show_text.py | 19 +++++++++++++++---- web/js/showText.js | 27 ++++++++++++++++++++------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/py/show_text.py b/py/show_text.py index 2238d71..f0fb564 100644 --- a/py/show_text.py +++ b/py/show_text.py @@ -1,9 +1,15 @@ class ShowText: @classmethod def INPUT_TYPES(s): - return {"required": { - "text": ("STRING", {"forceInput": True}), - }} + return { + "required": { + "text": ("STRING", {"forceInput": True}), + }, + "hidden": { + "unique_id": "UNIQUE_ID", + "extra_pnginfo": "EXTRA_PNGINFO", + }, + } INPUT_IS_LIST = True RETURN_TYPES = ("STRING",) @@ -13,7 +19,12 @@ class ShowText: CATEGORY = "utils" - def notify(self, text): + def notify(self, text, unique_id = None, extra_pnginfo=None): + if unique_id and extra_pnginfo and "workflow" in extra_pnginfo[0]: + workflow = extra_pnginfo[0]["workflow"] + node = next((x for x in workflow["nodes"] if str(x["id"]) == unique_id[0]), None) + if node: + node["widgets_values"] = [text] return {"ui": {"text": text}, "result": (text,)} diff --git a/web/js/showText.js b/web/js/showText.js index f52b2b2..d70d68b 100644 --- a/web/js/showText.js +++ b/web/js/showText.js @@ -7,11 +7,7 @@ app.registerExtension({ name: "pysssss.ShowText", async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeData.name === "ShowText|pysssss") { - // When the node is executed we will be sent the input text, display this in the widget - const onExecuted = nodeType.prototype.onExecuted; - nodeType.prototype.onExecuted = function (message) { - onExecuted?.apply(this, arguments); - + function populate(text) { if (this.widgets) { const pos = this.widgets.findIndex((w) => w.name === "text"); if (pos !== -1) { @@ -22,14 +18,31 @@ app.registerExtension({ } } - for (const list of message.text) { + for (const list of text) { const w = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget; w.inputEl.readOnly = true; w.inputEl.style.opacity = 0.6; w.value = list; } - this.onResize?.(this.size); + requestAnimationFrame(() => { + this.onResize?.(this.computeSize()); + }); + } + + // When the node is executed we will be sent the input text, display this in the widget + const onExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = function (message) { + onExecuted?.apply(this, arguments); + populate.call(this, message.text); + }; + + const onConfigure = nodeType.prototype.onConfigure; + nodeType.prototype.onConfigure = function () { + onConfigure?.apply(this, arguments); + if (this.widgets_values?.length) { + populate.call(this, this.widgets_values); + } }; } },