简体   繁体   English

Photoshop ScriptUI:显示一个对话框窗口,关闭它,再次显示它会给出一个空的全尺寸窗口

[英]Photoshop ScriptUI: Show a dialog window, close it, show it again gives an empty full size window

In my script for Photoshop CC 2015 (Windows 10), written in JavaScript, I am processing all layers of the active document in a loop and want to show a setup dialog in each step.在我用 JavaScript 编写的 Photoshop CC 2015 (Windows 10) 脚本中,我正在循环处理活动文档的所有图层,并希望在每个步骤中显示一个设置对话框。

For simplification, take the following working example.为简化起见,请使用以下工作示例。 The window is defined outside the loop, and among other steps which are stripped here, the window is shown once every step in the loop:窗口是在循环外定义的,在此处删除的其他步骤中,窗口在循环中的每一步都显示一次:

#target photoshop

var w = new Window('dialog', 'Title');
var b = w.add('button', undefined, 'OK');

for (var i = 0; i < 3; i++) {
    // other code
    w.show();
    // other code
}

When you execute it, a small dialog window with just one "OK" button appears, as expected.当您执行它时,会出现一个只有一个“确定”按钮的小对话窗口,正如预期的那样。 You can close it using the "OK" button.您可以使用“确定”按钮关闭它。 But every consecutive w.show() produces a blank window that almost fills the entire screen, with no controls whatsoever.但是每个连续的w.show()产生一个几乎填满整个屏幕的空白窗口,没有任何控件。 It can only be closed using the ESC key.它只能使用 ESC 键关闭。

I tried overriding the b.onClick event and manually call close() , but that did not change anything.我尝试覆盖b.onClick事件并手动调用close() ,但这并没有改变任何东西。

Upon inspection of the w variable, it is obvious that the bounds , respectively location and size somehow got changed.在检查w变量时,很明显bounds ,分别是locationsize不知何故发生了变化。 I tried resetting these values to their previous state, and the window size is restored.我尝试将这些值重置为以前的状态,并且窗口大小已恢复。 However, the button is still not visible.但是,该按钮仍然不可见。

Am I missing something?我错过了什么吗? How can I get the dialog window to show up correctly more than once?如何让对话窗口多次正确显示?

try this code, it works for me with Photoshop CC + OSX.试试这个代码,它适用于我的 Photoshop CC + OSX。

w.close() destroy dialog window, so you should create again. w.close()销毁对话框窗口,所以你应该重新创建。

press a button named 'ok', press return key are same as w.close() .按一个名为“ok”的按钮,按返回键与w.close()相同。

 #target 'photoshop' for (var i = 0; i < 3; i++) { var w = W(); $.writeln(w.show()); } function W () { var w = new Window('dialog', 'Title'); var b = w.add('button', undefined, 'OK', {name:'ok'}); return w }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM