[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] [ANN] Mac::Utils::ProgressBar



Eric Albert writes Thu, 12 Nov 1998 07:13:28 -0800

ProgressBar works very nicely. If this is a first attempt at a MacPerl
Toolbox script (reding between the lines I think it might be) it is a
matter for serious congratulations. I have a few comments which I hope will
in no way detract from the achievement but might be helpful.

Global variables in the module ought to be put into a hash belonging to the
bar object. I am much convinced by arguments put forward some months ago by
Chris Nandor that one should always do this. Security is better and
conflict is avoided if there are concurrent instances of the same object.

It would undoubtedly be better to use 'hooks' for all drawing in the
window. For instance, update events in Windows.pm call on its subroutine
'redraw()' and if if there is no draw routine hooked up to 'redraw()', the
window will not (in general) update properly. If this script is modified
slightly (so that the window stays put after a run) it can be seen that it
does not update at all when covered and uncovered by another window. Whilst
running this doesn't matter so much, since the ProgressBar window is
constantly being redrawn by the program, but it does take two bites at the
cherry nevertheless.

For similar reasons 'new_control()' is usually to be preferred to the raw
NewControl() (for the bar) because new_control() is registered as a pane in
the window and as such it shares in window updates and other events.

For reasons of tidyness the line WaitNextEvent() (to be found in the
calling script ProgressBarTest.pl) might be better put into the module.
Users of ProgressBar, not used to the MacToolbox mght find the need for
that line a bit strange?

Two minor 'bugs' came to light.

When the 'goaway box' is clicked during a run, the window closes. but the
script continues to run. It might be better if the script stopped I think.

Sometimes one of the text strings fails to appear: for some reason 3% never
comes up. That may be connected with the window drawing method, but I'm not
at all sure.

I have experimented on and off with MacPerl 'status' indicators for some
time and have not found one which is secure. Problems (crashes) can occur
if there if there is extensive drawing going on in other MacPerl windows.

I haven't got to the bottom of this, but suspect it is to do with knowing
when it is safe to change the graphics port(s). You can say 'SetPort(here)'
and then 'now draw this here', but MacOS gives no indication back (so far
as I can see) when it has finished. Hence you don't know when it is safe to
release the port.

If anyone is interested in tinkering with this problem I have at least one
script which has crashed all 'staus indicator' attempts except the
application Progress Bar. The fact that PBar is a different application
might be significant.

Incidentally (in the PS to Eric's leter) what is meant by 'indeterminate
state' and why is that wanted?

Alan Fry

>I sat down last night and decided that 'twas a good time to play with the
>progress bar module that I mentioned here recently, so here I am a good bit
>later with a working version.  You can grab a copy of
>Mac::Utils::ProgressBar at
><http://www.stanford.edu/~ejalbert/software/ProgressBar.sit>.
>
>Some basic documentation is included in the ReadMe with the download (I'm
>not quite up to figuring out pod syntax after coding all night), but here's
>a quick overview:  It's an all-Perl progress bar window that's
>Appearance-savvy.  In other words, you don't need the Progress Bar 1.01
>compiled AppleScript that goes along with Mac::Apps::PBar, and you now have
>something that looks nice under MacOS 8 and later (actually, I've only
>tested it under OS 8.5; please let me know if there are problems with
>earlier systems).  In quick tests, it seemed to be about 50% faster than
>Mac::Apps::PBar.
>
>Why Mac::Utils?  Because everything else in the Mac:: hierarchy seems to be
>a Toolbox interface module, which this one isn't (it uses those, but it
>doesn't add to them), and it's a Mac-specific utility.  I'm open to other
>suggestions, though....
>
>Feel free to provide comments on the source code; while I'm comfortable
>with Perl, I certainly don't know much about what would or would not be
>good Perl style, and I'm likely to miss a lot of shortcuts that'll come
>easily to more experienced programmers.
>
>BTW, here's a quick sample program that runs an installer's progress bar
>from 0 to 100% (it's included with the download):
>
>#!perl
>
>use Mac::Utils::ProgressBar;
>use Mac::Events;
>
>my $min=0;
>my $max=100;
>
>my $progressBar=new Mac::Utils::ProgressBar('Progress Bar');
>$progressBar->configure(-header=>'Installing...', -text=>'Text',
>-min=>$min, -max=>$max);
>my $i=$min;
>while($progressBar->inProgress()) {
>        $progressBar->setValue($i++);
>        $progressBar->setText(int (($i-$min)*100/($max-$min))."% done");
>        WaitNextEvent();
>}
>
>-Eric
>
>P.S. to those who are still reading: This module doesn't support a progress
>bar's indeterminate state because there's no SetControlData function in
>Controls.pm.  Are there any plans to add this?  It seems a bit of a strange
>omission, but then again, I don't know all that much about the Toolbox....
>
>--
>Eric Albert                     ejalbert@cs.stanford.edu
>http://www.stanford.edu/~ejalbert/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch