Page 1 of 1

Progress Indicator

Posted: 14 Aug 2014 14:26
by Stef123
It doesn't necessarily have to show the actual progress (although that would be nice) - but just any kind of hint that the script is still busy and doing something.

I pass a rather large selection of files to another program (repeated calls inside a ForEach loop) and have set up a msg-box to tell me when it's done. So theoretically I know it's still at work when I switch back to XY and don't see that Done-dialog.

But it were reassuring to have the opposite feedback: Seeing something - anything - for as long as the script is at work. An icon that stays up, a status bar message that I configure - any such thing I can do to keep me informed?

Re: Progress Indicator

Posted: 14 Aug 2014 14:45
by TheQwerty
The script could be modified to periodically call the Status SC to display a message in the status bar.

Code: Select all

"Count to 100"
 // Start counting at 1.
 $i = 1;

 // Keep counting until 100.
 while ($i < 100) {

   // Show current value of $i in the status bar.
   Status $i, '222299', 'progress';

   // Increment $i.
   $i++;

   // Pause for dramatic effect.
   wait 50;
 }

 // Print the final value of $i.
 Status $i, '229922', 'ready';
You can even get creative with the messages to create little text animations or progress bars. ;)

Re: Progress Indicator

Posted: 14 Aug 2014 15:30
by highend
Or for the selected files:

Code: Select all

    $selectedItems = get("SelectedItemsPathNames");
    $countNormalized = gettoken($selectedItems, "count", "<crlf>");

    $i = 1;
    foreach($item, $selectedItems, "<crlf>") {
        status "Percent done: " . round($i / $countNormalized * 100, 0) . "%", "006400", "progress";
        wait 500;
        $i++;
    }

Re: Progress Indicator

Posted: 14 Aug 2014 15:32
by Stef123
Thanks. Exactly what I needed. Both, feature-wise and also in terms of tasting the sweet grapes of success. It worked on the first go-around (I let it display the filename contained in $item of the ForEach loop that changes in every cycle). :biggrin:

EDIT: Noticed the percent-done variant just now - thank you highend, that adds the cream on top, getting the total count of my selection, then computing the percentage done. Must put this off for later tonight. Can't wait to try it out.

Re: Progress Indicator

Posted: 14 Aug 2014 15:47
by SkyFrontier
Interesting example:
http://www.xyplorer.com/xyfc/viewtopic.php?p=65775
(which I think could be adapted to suit your needs)

Re: Progress Indicator

Posted: 14 Aug 2014 17:09
by highend
You can enhance my last example with a simple progress bar easily:

Code: Select all

    $selectedItems = get("SelectedItemsPathNames");
    $countNormalized = gettoken($selectedItems, "count", "<crlf>");

    $i = 1;
    foreach($item, $selectedItems, "<crlf>") {
        $percentDone = round($i / $countNormalized * 100, 0);
        $progressBar = strrepeat("#", $percentDone / 20);
        status "Percent done: $progressBar $percentDone% $progressBar", "006400", "progress";
        wait 100;
        $i++;
    }
Select a hundred files and watch it *g*

You could even colorcode it...

Re: Progress Indicator

Posted: 14 Aug 2014 19:49
by bdeshi
Keep in mind that if the script is doing some heavy lifting, XYplorer will invest all resources to script execution and stop updating the statusbar. And will also look like it's hanged, I mean hung. :kidding:

Re: Progress Indicator

Posted: 14 Aug 2014 23:40
by Marco
SammaySarkar wrote:Keep in mind that if the script is doing some heavy lifting, XYplorer will invest all resources to script execution and stop updating the statusbar. And will also look like it's hanged, I mean hung. :kidding:
Unless you place a "wait 1;" at the end of the foreach() loop :)

Re: Progress Indicator

Posted: 15 Aug 2014 06:13
by bdeshi
Didn't know that, thanks.

Re: Progress Indicator

Posted: 15 Aug 2014 08:23
by Stef123
Quite some learning curve - have to take it slowly, one step at a time. Didn't expect the programming involved to be so intricate. Makes me see existing software in a more appreciative light.

@SkyFrontier - thanks for the link. Have to figure out the logics behind it. Weekend material
@Highend - your script is the one I've spent most time on, so far. Picked up many things along the way. Gettoken is the most taxing. Not the syntax per se, but understanding what to use it for and why. The same with TheQwerty's hint to "formatlist" (from another thread).
Marco wrote:
SammaySarkar wrote:Keep in mind that if the script is doing some heavy lifting, XYplorer will invest all resources to script execution and stop updating the statusbar. And will also look like it's hanged, I mean hung. :kidding:
Unless you place a "wait 1;" at the end of the foreach() loop :)
Glad you pointed this out. Not just the hang-up issue, but the very fact that resources are limited. Should have been obvious to me, but had not given it any thought at all. Another thing I put on my list - testing performance differences with various progress indicators.