From e8cbf51149e05324b82799f15bb8394cb034c124 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Thu, 30 Mar 2023 19:37:05 +0100 Subject: [PATCH] added show text node --- show-text/showText.js | 35 +++++++++++++++++++++++++++++++++++ show-text/show_text.py | 20 ++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 show-text/showText.js create mode 100644 show-text/show_text.py diff --git a/show-text/showText.js b/show-text/showText.js new file mode 100644 index 0000000..bc20af9 --- /dev/null +++ b/show-text/showText.js @@ -0,0 +1,35 @@ +import { app } from "/scripts/app.js"; +import { ComfyWidgets } from "/scripts/widgets.js"; + +// Displays input text on a node + +app.registerExtension({ + name: "pysssss.ShowText", + async beforeRegisterNodeDef(nodeType, nodeData, app) { + if (nodeData.name === "ShowText") { + // When the node is created we want to add a readonly text widget to display the text + const onNodeCreated = nodeType.prototype.onNodeCreated; + nodeType.prototype.onNodeCreated = function () { + const r = onNodeCreated?.apply(this, arguments); + + const w = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app).widget; + w.inputEl.readOnly = true; + w.inputEl.style.opacity = 0.6; + + return r; + }; + + // 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); + + this.widgets[0].value = message.text; + + if (this.size[1] < 180) { + this.setSize([this.size[0], 180]); + } + }; + } + }, +}); \ No newline at end of file diff --git a/show-text/show_text.py b/show-text/show_text.py new file mode 100644 index 0000000..d2a11bf --- /dev/null +++ b/show-text/show_text.py @@ -0,0 +1,20 @@ +class ShowText: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "text": ("STRING", {"forceInput": True}), + }} + + RETURN_TYPES = ("STRING",) + FUNCTION = "notify" + OUTPUT_NODE = True + + CATEGORY = "utils" + + def notify(self, text): + return {"ui": { "text": text }, "result": (text,)} + + +NODE_CLASS_MAPPINGS = { + "ShowText": ShowText, +} \ No newline at end of file