Skip to content

Commit

Permalink
ynput#327: enhancement: Creer un validator pour les layers dans Photo…
Browse files Browse the repository at this point in the history
…shop
  • Loading branch information
hfarre committed Mar 11, 2024
1 parent b1131e7 commit a420e66
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 126 deletions.
2 changes: 1 addition & 1 deletion openpype/hosts/photoshop/api/extension/CSXS/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<ExtensionManifest ExtensionBundleId="com.openpype.PS.panel" ExtensionBundleVersion="1.0.12" Version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ExtensionManifest ExtensionBundleId="com.openpype.PS.panel" ExtensionBundleVersion="1.0.13" Version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ExtensionList>
<Extension Id="com.openpype.PS.panel" Version="1.0.1" />
</ExtensionList>
Expand Down
111 changes: 60 additions & 51 deletions openpype/hosts/photoshop/api/extension/client/client.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
// client facing part of extension, creates WSRPC client (jsx cannot
// client facing part of extension, creates WSRPC client (jsx cannot
// do that)
// consumes RPC calls from server (OpenPype) calls ./host/index.jsx and
// returns values back (in json format)

var logReturn = function(result){ log.warn('Result: ' + result);};

var csInterface = new CSInterface();

log.warn("script start");

WSRPC.DEBUG = false;
WSRPC.TRACE = false;

function myCallBack(){
log.warn("Triggered index.jsx");
}
// importing through manifest.xml isn't working because relative paths
// possibly TODO
jsx.evalFile('./host/index.jsx', myCallBack);

function runEvalScript(script) {
// because of asynchronous nature of functions in jsx
// this waits for response
return new Promise(function(resolve, reject){
csInterface.evalScript(script, resolve);
});
}

/** main entry point **/
startUp("WEBSOCKET_URL");

// get websocket server url from environment value
async function startUp(url){
log.warn("url", url);
log.warn("url", url);
promis = runEvalScript("getEnv('" + url + "')");
var res = await promis;

var res = await promis;
// run rest only after resolved promise
main(res);
}
Expand All @@ -45,15 +45,15 @@
log.debug("get_extension_version")
var path = csInterface.getSystemPath(SystemPath.EXTENSION);
log.debug("extension path " + path);

var result = window.cep.fs.readFile(path + "/CSXS/manifest.xml");
var version = undefined;
if(result.err === 0){
if (window.DOMParser) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(result.data.toString(), 'text/xml');
const children = xmlDoc.children;

for (let i = 0; i <= children.length; i++) {
if (children[i] && children[i].getAttribute('ExtensionBundleVersion')) {
version = children[i].getAttribute('ExtensionBundleVersion');
Expand All @@ -63,22 +63,22 @@
}
return version
}

function main(websocket_url){
// creates connection to 'websocket_url', registers routes
log.warn("websocket_url", websocket_url);
// creates connection to 'websocket_url', registers routes
log.warn("websocket_url", websocket_url);
var default_url = 'ws://localhost:8099/ws/';

if (websocket_url == ''){
websocket_url = default_url;
}
log.warn("connecting to:", websocket_url);
log.warn("connecting to:", websocket_url);
RPC = new WSRPC(websocket_url, 5000); // spin connection

RPC.connect();
log.warn("connected");

log.warn("connected");

function EscapeStringForJSX(str){
// Replaces:
// \ with \\
Expand All @@ -87,7 +87,7 @@
// See: https://stackoverflow.com/a/3967927/5285364
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"');
}

RPC.addRoute('Photoshop.open', function (data) {
log.warn('Server called client route "open":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -97,7 +97,7 @@
return result;
});
});

RPC.addRoute('Photoshop.read', function (data) {
log.warn('Server called client route "read":', data);
return runEvalScript("getHeadline()")
Expand All @@ -106,7 +106,7 @@
return result;
});
});

RPC.addRoute('Photoshop.get_layers', function (data) {
log.warn('Server called client route "get_layers":', data);
return runEvalScript("getLayers()")
Expand All @@ -115,7 +115,16 @@
return result;
});
});


