progress bar example
Nicolas Cueto
niconiko at gmail.com
Thu Jul 10 07:50:33 EDT 2008
Hello,
A few years back, Dave Cragg was
kind enough to explain in detail how
to build a stack that shows the progress
of a download (I've included his message
below).
The script works, but there's a glitch.
When the progress-stack is called up
only its edge can be seen. Its body,
instead of showing a progres bar
increasing as the download progresses,
shows nothing but a freeze-view of whatever
was on the screen beneath it before it
popped open.
I've tried setting buffer properties,
but that did not work.
Is there a way of getting this to work?
Thank you.
-- Nicolas Cueto
<here's Dave Cragg's message and script>
You can show status using "go" as well. libUrlSetStatusCallback works
for both blocking (e.g. load url) and non-blocking (.e.g. get url)
calls.
Below is the script of a *very crude* progress palette. The stack
consists of two fields (one named "url" and the other named
"status"), and a scrollbar (progress bar) named "progress" . Name the
stack "url_status" (or anything you want).
Make this stack a substack of your main stack. Then somewhere (e.g in
your mainstack's preopenstack handler), include the following:
start using "url_status"
That's it. After that, it should work for all downloads and uploads
(which may not be what you want).
Cheers
Dave
--------------------------------------------------
local sUrls
----------------------------
on libraryStack
libUrlSetStatusCallback "urlCallback", the long id of me
palette me
hide me
end libraryStack
-------------------------
on releaseStack
libUrlSetStatusCallback empty
close me
end releaseStack
---------------------------
on urlCallback pUrl, pStatusString
show me
put pUrl into field "url" of card 1 of me
put item 1 of pStatusString into tStatus
put tStatus into field "status" of card 1 of me
put 1 into sUrls[pUrl]
if tStatus is among the items of "loading,downloading,uploading" then
put item 2 of pStatusString into tPart
put item 3 of pStatusString into tWhole
if tWhole <> empty then
showProgress tPart,tWhole
else
hide scrollbar "progress" of me
put "," && tPart && "bytes" after field "status" of card 1 of me
end if
--unlock screen
else if tStatus is among the items of
"loaded,downloaded,uploaded,cached" then
delete local sUrls[pUrl]
if the visible of scrollbar "progress" of me then showProgress 1,1
send "hideStatus" to me in 200 milliseconds ##leave visible for
short time
else if tStatus is among the items of "error,timeout" then
delete local sUrls[pUrl]
send "hideStatus" to me in 200 milliseconds ##leave visible for
short time
else
hide scrollbar "progress" of me
end if
end urlCallback
-------------------------
on showProgress pPart,pWhole
put the endValue of scrollbar "progress" of me into tMax
set the thumbPosition of scrollbar "progress" of me to round(tMax
* pPart / pWhole)
show scrollbar "progress" of me
wait 10 milliseconds
end showProgress
-----------------------
on hideStatus
if keys(sUrls) is empty then
hide me
end if
end hideStatus
More information about the use-livecode
mailing list