send text to layer
This commit is contained in:
@@ -435,6 +435,44 @@ def define_comfyui_nodes(sdpppServer):
|
||||
|
||||
return (output_mask, )
|
||||
|
||||
class SendTextToLayerNode:
|
||||
RETURN_TYPES = ("DOCUMENT",)
|
||||
FUNCTION = "action"
|
||||
CATEGORY = "SD-PPP"
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(self, **kwargs):
|
||||
return np.random.rand()
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ('STRING', {"sdppp_type": "STRING"}),
|
||||
"layer": ('LAYER', {"default": None, "sdppp_type": "LAYER"}),
|
||||
},
|
||||
"optional": SDPPPOptional({}, {
|
||||
"sdppp": ("STRING", {"default": ""})
|
||||
}),
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID",
|
||||
"prompt": "PROMPT",
|
||||
}
|
||||
}
|
||||
|
||||
def action(self, text, layer, **kwargs):
|
||||
sdpppServer.has_ps_instance(throw_error=True)
|
||||
|
||||
document = layer['document']
|
||||
|
||||
call_async_func_in_server_thread(ProtocolPhotoshop.send_text(
|
||||
instance_id=document['instance_id'],
|
||||
document_identify=document['identify'],
|
||||
text=text,
|
||||
layer_identify=layer['layer_identify'],
|
||||
), True)
|
||||
|
||||
return (document, )
|
||||
|
||||
class GetTextFromLayerNode:
|
||||
RETURN_TYPES = ("STRING",)
|
||||
@@ -469,15 +507,7 @@ def define_comfyui_nodes(sdpppServer):
|
||||
def action(self, layer_or_group, unique_id, prompt, document = None, **kwargs):
|
||||
sdpppServer.has_ps_instance(throw_error=True)
|
||||
|
||||
linked_style = check_linked_in_prompt(prompt, unique_id, 'layer_or_group')
|
||||
if not linked_style:
|
||||
document = json.loads(document)
|
||||
else:
|
||||
document = layer_or_group[0]['document']
|
||||
|
||||
# dont check here, some python cannot read the data in this thread.
|
||||
# if document['instance_id'] not in sdpppServer.ppp_instances:
|
||||
# raise ValueError(f'Photoshop instance {document["instance_id"]} not found')
|
||||
document = json.loads(document)
|
||||
|
||||
res_text = []
|
||||
for i, item_layer in enumerate(layer_or_group):
|
||||
@@ -517,6 +547,7 @@ def define_comfyui_nodes(sdpppServer):
|
||||
'SDPPP Get Linked Layers': GetLinkedLayersNode,
|
||||
'SDPPP Get Layers In Group': GetLayersInGroupNode,
|
||||
'SDPPP Get Text From Layer': GetTextFromLayerNode,
|
||||
'SDPPP Send Text To Layer': SendTextToLayerNode,
|
||||
'SDPPP Get Selection': GetSelectionNode,
|
||||
'SDPPP Parse Layer Info': ParseLayerInfoNode,
|
||||
# 'SDPPP Settings': SDPPPSettingsNode,
|
||||
|
||||
@@ -57,6 +57,19 @@ class ProtocolPhotoshop:
|
||||
})
|
||||
return result['text']
|
||||
|
||||
@classmethod
|
||||
async def send_text(cls, instance_id, document_identify, text, layer_identify):
|
||||
ppp_instance = cls.sdpppServer.ppp_instances[instance_id]
|
||||
result = await protocol_call(ppp_instance, 'B_photoshop', data={
|
||||
'action': 'sendText',
|
||||
'params': {
|
||||
'document_identify': document_identify,
|
||||
'text': text,
|
||||
'layer_identify': layer_identify
|
||||
}
|
||||
})
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
async def get_selection(cls, instance_id, document_identify, boundary):
|
||||
ppp_instance = cls.sdpppServer.ppp_instances[instance_id]
|
||||
|
||||
@@ -37,6 +37,7 @@ export default {
|
||||
'SDPPP Get Selection': 'SDPPP获取选区(GetSelection)',
|
||||
'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)',
|
||||
|
||||
// comfy widget/input
|
||||
@@ -170,6 +171,7 @@ export default {
|
||||
'get layer info': '获取图层信息',
|
||||
'sdppp extract PSD': 'sdppp 导入 PSD',
|
||||
'sdppp get PSD': 'sdppp 获取 PSD',
|
||||
'set text to layer': '设置图层的文本',
|
||||
|
||||
// photoshop dialog/widget
|
||||
'{0} wants to extract a PSD file to Photoshop, are you sure?': '{0} 想要释放一个.psd文件到Photoshop,确定吗?',
|
||||
|
||||
@@ -51,6 +51,14 @@ export class GetLinkedLayersNode extends SDPPPNodeWithInput implements NodeWithL
|
||||
this.node.outputs.forEach((i: any) => i.label = i18n(i.name));
|
||||
}
|
||||
}
|
||||
|
||||
export class SendTextToLayerNode extends SDPPPDownloadableNode {
|
||||
protected async update() {
|
||||
super.update();
|
||||
this.node.inputs[0].label = i18n(this.node.inputs[0].name)
|
||||
this.node.outputs[0].label = i18n(this.node.outputs[0].name)
|
||||
}
|
||||
}
|
||||
export class GetTextFromLayerNode extends SDPPPDownloadableNode {
|
||||
static prehandleNodeType(nodeData: any) {
|
||||
if (nodeData.input.optional['document']) {
|
||||
@@ -91,62 +99,6 @@ export class GetTextFromLayerNode extends SDPPPDownloadableNode {
|
||||
}
|
||||
}
|
||||
|
||||
// export class SDPPPSettingsNode extends SDPPPNodeWithInput {
|
||||
// async update() {
|
||||
// super.update();
|
||||
// this.node.inputs[0].label = i18n(this.node.inputs[0].name)
|
||||
// if (this.node.properties.psd) {
|
||||
// pageStore.setHasPSDNodes(true)
|
||||
// this.psdWidget.label = i18n('extract saved .psd to Photoshop')
|
||||
|
||||
// } else {
|
||||
// pageStore.setHasPSDNodes(false)
|
||||
// this.psdWidget.label = i18n('save .psd to this workflow')
|
||||
// }
|
||||
// }
|
||||
|
||||
// protected onDestroy(): void {
|
||||
// pageStore.setHasPSDNodes(false)
|
||||
// }
|
||||
|
||||
// protected psdWidget: any
|
||||
// constructor(node: any) {
|
||||
// const existed = app.graph.nodes.filter((n: any) => n.comfyClass == 'SDPPP Settings')
|
||||
// if (existed.length > 1) {
|
||||
// alert(i18n('You can only have one SDPPP Settings node in a workflow'))
|
||||
// app.graph.remove(node)
|
||||
// throw new Error(i18n('You can only have one SDPPP Settings node in a workflow'))
|
||||
// }
|
||||
// super(node);
|
||||
// this.psdWidget = node.addWidget('button', '', '', () => {
|
||||
// const backendDatas = pagePhotoshopStoreMap.getAllPhotoshopDocumentData();
|
||||
// const [instanceName, documentIdentify] = this.documentWidget.widget.value.split('/');
|
||||
// if (this.node.properties.psd) {
|
||||
// this.extractPSD(backendDatas[instanceName].sid, documentIdentify)
|
||||
|
||||
// } else {
|
||||
// ComfySocket.instance
|
||||
// .importPSDDataURLFromPhotoshop(backendDatas[instanceName].sid, documentIdentify)
|
||||
// .then(psdBase64 => {
|
||||
// this.node.setProperty('psd', psdBase64);
|
||||
// });
|
||||
// }
|
||||
// }, {})
|
||||
// }
|
||||
|
||||
// public extractPSD(sid: string, documentIdentify: string) {
|
||||
// if (this.node.properties.psd) {
|
||||
// ComfySocket.instance
|
||||
// .exportPSDDataURLToPhotoshop(sid, documentIdentify, this.node.properties['psd'])
|
||||
// .then(async () => {
|
||||
// await new Promise(resolve => setTimeout(resolve, 300));
|
||||
// (globalThis as any).app.canvas.draw(true, true)
|
||||
// })
|
||||
// .catch(console.error);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
export class GetDocumentNode extends SDPPPNodeWithInput implements NodeWithDocumentOutput {
|
||||
get documentWidget() {
|
||||
return this.widgets[0] as DocumentWidget;
|
||||
|
||||
@@ -58,6 +58,7 @@ export class DocumentWidget extends SDPPPComboWidget {
|
||||
const documentWidget = node.addWidget('combo', name, options[0] || '', () => { }, { forceInput: true, values: makeDocumentDataOptions })
|
||||
documentWidget.serializeValue = async () => {
|
||||
const data = parseDocumentOption(documentWidget.value);
|
||||
console.log('documentWidgetData: ', data);
|
||||
if (!data) return '';
|
||||
return JSON.stringify({
|
||||
instance_id: data.instance_id,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import i18n from "../../../common/i18n.mjs";
|
||||
import { GetImageFromLayerNode, SendImageToLayerNode } from "../comfy-nodes/legacy-nodes.mjs";
|
||||
import { GetDocumentNode, GetLayerNode, GetLayersInGroupNode, GetLinkedLayersNode, GetSelectionNode, GetTextFromLayerNode, ParseLayerInfoNode } from "../comfy-nodes/nodes.mjs";
|
||||
import { GetDocumentNode, GetLayerNode, GetLayersInGroupNode, GetLinkedLayersNode, GetSelectionNode, GetTextFromLayerNode, ParseLayerInfoNode, SendTextToLayerNode } from "../comfy-nodes/nodes.mjs";
|
||||
import { SDPPPNode } from "../comfy-nodes/SDPPPNode.mjs";
|
||||
import { SDPPPNodeWithInput } from "../comfy-nodes/SDPPPNodeWithInput.mjs";
|
||||
declare const comfyAPI: any;
|
||||
@@ -8,6 +8,7 @@ declare const comfyAPI: any;
|
||||
const SDPPPNodeList = {
|
||||
'Get Image From Photoshop Layer': GetImageFromLayerNode,
|
||||
'Send Images To Photoshop': SendImageToLayerNode,
|
||||
'SDPPP Send Text To Layer': SendTextToLayerNode,
|
||||
'SDPPP Get Text From Layer': GetTextFromLayerNode,
|
||||
'SDPPP Parse Layer Info': ParseLayerInfoNode,
|
||||
'SDPPP Get Linked Layers': GetLinkedLayersNode,
|
||||
|
||||
Reference in New Issue
Block a user