Files
2024-12-16 17:48:49 +08:00

115 lines
2.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import sys
import os
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", {"forceInput": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
OUTPUT_NODE = True
FUNCTION = "show_text"
CATEGORY = "MK/text"
def show_text(self, text):
return {"ui": {"string": [text,]}, "result": (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", {"default": ""}),
"new_string": ("STRING", {"default": ""}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "replace_text"
CATEGORY = "MK/text"
def replace_text(self, text, old_string, new_string):
old_strings = old_string.split(',')
for old in old_strings:
text = text.replace(old, new_string)
return (text,)