diff --git a/__init__.py b/__init__.py index 7469a95..7e160ac 100644 --- a/__init__.py +++ b/__init__.py @@ -5,7 +5,7 @@ @description: A custom node that pauses the flow while you choose which image or images to pass on to the rest of the workflow. Simplified and improved version of cg-image-picker. """ -from .image_filter import ImageFilter, TextImageFilter, MaskImageFilter +from .image_filter import ImageFilter, TextImageFilter, MaskImageFilter, TextImageFilterWithExtras VERSION = "1.0.1" WEB_DIRECTORY = "./js" @@ -13,6 +13,7 @@ WEB_DIRECTORY = "./js" NODE_CLASS_MAPPINGS= { "Image Filter": ImageFilter, "Text Image Filter": TextImageFilter, + "Text Image Filter with Extras": TextImageFilterWithExtras, "Mask Image Filter": MaskImageFilter } diff --git a/image_filter.py b/image_filter.py index 2b3267e..8ffaad1 100644 --- a/image_filter.py +++ b/image_filter.py @@ -114,6 +114,40 @@ class TextImageFilter(PreviewImage): return (image, response) +class TextImageFilterWithExtras(PreviewImage): + RETURN_TYPES = ("IMAGE","STRING","STRING","STRING","STRING") + RETURN_NAMES = ("image","text","extra1","extra2","extra3") + FUNCTION = "func" + CATEGORY = "image_filter" + OUTPUT_NODE = False + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "image" : ("IMAGE", ), + "text" : ("STRING", {"default":""}), + "extra1" : ("STRING", {"default":""}), + "extra2" : ("STRING", {"default":""}), + "extra3" : ("STRING", {"default":""}), + "timeout": ("INT", {"default": 60, "tooltip": "Timeout in seconds."}), + }, + "hidden": HIDDEN, + } + + @classmethod + def IS_CHANGED(cls, **kwargs): + return float("NaN") + + def func(self, image, text, extra1, extra2, extra3, timeout, uid, **kwargs): + urls:list[str] = self.save_images(images=image, **kwargs)['ui']['images'] + PromptServer.instance.send_sync("cg-image-filter-images", {"uid": uid, "urls":urls, "text":text, "extras":[extra1, extra2, extra3]}) + + response = wait(timeout) + response = response.split(",") if response else [""]*4 + + return (image, *response) + class MaskImageFilter(PreviewImage, LoadImage): RETURN_TYPES = ("IMAGE","MASK") RETURN_NAMES = ("image","mask") diff --git a/js/popup.js b/js/popup.js index 16a498d..bcda31c 100644 --- a/js/popup.js +++ b/js/popup.js @@ -18,6 +18,7 @@ class Popup extends HTMLSpanElement { this.click_sends_label = create('label', 'control_text', this.click_sends_pane, {for:"click_sends", innerText:"click to send"}) this.send_button = create('button', 'control', this.buttons, {innerText:"Send (S)"} ) this.cancel_button = create('button', 'control', this.buttons, {innerText:"Cancel (X)"} ) + this.extras = create('span', 'extras', this.buttons) this.send_button.addEventListener( 'click', this.send_current_state.bind(this) ) this.cancel_button.addEventListener('click', this.send_cancel.bind(this) ) @@ -29,7 +30,12 @@ class Popup extends HTMLSpanElement { _send_response(msg) { const body = new FormData(); - body.append('response', msg); + var response = msg + if (this.n_extras) { + response = [response] + Array.from(this.extras.children).forEach((e)=>{ response.push(e.value) }) + } + body.append('response', response); api.fetchApi("/cg-image-filter-message", { method: "POST", body, }); this.close() } @@ -84,6 +90,12 @@ class Popup extends HTMLSpanElement { } handle_urls(detail) { + this.n_extras = detail.extras ? detail.extras.length : 0 + this.extras.innerHTML = '' + for (let i=0; i