diff --git a/javascript/sdppp-a1111.js b/javascript/sdppp-a1111.js index 28e4caf..7504788 100644 --- a/javascript/sdppp-a1111.js +++ b/javascript/sdppp-a1111.js @@ -109,7 +109,7 @@ this.socket.emit('c_get_documents', resolve) }); await new Promise(resolve => { - this.socket.emit('c_set_sd_options', { + this.socket.emit('c_update_options', { document_data: data, special_get_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGet(), special_get_bound_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGetBounds(), diff --git a/javascript/sdppp-comfy.js b/javascript/sdppp-comfy.js index fd483cf..ee30b24 100644 --- a/javascript/sdppp-comfy.js +++ b/javascript/sdppp-comfy.js @@ -70,7 +70,7 @@ let widget; if (!downloadWidgets.has(node)) { const size = node.size; - widget = node.addWidget('button', '', 0, ()=> { + widget = node.addWidget('button', '', 0, () => { if (!Object.keys(documentData || {}).length) location.href = "/extensions/sd-ppp/plugins/sd-ppp_PS.ccx" }) @@ -84,7 +84,7 @@ function renderNotConnectedBG(node, ctx) { if (node.flags.collapsed) return; const connected = Object.keys(documentData || {}).length; - if (!connected) { + if (!connected) { ctx.save(); ctx.fillStyle = "rgba(255, 0, 0, 0.2)"; ctx.fillRect(0, 0, node.size[0], node.size[1]); @@ -128,6 +128,13 @@ documentData = (await new Promise(resolve => { socket.emit('c_get_documents', resolve) })) || {} + socket.emit('c_update_options', { + document_data: documentData, + special_get_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGet(), + special_get_bound_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGetBounds(), + special_send_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForSend() + }) + // TODO current document is added on PS side, that's strange this.widgets[0].options.values = Object.keys(documentData); if (!this.widgets[0].options.values.length) this.widgets[0].value = '' if (!this.widgets[0].value || this.widgets[0].options.values.indexOf(this.widgets[0].value) == -1) this.widgets[0].value = this.widgets[0].options.values[0]; @@ -176,6 +183,13 @@ documentData = (await new Promise(resolve => { socket.emit('c_get_documents', resolve) })) || {} + socket.emit('c_update_options', { + document_data: documentData, + special_get_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGet(), + special_get_bound_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForGetBounds(), + special_send_layer_options: SDPPPSpeicialIDManager.getSpecialLayerForSend() + }) + // TODO current document is added on PS side, that's strange this.widgets[0].options.values = Object.keys(documentData); if (!this.widgets[0].options.values.length) this.widgets[0].value = '' if (!this.widgets[0].value || this.widgets[0].options.values.indexOf(this.widgets[0].value) == -1) this.widgets[0].value = this.widgets[0].options.values[0]; diff --git a/scripts/sd_init.py b/scripts/sd_init.py index 1115825..d5bb690 100644 --- a/scripts/sd_init.py +++ b/scripts/sd_init.py @@ -3,7 +3,7 @@ from modules import script_callbacks, shared from modules.ui_components import ToolButton from sdppp_python.sdppp import SDPPP from sdppp_python.apis import consumeImageCache -from sdppp_python.sd_data import get_sd_document_data, get_sd_special_get_bound_layer_options, get_sd_special_get_layer_options, get_sd_special_send_layer_options +from sdppp_python.data import get_sd_document_data, get_special_get_bound_layer_options, get_special_get_layer_options, get_special_send_layer_options import gradio as gr refresh_symbol = '\U0001f504' # 🔄 @@ -24,21 +24,21 @@ def on_app_started(blocks: gr.Blocks, app): def update_layers_dropdown(origin, document): if not sdppp.has_ps_instance(): return ['==please connect SD in photoshop by sdppp first=='] - choices = [*get_sd_special_get_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] + choices = [*get_special_get_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] value = choices[0] if origin not in choices else origin return gr.Dropdown.update(choices=choices, value=value, interactive=True) def update_bounds_dropdown(origin, document): if not sdppp.has_ps_instance(): return ['==please connect SD in photoshop by sdppp first=='] - choices = [*get_sd_special_get_bound_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] + choices = [*get_special_get_bound_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] value = choices[0] if origin not in choices else origin return gr.Dropdown.update(choices=choices, value=value, interactive=True) def update_send_layers_dropdown(origin, document): if not sdppp.has_ps_instance(): return ['==please connect SD in photoshop by sdppp first=='] - choices = [*get_sd_special_send_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] + choices = [*get_special_send_layer_options(), *(x['name'] for x in get_sd_document_data()[document]['layers'])] value = choices[0] if origin not in choices else origin return gr.Dropdown.update(choices=choices, value=value, interactive=True) diff --git a/sdppp_python/apis.py b/sdppp_python/apis.py index d782576..379da51 100644 --- a/sdppp_python/apis.py +++ b/sdppp_python/apis.py @@ -6,6 +6,7 @@ except ImportError: print("SD-PPP: fastapi not found") try: from aiohttp import web + from .data import set_sd_document_data, set_special_get_bound_layer_options, set_special_get_layer_options, set_special_send_layer_options except ImportError: print("SD-PPP: aiohttp not found") @@ -65,14 +66,8 @@ def registerSDHTTPEndpoints(sdppp, app): name = addImageCache(Image.open(BytesIO(image.file.read()))) return {'name': name} -from .sd_data import get_sd_document_data, set_sd_document_data, set_sd_special_get_bound_layer_options, set_sd_special_get_layer_options, set_sd_special_send_layer_options +from .data import get_sd_document_data, set_sd_document_data, set_special_get_bound_layer_options, set_special_get_layer_options, set_special_send_layer_options def registerSocketEvents(sdppp, sio): - @sio.event - async def c_set_sd_options(sid, data={}): - set_sd_document_data(data['document_data']) - set_sd_special_get_layer_options(data['special_get_layer_options']) - set_sd_special_get_bound_layer_options(data['special_get_bound_layer_options']) - set_sd_special_send_layer_options(data['special_send_layer_options']) # only emit by sd webui instance @sio.event @@ -180,4 +175,10 @@ def registerSocketEvents(sdppp, sio): return {} photoshop_sid = instance.sid return await sio.call('c_get_documents', data, to=photoshop_sid) - \ No newline at end of file + + @sio.event + async def c_update_options(sid, data={}): + set_sd_document_data(data['document_data']) + set_special_get_layer_options(data['special_get_layer_options']) + set_special_get_bound_layer_options(data['special_get_bound_layer_options']) + set_special_send_layer_options(data['special_send_layer_options']) \ No newline at end of file diff --git a/sdppp_python/comfy_nodes.py b/sdppp_python/comfy_nodes.py index 330edf1..e3987c1 100644 --- a/sdppp_python/comfy_nodes.py +++ b/sdppp_python/comfy_nodes.py @@ -3,6 +3,7 @@ import time from nodes import LoadImage from PIL import Image from .apis import addImageCache +from .data import get_sd_document_data, get_special_get_bound_layer_options, get_special_get_layer_options, get_special_send_layer_options def define_comfyui_nodes(sdppp): def validate_sdppp(): @@ -38,6 +39,7 @@ def define_comfyui_nodes(sdppp): class GetImageFromPhotoshopLayerNode: + @classmethod def VALIDATE_INPUTS(s): return validate_sdppp() @@ -58,12 +60,21 @@ def define_comfyui_nodes(sdppp): @classmethod def INPUT_TYPES(cls): + document_data = get_sd_document_data() + document_data_keys = document_data.keys() + list_of_list_of_layers = [document_data[key]['layers'] for key in document_data_keys] return { "required": {}, "optional": { - "document": ([], {"default": None}), - "layer_or_group": ([], {"default": None}), - "use_layer_bounds": ([], {"default": None}), + "document": (list(document_data_keys), {"default": None}), + "layer_or_group": ([ + *get_special_get_layer_options(), + *(item['name'] for sublist in list_of_list_of_layers for item in sublist) + ], {"default": None}), + "use_layer_bounds": ([ + *get_special_get_bound_layer_options(), + *(item['name'] for sublist in list_of_list_of_layers for item in sublist) + ], {"default": None}), } } @@ -87,18 +98,26 @@ def define_comfyui_nodes(sdppp): class SendImageToPhotoshopLayerNode: + @classmethod def VALIDATE_INPUTS(s): return validate_sdppp() @classmethod def INPUT_TYPES(cls): + document_data = get_sd_document_data() + document_data_keys = document_data.keys() + list_of_list_of_layers = [document_data[key]['layers'] for key in document_data_keys] return { "required": {}, "optional": { "images": ("IMAGE", ), - "document": ([], {"default": None}), - "layer_or_group": ([], {"default": None}), + # documents_options + "document": (list(document_data), {"default": None}), + "layer_or_group": ([ + *get_special_send_layer_options(), + *(item['name'] for sublist in list_of_list_of_layers for item in sublist) + ], {"default": None}), } } diff --git a/sdppp_python/data.py b/sdppp_python/data.py new file mode 100644 index 0000000..404450b --- /dev/null +++ b/sdppp_python/data.py @@ -0,0 +1,29 @@ + +# need refactor +document_data = dict() +def set_sd_document_data(data): + global document_data + document_data = data +def get_sd_document_data(): + return document_data + +special_get_layer_options = [] +def set_special_get_layer_options(data): + global special_get_layer_options + special_get_layer_options = data +def get_special_get_layer_options(): + return special_get_layer_options + +special_get_bound_layer_options = [] +def set_special_get_bound_layer_options(data): + global special_get_bound_layer_options + special_get_bound_layer_options = data +def get_special_get_bound_layer_options(): + return special_get_bound_layer_options + +special_send_layer_options = [] +def set_special_send_layer_options(data): + global special_send_layer_options + special_send_layer_options = data +def get_special_send_layer_options(): + return special_send_layer_options diff --git a/sdppp_python/sd_data.py b/sdppp_python/sd_data.py deleted file mode 100644 index cd56eb5..0000000 --- a/sdppp_python/sd_data.py +++ /dev/null @@ -1,29 +0,0 @@ - -# need refactor -sd_document_data = dict() -def set_sd_document_data(data): - global sd_document_data - sd_document_data = data -def get_sd_document_data(): - return sd_document_data - -sd_special_get_layer_options = [] -def set_sd_special_get_layer_options(data): - global sd_special_get_layer_options - sd_special_get_layer_options = data -def get_sd_special_get_layer_options(): - return sd_special_get_layer_options - -sd_special_get_bound_layer_options = [] -def set_sd_special_get_bound_layer_options(data): - global sd_special_get_bound_layer_options - sd_special_get_bound_layer_options = data -def get_sd_special_get_bound_layer_options(): - return sd_special_get_bound_layer_options - -sd_special_send_layer_options = [] -def set_sd_special_send_layer_options(data): - global sd_special_send_layer_options - sd_special_send_layer_options = data -def get_sd_special_send_layer_options(): - return sd_special_send_layer_options