Welcome, Guest. Please Login
Rorohiko Workflow Resources
  Welcome the Message Board of Rorohiko Workflow Resources. To register, please e-mail [email protected] - automatic registration has been turned off because of relentless spambots and spammers. This Message Board is not actively monitored. If you have an urgent question, please e-mail [email protected]. If you post it here, it will probably be many weeks before we notice.
  HomeHelpSearchLogin  
 
Page Index Toggle Pages: 1
Send Topic Print
progress bar won't terminate (Read 8872 times)
jpobojewski
YaBB Newbies
*
Offline


90% Designer / 10% Programmer

Posts: 2
Gender: male
progress bar won't terminate
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
Back to top
 
 
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: progress bar won't terminate
Reply #1 - 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++;
    }
}
[/code]

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++;
    }
}
[/code]

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 [i]inside[/i] an event, so when the drawBoxes(100) is done, the progress bar will disappear.
Back to top
 

Kris
WWW  
IP Logged
 
jpobojewski
YaBB Newbies
*
Offline


90% Designer / 10% Programmer

Posts: 2
Gender: male
Re: progress bar won't terminate
Reply #2 - 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
Back to top
 
 
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: progress bar won't terminate
Reply #3 - 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!


Back to top
 

Kris
WWW  
IP Logged
 
Kris Coppieters
YaBB Administrator
*****
Offline



Posts: 181
New Zealand
Gender: male
Re: progress bar won't terminate
Reply #4 - 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
Back to top
 

Kris
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print