RPC.addRoute('Photoshop.set_blendmode', function (data) {
log.warn('Server called client route "set_blendmode":', data);
return runEvalScript("setBlendmode(" + "'" + data.layer_name + "', " + "'" +data.blendMode_name + "')")
.then(function(result){
log.warn("setBlendmode: " + result);
return result;
});
});

RPC.addRoute('Photoshop.set_visible', function (data) {
log.warn('Server called client route "set_visible":', data);
return runEvalScript("setVisible(" + data.layer_id + ", " +
Expand All @@ -125,17 +134,17 @@
return result;
});
});

RPC.addRoute('Photoshop.get_active_document_name', function (data) {
log.warn('Server called client route "get_active_document_name":',
log.warn('Server called client route "get_active_document_name":',
data);
return runEvalScript("getActiveDocumentName()")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.get_active_document_full_name', function (data) {
log.warn('Server called client route ' +
'"get_active_document_full_name":', data);
Expand All @@ -145,49 +154,49 @@
return result;
});
});

RPC.addRoute('Photoshop.save', function (data) {
log.warn('Server called client route "save":', data);

return runEvalScript("save()")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.get_selected_layers', function (data) {
log.warn('Server called client route "get_selected_layers":', data);

return runEvalScript("getSelectedLayers()")
.then(function(result){
log.warn("get_selected_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.create_group', function (data) {
log.warn('Server called client route "create_group":', data);

return runEvalScript("createGroup('" + data.name + "')")
.then(function(result){
log.warn("createGroup: " + result);
return result;
});
});

RPC.addRoute('Photoshop.group_selected_layers', function (data) {
log.warn('Server called client route "group_selected_layers":',
log.warn('Server called client route "group_selected_layers":',
data);

return runEvalScript("groupSelectedLayers(null, "+
"'" + data.name +"')")
.then(function(result){
log.warn("group_selected_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.import_smart_object', function (data) {
log.warn('Server called client "import_smart_object":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -199,7 +208,7 @@
return result;
});
});

RPC.addRoute('Photoshop.replace_smart_object', function (data) {
log.warn('Server called route "replace_smart_object":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -211,7 +220,7 @@
return result;
});
});

RPC.addRoute('Photoshop.delete_layer', function (data) {
log.warn('Server called route "delete_layer":', data);
return runEvalScript("deleteLayer("+data.layer_id+")")
Expand All @@ -230,39 +239,39 @@
return result;
});
});

RPC.addRoute('Photoshop.select_layers', function (data) {
log.warn('Server called client route "select_layers":', data);

return runEvalScript("selectLayers('" + data.layers +"')")
.then(function(result){
log.warn("select_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.is_saved', function (data) {
log.warn('Server called client route "is_saved":', data);

return runEvalScript("isSaved()")
.then(function(result){
log.warn("is_saved: " + result);
return result;
});
});

RPC.addRoute('Photoshop.saveAs', function (data) {
log.warn('Server called client route "saveAsJPEG":', data);
var escapedPath = EscapeStringForJSX(data.image_path);
return runEvalScript("saveAs('" + escapedPath + "', " +
"'" + data.ext + "', " +
"'" + data.ext + "', " +
data.as_copy + ")")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.imprint', function (data) {
log.warn('Server called client route "imprint":', data);
var escaped = data.payload.replace(/\n/g, "\\n");
Expand All @@ -282,19 +291,19 @@
log.warn('Server called client route "close":', data);
return runEvalScript("close()");
});

RPC.call('Photoshop.ping').then(function (data) {
log.warn('Result for calling server route "ping": ', data);
return runEvalScript("ping()")
.then(function(result){
log.warn("ping: " + result);
return result;
});

}, function (error) {
log.warn(error);
});

}

log.warn("end script");
Binary file modified openpype/hosts/photoshop/api/extension/extension.zxp
Binary file not shown.
Loading

0 comments on commit a420e66

Please sign in to comment.