Here's an graphical example using Tk. I wrote this to measure the progress of a compile (count's .o's in the build directory), but it can easily be tweakified for your own purposes.
Enjoy.
use Tk;
sub tick;
$MYBUILDDIR="c:\\build"; #Dont forget to backslash the backslashes
$total_objects = 303; #Number of object files a full build would creat
+e
$progressbar_width = 2*$total_objects;
$progressbar_height = 50;
$timer_interval=10; #in seconds
$MW = MainWindow->new;
$MW->bind('<Control-c>' => \&exit);
$MW->bind('<Control-q>' => \&exit);
$canvas1 = $MW->Canvas(
'-width' => $progressbar_width,
-height => $progressbar_height,
-background => 'black'
) -> pack;
$newval = 10;
$start = $MW->Button(
-text => 'Start',
-command => sub {tick},
);
$start->pack(-side => 'left', -fill => 'both', -expand => 'yes');
sub tick {
# Update the counter every 5 seconds
$MW->after($timer_interval * 1000, \&tick);
$num_objs = @objects = glob($MYBUILDIR . "*.o");
print "\n$num_objs out of $total_objects built so far...";
$newval = ($num_objs / $total_objects)*$progressbar_width;
$canvas1->create ('rectangle','0','0',$newval,$progressbar_height,
+-fill=>'red');
}
MainLoop;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|