Message Board for Rorohiko Workflow Resources
https://www.rorohiko.com/cgi-bin/yabb2/YaBB.pl
General Category >> General Board >> progress bar won't terminate
https://www.rorohiko.com/cgi-bin/yabb2/YaBB.pl?num=1153237036

Message started by jpobojewski on 07/19/06 at 03:37:16

Title: progress bar won't terminate
Post by jpobojewski on 07/19/06 at 03:37:16
Kris,

Great product! I am currently doing some initial testing for your progress bar and cannot get the window to terminate either when a) the script ends or b) I press cancel when the [showCancelButton] is set to 'true.' Here's a little snippet for context:

function drawBoxes(total) {
   var progBar = _item.createProgressBar("Test Bar", 0, 100, false);    
   for (var i=0; i< total; i++){
       var t = _page.rectangles.add();
       t.fillColor = _doc.swatches[0];
       var rx = Math.random()*_page_width;
       var ry = Math.random()*_page_height;
       var newBounds = [ry, rx, ry+Math.random()*5, rx+Math.random()*5];
       t.geometricBounds = newBounds;
       var per = (i/total)*100;
       t.setProgress(parseInt(per));
   }
}

Just wondering what I'm doing wrong. Thanks in advance.

John Pobojewski / 3ST

Title: Re: progress bar won't terminate
Post by Kris Coppieters on 07/19/06 at 08:08:13
Hi John!

First the simple solution - which might or might not work for you depending on the context of what you're doing:


Code (]
function drawBoxes(total) {
    var progBar = _item.createProgressBar("Test Bar", 0, total, true);
   var i = 0;   
   var cancelled = false;
    while (i < total && ! cancelled) {
        var t = _page.rectangles.add();
        t.fillColor = _doc.swatches[0):

;
        var rx = Math.random()*_page_width;
        var ry = Math.random()*_page_height;
        var newBounds = [ry, rx, ry+Math.random()*5, rx+Math.random()*5];
        t.geometricBounds = newBounds;
        cancelled = t.setProgress(i);
       i++;
    }
}


It is better to use the proper range in your progress bar (i.e. 0-total) instead of using 0-100 and then transform your progress to a value between 0-100.

For cancel handling also need to check the return value of t.setProgress(i) - it will normally return 'false' but if the user clicks 'Cancel' it will return 'true'. My example loop terminates as soon as the user clicks cancel.

Now the more detailed stuff. Progress bars and event handlers are intricately linked - if you create a progress bar it will only disappear when the event handler you're in terminates. Normally, that is when the user causes some handler to fire (selecting, modifying, selecting menu item,...) - the idea is that the progress bar comes up and disappears when the handler finishes.

So, the best way is to not relate progress bars to functions (as your example is doing) but rather to 'user actions' - show bar at beginning of user action (read - event handler), and it will auto-disappear at the end.

However, if you want to show and hide progress bars on-the-fly, there is a little trick: wrap your function into an event handler and the bar will disappear when the handler ends.

Try this:


Code (]
_item.javaScript = "drawBoxes(100);"
_item.eventFilter = "drawBoxesEvent";
_item.handleScriptEvent("drawBoxesEvent");

function drawBoxes(total) {
    var progBar = _item.createProgressBar("Test Bar", 0, total, true);
   var i = 0;   
   var cancelled = false;
    while (i < total && ! cancelled) {
        var t = _page.rectangles.add();
        t.fillColor = _doc.swatches[0):

;
        var rx = Math.random()*_page_width;
        var ry = Math.random()*_page_height;
        var newBounds = [ry, rx, ry+Math.random()*5, rx+Math.random()*5];
        t.geometricBounds = newBounds;
        cancelled = t.setProgress(i);
       i++;
    }
}


I used '_item' (which I assume is some page item) and temporarily assigned it a simple, one-line JavaScript:

drawBoxes(100);

Then I gave it an event code in its event filter (I randomly named it 'drawBoxesEvent'), and finally I sent the event to _item.
So, I replaced the single line

drawBoxes(100);

with three lines:

_item.javaScript = "drawBoxes(100);"
_item.eventFilter = "drawBoxesEvent";
_item.handleScriptEvent("drawBoxesEvent");

The end result is that the drawBoxes call is wrapped inside an event, so when the drawBoxes(100) is done, the progress bar will disappear.

Title: Re: progress bar won't terminate
Post by jpobojewski on 07/19/06 at 08:44:51
Kris,

Works like a charm AND now I know how to trigger your event handlers. Thanks so much!

J

Title: Re: progress bar won't terminate
Post by Kris Coppieters on 07/19/06 at 08:51:39
P.S. as a result of your question - for the coming version 1.0.25 I've added a small new feature which will remove the need for the 'wrapping' all together.

From 1.0.25 onwards, you'll be able to make the progress bar disappear by setting its progress value beyond its range - so if the range is 0-100, and you set the progress value to 101 it will disappear.

That will allow the use of the progress bar without artificially having to wrap stuff in an event handler - much better! It also makes using the progress bar from standard ExtendScripts (which sit on the Scripts palette) much easier.

Thanks for asking questions! Feedback like this helps us tremendously in figuring out what shortcomings we need to address first!



Title: Re: progress bar won't terminate
Post by Kris Coppieters on 08/02/06 at 07:48:57
Ok, version 1.0.26 is available which has the new behavior - setting the progress value beyond the range makes the progress window close...

http://www.rorohiko.com/activepageitemsdeveloper.html

Message Board for Rorohiko Workflow Resources » Powered by YaBB 2.5.2!
YaBB Forum Software © 2000-2024. All Rights Reserved.