fix
This commit is contained in:
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -5,24 +5,28 @@ sys.path.append(
|
||||
os.path.dirname(os.path.abspath(__file__))
|
||||
)
|
||||
|
||||
# DisplayText node is forked from AlekPet,ZHO-ZHO-ZHO,thanks to AlekPet,ZHO-ZHO-ZHO!
|
||||
class ShowText:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING"),
|
||||
"text": ("STRING", {"forceInput": True}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("text",)
|
||||
OUTPUT_NODE = True
|
||||
|
||||
FUNCTION = "show_text"
|
||||
CATEGORY = "MK/text"
|
||||
|
||||
def show_text(self, text):
|
||||
return {"ui": {"text": [text,]}}
|
||||
return {"ui": {"string": [text,]}, "result": (text,)}
|
||||
|
||||
class CombinationText:
|
||||
def __init__(self):
|
||||
@@ -89,8 +93,8 @@ class ReplaceText:
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"multiline": True}),
|
||||
"old_string": ("STRING",),
|
||||
"new_string": ("STRING",),
|
||||
"old_string": ("STRING", {"default": ""}),
|
||||
"new_string": ("STRING", {"default": ""}),
|
||||
},
|
||||
}
|
||||
|
||||
+34
-4
@@ -1,10 +1,40 @@
|
||||
from .node import *
|
||||
from .MKTextNode import *
|
||||
from .install import *
|
||||
import filecmp
|
||||
import shutil
|
||||
import __main__
|
||||
|
||||
python = sys.executable
|
||||
|
||||
|
||||
extentions_folder = os.path.join(os.path.dirname(os.path.realpath(__main__.__file__)),
|
||||
"web" + os.sep + "extensions" + os.sep + "Comfy-MK")
|
||||
javascript_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), "js")
|
||||
|
||||
if not os.path.exists(extentions_folder):
|
||||
os.mkdir(extentions_folder)
|
||||
|
||||
result = filecmp.dircmp(javascript_folder, extentions_folder)
|
||||
|
||||
if result.left_only or result.diff_files:
|
||||
print('Update to javascripts files detected')
|
||||
file_list = list(result.left_only)
|
||||
file_list.extend(x for x in result.diff_files if x not in file_list)
|
||||
|
||||
for file in file_list:
|
||||
print(f'Copying {file} to extensions folder')
|
||||
src_file = os.path.join(javascript_folder, file)
|
||||
dst_file = os.path.join(extentions_folder, file)
|
||||
if os.path.exists(dst_file):
|
||||
os.remove(dst_file)
|
||||
shutil.copy(src_file, dst_file)
|
||||
|
||||
|
||||
# A dictionary that contains all nodes you want to export with their names
|
||||
# NOTE: names should be globally unique
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"Show Text": ShowText
|
||||
"ShowText": ShowText,
|
||||
"CombinationText": CombinationText,
|
||||
"PlaceholderText": PlaceholderText,
|
||||
"ReplaceText": ReplaceText
|
||||
}
|
||||
|
||||
__all__ = ['NODE_CLASS_MAPPINGS']
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
import { app } from "/scripts/app.js";
|
||||
import { ComfyWidgets } from "/scripts/widgets.js";
|
||||
|
||||
app.registerExtension({
|
||||
name: "Comfy.MKTextNode",
|
||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||
if (nodeData.name === "ShowText" && nodeData.category === "MK/text") {
|
||||
// Node Created
|
||||
const onNodeCreated = nodeType.prototype.onNodeCreated;
|
||||
nodeType.prototype.onNodeCreated = function () {
|
||||
const ret = onNodeCreated
|
||||
? onNodeCreated.apply(this, arguments)
|
||||
: undefined;
|
||||
|
||||
let ShowText = app.graph._nodes.filter(
|
||||
(wi) => wi.type == nodeData.name
|
||||
),
|
||||
nodeName = `${nodeData.name}_${ShowText.length}`;
|
||||
|
||||
const wi = ComfyWidgets.STRING(
|
||||
this,
|
||||
nodeName,
|
||||
[
|
||||
"STRING",
|
||||
{
|
||||
default: "",
|
||||
placeholder: "Text output...",
|
||||
multiline: true,
|
||||
},
|
||||
],
|
||||
app
|
||||
);
|
||||
wi.widget.inputEl.readOnly = true;
|
||||
return ret;
|
||||
};
|
||||
// Function set value
|
||||
const outSet = function (texts) {
|
||||
if (texts.length > 0) {
|
||||
let widget_id = this?.widgets.findIndex(
|
||||
(w) => w.type == "customtext"
|
||||
);
|
||||
|
||||
if (Array.isArray(texts))
|
||||
texts = texts
|
||||
.filter((word) => word.trim() !== "")
|
||||
.map((word) => word.trim())
|
||||
.join(" ");
|
||||
|
||||
this.widgets[widget_id].value = texts;
|
||||
app.graph.setDirtyCanvas(true);
|
||||
}
|
||||
};
|
||||
|
||||
// onExecuted
|
||||
const onExecuted = nodeType.prototype.onExecuted;
|
||||
nodeType.prototype.onExecuted = function (texts) {
|
||||
onExecuted?.apply(this, arguments);
|
||||
outSet.call(this, texts?.string);
|
||||
};
|
||||
// onConfigure
|
||||
const onConfigure = nodeType.prototype.onConfigure;
|
||||
nodeType.prototype.onConfigure = function (w) {
|
||||
onConfigure?.apply(this, arguments);
|
||||
if (w?.widgets_values?.length) {
|
||||
outSet.call(this, w.widgets_values);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user