Progress bar problem

Any idea why this is not working?

				set maximum value of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 3
				set contents of text field "progtext" of box "box" of tab view item "driver" of tab view "tab" of window "main" to "Downloading..."
				set content of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 0
				start progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main"


--------------------
				repeat while newSize is not equal to theFileSize
					delay 3
					tell application "System Events" to set newSize to size of (get properties of (destination_file as alias))
					if newSize < (theFileSize / 3) then
						set content of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 1
					else if newSize < (theFileSize / 1.5) then
						set content of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 2
					else
						set content of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 3
					end if
				end repeat

the problem is that the progress bar goes full instantly.

everything after ------------ is working correct cause if I use dialogs “<30% completed” or “<60% completed” etc. instead of “set content of progress indicator” it works fine.

Hello,

Well, first thing i see that could be a problem is you use this:

start progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main"

and is not necessary in the case where you specify the value yourself to the progress bar. I am assuming that it is a horizontal gray when zero and blue when used kinda progress bar? You would also need to set the indeterminate to false, just to prevent the white/blue crossing. This kind of progress bar needs to be told to start, same for the round ones.

Try removing the line (by changing it to a comment with --) and see what happens.

As for the rest of your code, I dont see anything wrong…

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

thanks, I made some changes and got it to work!

				set maximum value of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to theFileSize
				
				
				set content of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to 0
				set indeterminate of progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main" to false
				
				start progress indicator "progbar" of box "box" of tab view item "driver" of tab view "tab" of window "main"
				set contents of text field "progtext" of box "box" of tab view item "driver" of tab view "tab" of window "main" to "Downloading..."
				

Hi.

You only have to tell your progress indicator once that it lives in the box.
That saves you a lot of typing/pasting code.
So in this case it would look like this.

tell window "main"
  tell box "box" of tab view item "driver" of tab view "tab"
    tell (start progress indicator "progbar") to set {indeterminate, minimum value, maximum value, content, visible } to {false, 0, theFileSize, 0, true}
    set contents of text field "progtext"  to "Downloading..."
  end tell
end tell

Marcus.

This is indeed a better way to code, much easier to read and thus understand. I also tend to create a subroutine (on … end) upon which i call as many times as i want with one line throughout my app.

And just a quick correction in the previous post… this:

tell (start progress indicator "progbar")

should be:

tell (progress indicator "progbar")

no need for the “start”. You only need to tell a progress indicator to start when it is indeterminate, not when it is reflecting an actual value. As reference, the circular round thing you have when you boot your mac, under the apple logo, is an indeterminate progress bar, and needs to be told to start.

Also, fun thing, you can tell a progress indicator to use it’s own thread (uses threaded animation), so it will keep on running even if your app’s UI is non-responsive. Very usefull to let the user know something is still happenning…

Good luck!

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Never quite grasped what the “threading” meant, so nice one.
And while we’re at progress bars;

how to show the percentage progression (e.g. 56%) on top of one,
without getting an I.B. ‘clipped contents’ error?
Any step in the right direction would most warmly be welcomed.

Thanks,
Marcus

Model: iMac 2.16 Ghz IC2D
AppleScript: 2.3 (118)
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

Quickly said, a thread is a an task currently running. AppleScript (any version) is single-threaded, which means you can only do one thing at any given time. An example of a multi-threaded application is iTunes. You can still play music while importing other tracks.

So telling the progress indicator to use a separate thread will tell the system to create a separate task, alongside your app, that will take care of it’s animation. Basically, the animation in the progress indicator (any kind) will not pause or break while your app does something else. Sadly in AppleScript Studio, this is the only thing I know of that allows threading, so I use it every time!

There is ways to “mimic” a multi-threaded app with ASS, but it involves creating shell task via the “do shell script” command that runs in the background, but then you have to keep track of it, if it’s done, etc… not easy, cannot be used for everything, but does the job.

More info here on threads that explains it ten times better than I can:
http://en.wikipedia.org/wiki/Thread_(computer_science)

As for your question, I did not know that the progress indicator had options to display it’s value in a text field… I have checked Xcode Documentation for NSProgressIndicator and there is no mention of this. If I wanted one to display, I would create a text field that sits on top or wherever I’d like and update it’s content either via code or better yet, by using bindings in Interface Builder, binding the text field’s value to the progress indicator’s and using a formatter to display it as a percentage.

Can you expand a bit on what you said? Just curious…

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

leonsimard.

Thanks for the time you’re taking.
The problem is not calculating the progress value. That would be something like:

(round ((max val/100) * the index of the list item or content of the bar) as integer).

The error that the Interface Builder Document Info shows, is:

  • the view of text field 1 - overlaps - one of its sibblings -
    Dito for the pro bar.
    Thus preventing Xcode to build the app.

Does this explain it a little better?

Marcus.

Model: iMac 2.16 Ghz IC2D
AppleScript: 2.3 (118)
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

That’s odd… usually, such kind of warnings do not prevent Xcode to compile the app. However, it will potentially create some odd visual result in the window.

Can you send me a screen shot just to give me an idea of the layout? I’m a visual person :slight_smile: Or better yet, the nib file itself (and only that). Zip it and email it to me, if you want to, of course.

Model: MacBookPro2,2
Browser: Safari 531.9
Operating System: Mac OS X (10.6)

hidee, leonsimard.

I’ll sent you a nib, as soon as I’m back in town.
Presumably next Sunday./
Thanks in advance,

Marcus.