UI progressbar example

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Larry Ligon

UI progressbar example

Post by Larry Ligon »

Here is a variation of Mike Hale's code. Doesn't have the flickering.

Code: Select all//progress bar
var value = 0;
var win = new Window("palette{text:'Please wait...',bounds:[100,100,550,140]," +
               "progress:Progressbar{bounds:[20,10,430,28] , minvalue:0,value:" + value + "}" +
               "};"
         );

var sFolder = new Folder('/c/temp2');
var files = sFolder.getFiles("*.jpg");
win.progress.maxvalue = files.length;

while(files.length>0){
   win.center();
   win.show();
   var doc = app.open(files.pop());
   doc.close(SaveOptions.DONOTSAVECHANGES);
   win.progress.value++;
   win.layout.layout(true);
};

 

It only works in versions of Photoshop that have autolayout!
Mike Hale

UI progressbar example

Post by Mike Hale »

Nice one Larry,

I use autolayout most of the time and this is much better than the show/hide dance.
kpt

UI progressbar example

Post by kpt »

I don't know how you manage to see the progress bar update itself without an app.refresh() ?
mycort

UI progressbar example

Post by mycort »

I've tried adding Mike's code for this progressbar and the code before, tried adding to the front and end of my script.....still I dont see a progressbar. Am I doing something wrong? I have the most recent PHotoshop CS5 version.
Mike Hale

UI progressbar example

Post by Mike Hale »

It seems that in Photoshop CS5 some changes were made to the ScriptUI that are not documented and cause older code to break.

I modified Xbytor's progressbar function and it works for me in CS5.

Here is the function:
Code: Select allfunction createProgressWindow(title, message, min, max, parent, useCancel) {
   var win = new Window('palette', title);
   win.bar = win.add('progressbar', undefined, min, max);
   win.bar.preferredSize = [300, 20];
   win.stProgress = win.add('statictext');
   win.stProgress .preferredSize.width = 200;
   win.parent = undefined;

   if (parent) {
      if (parent instanceof Window) {
         win.parent = parent;
      } else if (useCancel == undefined) {
         useCancel = parent;
      }
   }

   if (useCancel) {
      win.cancel = win.add('button', undefined, 'Cancel');
      win.cancel.onClick = function() {
      try {
         if (win.onCancel) {
            var rc = win.onCancel();
            if (rc || rc == undefined) {
               win.close();
            }
         } else {
            win.close();
         }
         } catch (e) { alert(e); }
      }
   }

   win.updateProgress = function(val) {
      var win = this;
      if (val != undefined) {
         win.bar.value = val;
      }else {
         win.bar.value++;
      }
      if (win.recenter) {
         win.center(win.parentWin);
      }
      win.update();
   }
   win.center(win.parent);
   return win;
};

And here is an example of how to use it:
Code: Select all// set up the progress bar with a title and range
var progressWindow = createProgressWindow("Please wait...", undefined, 0, 10,undefined, false);
progressWindow.show();
progressWindow.isDone = false;
// if you code does several things you can change the message under the bar as needed
progressWindow.stProgress.text = ("Creating template document");
// update the bar as needed
progressWindow.updateProgress();
// change the message if desired
progressWindow.stProgress.text = ("Placing Images");
// when done
progressWindow.isDone = true;
progressWindow.close();
// the inDone flag is useful if you have code like a function
// that you may or may not want to update the progress bar
// in that case you can do something like
if(!progressWindow.isDone) progressWindow.upDateProgress();


The above explains how to use the function in 'auto increment' mode. You can also control the amount of progress by passing the value to use.
Code: Select allprogressWindow.updateProgress( 3 );

If I have a process that may vary in the number of steps I can use the function in auto mode and pass the value at some point to step back the bar so I can use the same bar for say a 10 or 13 step process. In the extra steps I just pass the current value. The bar length doesn't change for that step but I can change the message.
roldy
Posts: 1
Joined: Fri Mar 08, 2019 1:57 am

Re: UI progressbar example

Post by roldy »

How do I stop the progress bar window from stop flickering?
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

HI guys, this is my first post here. Kinda a new to this forum

I was looking for a progress bar script and after long hours of searching, i bumped into this one. I got the initial code working, but not everything works correctly. I also found other scripts that do app.refresh() and win.update(). Both cause issues on OSX. app.refresh somehow causes the script to progress 4-5 times longer, said its executing it multiple times. win.update, simply slows down the process, does do anything.

I also did some time checks on this progress bar. Im doing a script on approx 60layers as testing. Running it without any dialog tasks around 4-5seconds. Running it with this dialog takes around 14 seconds. It seems its slowing down quite a lot With the progress bar i do see the UI update and layers get selected and such. But my guess this big slow down is that the window is added and redrawn each time. For instance, when i move it, i see a copy of the window. Just like when you have big redraw issues on your OS or something likewise. I don't understand why the complete window needs to be redrawn or setup. Feels like a very bad implementation of something super simple.

I found 3 different progress bar codes and 2 use win.update() but that doesn't work properly on OSX. he trick this script does with hide and show does work, only it has 1 show to many. At the end it would not go away or it would appear again if i left PS and got back.

I read something on this adobe forum post about the UI freezing on OSX. Is that perhaps the issue here?
https://community.adobe.com/t5/get-star ... 586?page=1
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

@Mike Hale,

i just tried your updated version. I see same issue as with the other. Nothing shows, I need to add win.hide() and a win.show() right after each other to get it to show. I also did a time run with this one, its also slowing down the script almost double the time.

I guess that's why its better to use the delay method adding an integer in that updateProgress(X). I tried it and thought it would steps by 5 then. But it seems to go to X percentage of that. I think i need to figure this one out differently.
Last edited by schroef on Sat Apr 11, 2020 7:13 am, edited 2 times in total.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

There is problem with ProgressBar on OSX indeed. It doesn't work without refresh() like on Windows.
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

Kukurykus wrote: Sat Apr 11, 2020 12:46 pm There is problem with ProgressBar on OSX indeed. It doesn't work without refresh() like on Windows.
Well app.refresh() makes it terribly slow, the same process takes longer

No visual feedback, but is fastest
without visual progressbar
start: 23:32.511
End: 23:38.980

Progressbar updates but window cant be clicked
with win.show() & win.hide()
start: 22:15.668
End: 22:23.698

window flickers because of win.hide() and feels terribly slow
with app.refresh()
start: 21:11.703
End: 21:36.382

No visual difference
with win.update()
start: 20:14.441
End: 20:22.609

PS is there anyway i can escape if its running. I get a warning "The command is currently not available"
This is in a catch i added in the main execution script. Should i remove the try catch then?