commit 5aaf39c888530a42c077d80872f1efe72074a8ba Author: 蔡孟昆 <865240848@qq.com> Date: Sat Mar 16 11:01:33 2024 +0800 text diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/ComfyUI_Text.iml b/.idea/ComfyUI_Text.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/ComfyUI_Text.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..db8786c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..55ebf47 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..6f490c8 --- /dev/null +++ b/__init__.py @@ -0,0 +1,12 @@ +from .node import * +from .install import * + +# 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 +} + +__all__ = ['NODE_CLASS_MAPPINGS'] + + diff --git a/install.py b/install.py new file mode 100644 index 0000000..2c14be2 --- /dev/null +++ b/install.py @@ -0,0 +1,17 @@ +import sys +import os.path +import subprocess + +custom_nodes_path = os.path.dirname(os.path.abspath(__file__)) + +def build_pip_install_cmds(args): + if "python_embeded" in sys.executable or "python_embedded" in sys.executable: + return [sys.executable, '-s', '-m', 'pip', 'install'] + args + else: + return [sys.executable, '-m', 'pip', 'install'] + args + +def ensure_package(): + cmds = build_pip_install_cmds(['-r', 'requirements.txt']) + subprocess.run(cmds, cwd=custom_nodes_path) + +ensure_package() \ No newline at end of file diff --git a/node.py b/node.py new file mode 100644 index 0000000..3134a94 --- /dev/null +++ b/node.py @@ -0,0 +1,108 @@ +import sys +import os + +sys.path.append( + os.path.dirname(os.path.abspath(__file__)) +) + +class ShowText: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + + return { + "required": { + "text": ("STRING"), + }, + } + + FUNCTION = "show_text" + CATEGORY = "MK/text" + + def show_text(self, text): + return {"ui": {"text": [text,]}} + +class CombinationText: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text1": ("STRING", {"multiline": True}), + "text2": ("STRING", {"multiline": True}), + "connector": ("STRING", {"default": ","}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + + FUNCTION = "combination_text" + + CATEGORY = "MK/text" + + def combination_text(self, text1, text2, connector): + texts = [text1, text2] + combined_text = connector.join(texts) + return (combined_text,) + +class PlaceholderText: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text1": ("STRING", {"multiline": True}), + "text2": ("STRING", {"multiline": True}), + "placeholder": ("STRING", {"default": "$1,$2"}), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + + FUNCTION = "placeholder_text" + + CATEGORY = "MK/text" + + def placeholder_text(self, text1, text2, placeholder): + replacements = {"$1": text1, "$2": text2} + + for old, new in replacements.items(): + placeholder = placeholder.replace(old, new) + + return (placeholder,) + + +class ReplaceText: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"multiline": True}), + "old_string": ("STRING",), + "new_string": ("STRING",), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + + FUNCTION = "replace_text" + + CATEGORY = "MK/text" + + def replace_text(self, text, old_string, new_string): + + text = text.replace(old_string, new_string) + + return (text,) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29