Progress Bar Example

Sarah Reichelt sarah.reichelt at gmail.com
Fri Mar 24 16:42:06 EST 2006


On 3/25/06, Jeff Honken <jhonken at x12.info> wrote:
>
> I would like to use a "progress bar" to monitor a "go stack URL".  I'm
> clueless on how to write the code.  Does someone have an example of this
> or can someone please point me in the correct direction. Jeff

I haven't done it using stacks, but I have done it for downloading
pictures from the web and I guess it's much the same. Firstly, you
need to use "load" instead of "go". This is non-blocking and reports
it's status so you can show what's happening.

Here is part of the handler I use to start a download. It sets the
status callback object to a progress bar and then starts loading. When
it is finished, it's going to call the "picDownloaded" handler.


on downloadFile pAddress
  libURLSetStatusCallback "showStatus", the long ID of sb "Progress"
of stack "Download"
  load URL pAddress with message "picDownloaded"
end downloadFile

In the script of the scrollbar, I have this:

on showStatus pURL, pStatus
  if item 1 of pStatus = "loading" then
    put item 2 of pStatus into tNow
    put item 3 of pStatus into tEnd

    if the visible of sb "Progress" = false then
      -- hasn't started yet
      set the endValue of  sb "Progress" to tEnd
      set the thumbPos of  sb "Progress" to tNow
      show  sb "Progress"
    else
      set the thumbPos of  sb "Progress" to tNow
    end if

  else if pStatus = "error" then
    libURLSetStatusCallback
    set the dialogData to empty
    close this stack
   end if
end showStatus

which sets the range of the progress bar and shows it if not already
visible, otherwise it just moves the progress bar. If there is an
error, it gets out.

Back in my download script, I have the handler that gets called after
the download is finished. This is in the same script as the
downloadFile handler:

on picDownloaded pURL, pStatus
    libURLSetStatusCallback
    set the dialogData to URL pURL
    unload URL pURL
 end picDownloaded

This puts the newloy downloaded data into a variable (I'm using the
dialogData as it downloads from a separate dialog stack), and then
unloads the file so that it isn't held in two places of memory at
once.

At this point, you could have a "go to stack pURL" line.

Let me know if this doesn't work or if you have any further questions.

Cheers,
Sarah



More information about the Use-livecode mailing list