UI progressbar example

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

Moderators: Tom, Kukurykus

schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

Well i answered my own question, that try / catch with warning i added doesn't allow the user to escape the script when its running. Dang, now i need to update 20+ files hahaha
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

For Os X you can use counter, I mean increasing number (in seconds) as Static text. I think that can be used without refresh()
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

Soryy im no code guru so i have no idea what counter is directed at. Is that a DIaliag attribute torso because i see counter in many scripts but its a variable which is being declared. iwin.bar.value = all or win.bar.value++ simply does not show any difference unless i do hide and show. Ive now implemented some kind of step process, so it only update on each 5nth, not sure this is correct. But updating on each function run is slowing down the script. I don't understand why the whole panel needs to be redrawn??? Im using this now where progress is the step i define. if (progress == 1 * i) if it equals i do an update and raise the step by 5 more.

Looks like this

Code: Select all

var progress = 10;
for (var i = 0; i < layers.length; i++) {
    // update the bar as needed
    if (progress == 1 * i) {
            progressWindow.updateProgress();
            progress += 10;
    }
    progressWindow.strDesc.stProgress.text = ("Reselecting layers");
    selLyr(layerInfo[i].lyrIndex, 1);
}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

I'm not sure if win.update worked on OsX, but you can try the code that works on Windows:

Code: Select all

function pB(v) {
	function prg(v) {return ('0000' + (v)).slice(-4)}
	if (v) value.text = prg(++num) + text, win.update() else{
		num = 0, value = (win = new Window('palette')).add
		('group').add('statictext', [0, 0, 58, 17], prg(num)
		+ text = ' / ' + (len = 5000)), win.show(), refresh()
	}
}

pB(), pB(true); for(i = 1; i < len; i++) pB(true)
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

Thanks for the example! Ill try to see what this one does. PS can you use refresh() as a single function? I didn't knew that.

THe scripts looks pretty advanced to me, i do understand it. WIth my coding skills were better. Ive been doing Python stuff a bit, but i don't know how to expand my knowledge.

PS those last items can be kept at single line right, i believe beautifying the script will get rid of that anyways

PS it does keep showing a warning for that = sign.

EDIT
I change some values so the dialog is bigger. Only thing i see is 0000 5000 its not counting. But i guess that's due to the warning i see on that = sign
I guess this is the OSX progress bar issue, nothing updates. Ill try it with a show / hide like i did in my setup.
Somehow the text doesn't get updated in the counter. I think there due to that error. I checked if its counting and that does work.
Attachments
See #394  text =
See #394 text =
Screen Shot 2020-04-12 at 17.27.00.png (142.4 KiB) Viewed 24490 times
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

It only seems to be counting if i add the refresh to the if statement. Other wise it will show a split second and hides
I think that refresh() is same as using app.refresh() right? It slowing down the script to be able to see it count

I changed it like this

Code: Select all

var num = 0;
function pB(v) {
    function prg(v) {
        return ('0000' + (v)).slice(-4)
    }
    if (v) 
        value.text = prg(++num) + text, win.update(), refresh()
        // ,win.show(), refresh()
        // alert(num)
    else {
        value = (win = new Window('palette'))
        win.add('group')
        win.add('statictext', [20, 20, 300, 50], prg(num) + text = ' / ' + (len = 200));
        win.show(), refresh();
    }
}

pB(), pB(true);for (i = 1; i < len; i++) pB(true)
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: UI progressbar example

Post by schroef »

I got it working with a bar as well. But does show anything unless i do that refresh() in the if statement or add win.show(),win.hide()
If that's not in, its showing nothing counts to 5000 and show the dialog for like 200ms torso

also notice sometimes it keeps counting past that 500, i lowered the amount because was to slow
Image

when i used a refresh, last part, it goes super slow. It feels like win.update() simply doesn't exist on OSX code part. It doesn't give any improvement or difference than not using it.

See this post on Adobe Forum, perhaps you already know, i guess you do
https://community.adobe.com/t5/get-star ... 586?page=1


Another weird thing i see happening, because i updated the script with it counting in the body text and the addition of the pbar. Now it starts counting to 500 twice??? If i leave that part out, it counts to 500 and hides. Feels really buggy indeed. I also read a post about some issue on OSX about asynchronous and synchronous, I'm not sure i followed along properly but it seems OSX has some issue with updating and running scripts at the same time. When i don't add the progress bar it does work properly. Did i make a mistake somewhere? even checking if len == 500 does not close the window?

this is my updated version

Code: Select all

var num = 0;
function pB(v) {
    function prg(v) {
        return ('000' + (v)).slice(-3)
    }
    if (v) 
        // value.text = prg(++num) + text
        win.update()
        , win.show(),win.hide()
        , win.pb.text = prg(++num) + text
        , win.bar.value = ++num
        // , refresh()
        // ,win.show(), refresh()
        // alert(num)
    else {
        value = (win = new Window('palette'))
        win.add('group')
        win.add('statictext', [20, 20, 300, 50], prg(num) + text = ' / ' + (len = 500), {name: "pb"});
        win.bar = win.add('progressbar', undefined, 0, 500);
        win.bar.preferredSize = [300, 20];
        win.show(), refresh();
    }
}

pB(), pB(true);
for (i = 1; i < len; i++) {
    pB(true)
    if(len==500) win.close()
}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

Yes, refresh() is built-in function. You can use that code in else statement as single line. Your editor warns you of = sign, but it shouldn't matter.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

Yes refresh() can be used without app. As I assumed win.update() may not work on OsX, however it doesn't slow down script like refresh()
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: UI progressbar example

Post by Kukurykus »

I don't use Mac these days, but I found I can't have ProgressBar there, then someone said they are not normally used in OsX outside of Photoshop too so probably they are designed so. I found solution with the counter what worked, and that was without win.update() indeed, but why it's not working now I don't know. I remember the code that worked looked similar to that I shared. For now I can't say anything more.