Just for the sake of discussion........
The problem which you present and the solution which you chose, have been talked about numerous times in different Tk threads...usually named something like "updating my Tk window".
Without seeing your code, but from your description, it sounds like the solution you have selected, is "not finely grained in realtime". It sounds like you upload a file, and when it's done, report it is done with a count of total_done and total_max. Thats usually good enough, but what if the files are very big, and take many minutes between updates?
In those cases you need to find an "upload subroutine" which triggers a callback for every 10k transfered. Now wget, curl, and lwp all have methods for downloading with this callback. If you search around through the snippets section, you should find examples with Tk.
Here is the basic lwp code for doing it. I'm just showing the lwp code, but you could see how to it could be incorporated into your Tk code to show a progessbar. Like I said, it makes a difference when your files are big, and bandwidth is low.
Check out tk-http-file-upload-w-progress
#!/usr/bin/perl -w #from lwpcook use LWP::UserAgent; $ua = LWP::UserAgent->new; $URL = 'http://zentara.net/zentara1.avi'; $filename = substr( $URL, rindex( $URL, "/" ) + 1 ); #print "$filename\n"; open( IN, ">$filename" ) or die $!; my $expected_length; my $bytes_received = 0; my $res = $ua->request(HTTP::Request->new(GET => $URL), sub { my ( $chunk, $res ) = @_; $bytes_received += length($chunk); unless ( defined $expected_length ) { $expected_length = $res->content_length || 0; } if ($expected_length) { printf STDERR "%d%% - ", 100 * $bytes_received / $expected +_length; } print STDERR "$bytes_received bytes received\n"; # XXX Should really do something with the chunk itself print IN $chunk; } ); print $res->status_line, "\n"; close IN; exit;
In reply to Re: Tk and realtime logging.
by zentara
in thread Tk and realtime logging.
by injunjoel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |