From a6d8c94acaa617aa1cd2fcdb9e0fe640897d964c Mon Sep 17 00:00:00 2001 From: zombieyang Date: Sat, 26 Apr 2025 22:46:57 +0800 Subject: [PATCH] photoshop action support --- sdppp_python/comfy/nodes.py | 40 +++++++++++++++++++ sdppp_python/protocols/photoshop.py | 13 +++++- sdppp_python/sdppp.py | 4 +- .../modules/comfy/src/comfy-nodes/nodes.mts | 10 ++++- .../comfy/src/litegraph/node-wrapper.mts | 3 +- typescripts/modules/photoshop-internal | 2 +- typescripts/src/common/zh-cn.mts | 5 ++- .../src/socket/PhotoshopCalleeInterface.mts | 12 ++++++ 8 files changed, 83 insertions(+), 6 deletions(-) diff --git a/sdppp_python/comfy/nodes.py b/sdppp_python/comfy/nodes.py index 6b090ef..5727a6b 100644 --- a/sdppp_python/comfy/nodes.py +++ b/sdppp_python/comfy/nodes.py @@ -525,6 +525,45 @@ def define_comfyui_nodes(sdpppServer): return (res_text,) + class RunPhotoshopActionNode: + RETURN_TYPES = ("DOCUMENT",) + RETURN_NAMES = ("document",) + FUNCTION = "action" + CATEGORY = "SD-PPP" + OUTPUT_NODE = True + + @classmethod + def IS_CHANGED(self, **kwargs): + return np.random.rand() + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "document": ("DOCUMENT", {"default": None, "sdppp_type": "DOCUMENT"}), + "action_set": ("STRING", {"default": "", "sdppp_type": "STRING"}), + "action": ("STRING", {"default": "", "sdppp_type": "STRING"}), + }, + "optional": SDPPPOptional({}, { + "sdppp": ("STRING", {"default": ""}) + }) + } + + def action(self, document, action_set, action, **kwargs): + sdpppServer.has_ps_instance(throw_error=True) + + call_async_func_in_server_thread(ProtocolPhotoshop.run_photoshop_action( + instance_id=document['instance_id'], + document_identify=document['identify'], + action_set=action_set, + action=action + ), True) + + return (document, ) + + + + # class SDPPPSettingsNode: # RETURN_TYPES = () # FUNCTION = "action" @@ -550,5 +589,6 @@ def define_comfyui_nodes(sdpppServer): 'SDPPP Send Text To Layer': SendTextToLayerNode, 'SDPPP Get Selection': GetSelectionNode, 'SDPPP Parse Layer Info': ParseLayerInfoNode, + 'SDPPP Run Photoshop Action': RunPhotoshopActionNode, # 'SDPPP Settings': SDPPPSettingsNode, } diff --git a/sdppp_python/protocols/photoshop.py b/sdppp_python/protocols/photoshop.py index a0c5b45..7262743 100644 --- a/sdppp_python/protocols/photoshop.py +++ b/sdppp_python/protocols/photoshop.py @@ -131,4 +131,15 @@ class ProtocolPhotoshop: } }) return result - + + @classmethod + async def run_photoshop_action(cls, instance_id, document_identify, action_set, action): + ppp_instance = cls.sdpppServer.ppp_instances[instance_id] + result = await protocol_call(ppp_instance, 'B_photoshop', data={ + 'action': 'runPhotoshopAction', + 'params': { + 'action_set': action_set, + 'action': action + } + }) + return result diff --git a/sdppp_python/sdppp.py b/sdppp_python/sdppp.py index 5830c3c..df844c6 100644 --- a/sdppp_python/sdppp.py +++ b/sdppp_python/sdppp.py @@ -27,7 +27,9 @@ class SDPPP: self.sio = socketio.AsyncServer( async_mode='aiohttp', cors_allowed_origins="*", - max_http_buffer_size=524288000 + max_http_buffer_size=524288000, + ping_interval=60, + ping_timeout=50 ) self.sio.attach( PromptServer.instance.app, diff --git a/typescripts/modules/comfy/src/comfy-nodes/nodes.mts b/typescripts/modules/comfy/src/comfy-nodes/nodes.mts index eccfd1c..213a1cf 100644 --- a/typescripts/modules/comfy/src/comfy-nodes/nodes.mts +++ b/typescripts/modules/comfy/src/comfy-nodes/nodes.mts @@ -147,4 +147,12 @@ export class GetDocumentNode extends SDPPPNodeWithInput implements NodeWithDocum this.psdWidget.label = i18n('save .psd to this workflow') } } -} \ No newline at end of file +} + +export class RunPhotoshopActionNode extends SDPPPNodeWithInput { + async update() { + super.update(); + this.node.inputs.forEach((i: any) => i.label = i18n(i.name)); + this.node.outputs.forEach((i: any) => i.label = i18n(i.name)); + } +} diff --git a/typescripts/modules/comfy/src/litegraph/node-wrapper.mts b/typescripts/modules/comfy/src/litegraph/node-wrapper.mts index 015e710..a45cd64 100644 --- a/typescripts/modules/comfy/src/litegraph/node-wrapper.mts +++ b/typescripts/modules/comfy/src/litegraph/node-wrapper.mts @@ -1,6 +1,6 @@ import i18n from "../../../../src/common/i18n.mts"; import { GetImageFromLayerNode, SendImageToLayerNode } from "../comfy-nodes/legacy-nodes.mjs"; -import { GetDocumentNode, GetLayerNode, GetLayersInGroupNode, GetLinkedLayersNode, GetSelectionNode, GetTextFromLayerNode, ParseLayerInfoNode, SendTextToLayerNode } from "../comfy-nodes/nodes.mjs"; +import { GetDocumentNode, GetLayerNode, GetLayersInGroupNode, GetLinkedLayersNode, GetSelectionNode, GetTextFromLayerNode, ParseLayerInfoNode, RunPhotoshopActionNode, SendTextToLayerNode } from "../comfy-nodes/nodes.mjs"; import { SDPPPNode } from "../comfy-nodes/SDPPPNode.mjs"; import { SDPPPNodeWithInput } from "../comfy-nodes/SDPPPNodeWithInput.mjs"; declare const comfyAPI: any; @@ -16,6 +16,7 @@ const SDPPPNodeList = { 'SDPPP Get Layer By ID': GetLayerNode, 'SDPPP Get Document': GetDocumentNode, 'SDPPP Get Selection': GetSelectionNode, + 'SDPPP Run Photoshop Action': RunPhotoshopActionNode, // 'SDPPP Settings': SDPPPSettingsNode, } export const ComfyNodeDefList: Record = {} as any diff --git a/typescripts/modules/photoshop-internal b/typescripts/modules/photoshop-internal index 1a240fb..1725546 160000 --- a/typescripts/modules/photoshop-internal +++ b/typescripts/modules/photoshop-internal @@ -1 +1 @@ -Subproject commit 1a240fbc7312afd0897e69e47ce1d64939262b37 +Subproject commit 17255469f345fa60de425cf70c7906acfdcd0d31 diff --git a/typescripts/src/common/zh-cn.mts b/typescripts/src/common/zh-cn.mts index a31f63a..d2092a3 100644 --- a/typescripts/src/common/zh-cn.mts +++ b/typescripts/src/common/zh-cn.mts @@ -38,7 +38,7 @@ export default { 'SDPPP Get Image From Photoshop': 'SDPPP从PS获取图像(GetImageFromPhotoshop)', 'SDPPP Send Images To Photoshop': 'SDPPP发送图像到PS(SendImagesToPhotoshop)', 'SDPPP Send Text To Layer': 'SDPPP发送文本到图层(SendTextToLayer)', - 'SDPPP Settings': 'SDPPP设置/杂项(Settings/Misc)', + 'SDPPP Run Photoshop Action': 'SDPPP运行PS Action(RunPhotoshopAction)', // comfy widget/input 'download PS plugin (.ccx)': '下载 Photoshop 插件 (.ccx)', @@ -171,6 +171,8 @@ export default { 'Workflow list loading failed: {0}': '工作流列表加载失败: {0}', 'Please register a user in ComfyUI': '请在 ComfyUI 中注册一个用户', 'GetSelection need Photoshop version 25+': 'GetSelection 需要 Photoshop 25+ 版本', + 'Action {0} not found': 'Action {0} 未找到', + 'Action set {0} not found': 'ActionSet {0} 未找到', // photoshop modal state 'create document for sent images': '给发送的图片创建文档', @@ -182,6 +184,7 @@ export default { 'sdppp extract PSD': 'sdppp 导入 PSD', 'sdppp get PSD': 'sdppp 获取 PSD', 'set text to layer': '设置图层的文本', + 'sdppp Run Photoshop Action': 'sdppp 运行 Photoshop Action', // photoshop dialog/widget '{0} wants to extract a PSD file to Photoshop, are you sure?': '{0} 想要释放一个.psd文件到Photoshop,确定吗?', diff --git a/typescripts/src/socket/PhotoshopCalleeInterface.mts b/typescripts/src/socket/PhotoshopCalleeInterface.mts index c70d0cb..86bf0cb 100644 --- a/typescripts/src/socket/PhotoshopCalleeInterface.mts +++ b/typescripts/src/socket/PhotoshopCalleeInterface.mts @@ -141,6 +141,17 @@ export interface LayerReducerActions { } } +// =========== runPhotoshopAction Interfaces =========== +export interface RunPhotoshopActionActions { + params: { + action_set: string, + action: string + }, + result: { + success: boolean + } +} + // Main interface that aggregates all action types export interface PhotoshopCalleeActions { psd: PSDActions; @@ -153,6 +164,7 @@ export interface PhotoshopCalleeActions { getDocumentInfo: getDocumentInfoActions; getLinkedLayers: LayerReducerActions; getLayersInGroup: LayerReducerActions; + runPhotoshopAction: RunPhotoshopActionActions; } // // PhotoshopCaller actions interface (referenced in PhotoshopCallee)