Copy link to clipboard
Copied
Hi friends
I´m trying to add a window with a simple progress bar. But I´m having 2 problems. To better explain I made a simple example that reproduces the intent:
#target Bridge
var d1 = new Window ("dialog", "Show images", [0,0,0,0])
d1.size = [600,290]
d1.center()
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"})
exec.size = [80,30]
exec.location = [410,240]
exec.onClick = function (){
d1.close() //first problem is here
var d2 = new Window ("dialog", "Progress", [0,0,0,0])
d2.size = [230,80]
d2.center()
var bProgress = d2.add ("progressbar", [0,0,0,0], 0)
bProgress.size = [200,20]
bProgress.location = [15,20]
var comment = d2.add ("statictext", [0,0,0,0], "Running numbers")
comment.size = [200,20]
comment.location = [15,45]
d2.show()
for (var g=0; g<10; g++){
bProgress.value = bProgress.value + 10
alert(g)
}
}
d1.show()
The 2 problems I´m having are:
1: When pressing the OK in the first dialog..to run the action...I passed a command to close the dlg1. And it does not close (you will se the 2 dialogs keep opened at the same time)
2: Progress bar does not work. It´s expecting myself to close the dlg2 in order to start running the "for" cycle.
--
What Am I missing??
Thank you a lot for the help
Best Regards
Gustavo
Message was edited by: Gustavo Del Vechio
There are some examples here...
http://www.ps-scripts.com/bb/viewtopic.php?f=13&t=786&sid=7222ff525179a4b47ee49b70d787342e
A progress bar is normally run as a a palette not a dialog...
...#target bridge
app.bringToFront();
var d1 = new Window ("dialog", "Show images", [0,0,0,0]);
d1.size = [600,290];
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"});
exec.size = [80,30];
exec.location = [410,240];
exec.onClick = function (){
d1.visible=false;
d1.close();
var value = 0;
var win = new Window("palette{t
Copy link to clipboard
Copied
There are some examples here...
http://www.ps-scripts.com/bb/viewtopic.php?f=13&t=786&sid=7222ff525179a4b47ee49b70d787342e
A progress bar is normally run as a a palette not a dialog...
#target bridge
app.bringToFront();
var d1 = new Window ("dialog", "Show images", [0,0,0,0]);
d1.size = [600,290];
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"});
exec.size = [80,30];
exec.location = [410,240];
exec.onClick = function (){
d1.visible=false;
d1.close();
var value = 0;
var win = new Window("palette{text:'Please be patient...',bounds:[100,100,580,140]," +
"progress:Progressbar{bounds:[20,10,460,30] , minvalue:0,value:" + value + "}};" );
var d = win.graphics;
d.backgroundColor = d.newBrush(d.BrushType.SOLID_COLOR, [0.00, 0.00, 0.00, 1]);
win.progress.maxvalue = 10;
Count =10;
while(Count > 0){
win.center();
win.show();
Count--;
win.progress.value++;
win.layout.layout(true);
alert(Count);
}
}
d1.center();
d1.show();
Copy link to clipboard
Copied
Hi Paul
Thank you a lot as ever. As a palette instead of dialog it worked. How about a script for Photoshop? Since Photoshop does not accept dialogs of "palettes", how could I set a progress bar working when targetting Photoshop???
And..I´m curious. Why it did not respect the call d1.close()?? (You need to pass "false" to a "d1.visible" property in order to hide that dialog).
Best Regards
Gustavo.
Copy link to clipboard
Copied
I was just trying to see if I could close the dialog window, when it wouldn't I tried to hide it, neither works. This is because of the Bridge scripting engine. It's yet another bug!
If You change the target to photoshop the same code will be run correctly in Photoshop and the main window will close.
Copy link to clipboard
Copied
As I understand it, a window or it's control callbacks don't respond to events when the window is hidden.
So you need to do something like this.
var d1 = new Window ("dialog", "Show images", [0,0,0,0]);// must be dialog to wait for onShow() return
d1.size = [600,290]
d1.center()
var exec = d1.add ("button", [0,0,0,0], "Run", {name:"ok"})
exec.size = [80,30]
exec.location = [410,240]
exec.onClick = function (){
d1.close()
}
d1.show();
// define the progress after dialog.show()
var d2 = new Window ("palette", "Progress", [0,0,0,0])// must be palette so the rest of the script will run
d2.size = [230,80]
d2.frameLocation = [$.screens[0].right/2, $.screens[0].top+200];
bProgress = d2.add ("progressbar", [0,0,0,0], 0)// this needs to be visible outside the function
bProgress.size = [200,20]
bProgress.location = [15,20]
var comment = d2.add ("statictext", [0,0,0,0], "Running numbers")
comment.size = [200,20]
comment.location = [15,45]
d2.show()
// do your thing and update the progressbar
for (var g=0; g<10; g++){
bProgress.value = bProgress.value + 10;
//d2.update(); // older version may need this line
alert(g);// the alert is just to show down the loop.
}
//d2.close();// when you are done with the progressbar close it. unless the script is also done
// the progressbar will close here either way
Copy link to clipboard
Copied
I forgot to add that Photoshop supports palettes as long as the script is running.
And you could have a button on the palette window to cancel the script. In this example you could just set g = false in the button onClick to break out of the loop.
Copy link to clipboard
Copied
Nice to see you in the Bridge forum Mike.
I still think there is a bug in Bridge though Mike as the same code run in ESTK also Photoshop will close the main dialog window first before running the palette even without the hidden line.
Copy link to clipboard
Copied
I follow this forum by email so most of the time you have already answered the question before I see the post.
Although there does seem to be a lot of bugs in ScriptUI, I don't think this is one of them. You just have to set everything to account for the different way the apps treat the two types of dialog( the 'Photoshop doesn't support palattes' thing ) to do what you want. I didn't think the first dialog was wanted so I set it up to close before showing the progressbar. Here is a version that shows the bar window before closing.
var cancel = false;
var d1 = new Window ("dialog", "Show images");// must be dialog to wait for onShow() return
d1.size = [600,290]
d1.center()
var exec = d1.add ("button", undefined, "Run", {name:"ok"})
exec.size = [80,30]
exec.location = [410,240]
exec.onClick = function (){
d2.show();
$.sleep(1000);
d1.close();// do what you need before calling onClose()
}
var d2 = new Window ("palette", "Progress")// must be palette so the rest of the script will run
//d2.size = [230,80]
d2.frameLocation = [$.screens[0].right/2, $.screens[0].top+200];
bProgress = d2.add ("progressbar",undefined, 0)// this needs to be visible outside the function
bProgress.size = [200,20]
// bProgress.location = [15,20]
var comment = d2.add ("statictext",undefined, "Running numbers")
comment.size = [200,20]
//comment.location = [15,45]
d2.cancel = d2.add ("button",undefined, "Cancel");
d2.cancel.onClick = function (){
cancel=true;
d2.close();// same here, none of the code after close() will run( at least in Photoshop )
}
d1.show();
// define the progress after dialog.show()
// do your thing and update the progressbar
for (var g=0; g<10; g++){
if(cancel) break;
bProgress.value = bProgress.value + 10;
//d2.update(); // older version may need this line
alert(g);// the alert is just to show down the loop.
}
d2.close();// when you are done with the progressbar close it. unless the script is also done
// the progressbar will close here either way
Copy link to clipboard
Copied
Thank you Mike, that was a good explanation. It's always good to get another perspective and it does explain a lot of features.
Copy link to clipboard
Copied
That is just my understanding of how dialogs work and I may be wrong about the reasons it works that way it.
I think it would have caused less confusion if the guide said Photoshop doesn't support persistent non-modal ScriptUI windows.That wording is longer and harder to understand but( I think ) more accurate.
Neither are persistent because they are object defined by the script and exists only as long as the script is running. Neither are non modal to the GUI except for some limited interactions that DialogModes allow.
The difference between the two types of windows( at least in Photoshop ) is a dialog is modal to the script. Meaning the script stops at onShow and waits for the user to close the window. A palette window non modal to the script as for as long as it continues to run.
I am not sure of the reason Bridge and ESTK are different than Photoshop. A guess would be in Photoshop windows are 'children' of the script and in those app they are children of the app.
Copy link to clipboard
Copied
Yes Paul has a habit of answering posts while you are in the middle of coming up with an answer… Mike good to see you branching out…
Copy link to clipboard
Copied
Thank you a lot Paul and Michael for the answers!
Michael...Let me see if I understand it: Photoshop supports window of type "palette" only in the middle of the script?? I could not only start creating a palette for running actions after??
Am I right??
Best Regards
Gustavo.
Copy link to clipboard
Copied
If you mean as a type of Photoshop’s Action panel replacement, then no. You would need a custom panel for that. A Configurator or CS-SDK panel.
Copy link to clipboard
Copied
No no Michael
I mean dialog of type "palette" like
var test = new Window ("palette", undefined, "My dialog")
Best Regards
Gustavo.
Copy link to clipboard
Copied
I was wondering what the use is for that graphic. I see var d declared. But it doesnt have a size, nor is it applied to anything.
Was this something to give the progressbar a background. The photoshop progressbar in ScriptUI seems to be missing a background, illustrator does have one.
Edit
my mistake, wasnt paying attention. You apply it to the background of the palette. I noticed doesnt work anymore. Only when i change that to a dialog. But this got me an idea how to give the progressbar a dark background so user see how long the bar will be
See the result