Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A combination of $Widget->update; and $framename->see("end"); did it. Im still open to suggestions though if anyone sees a problem with my current solution.

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;

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Tk and realtime logging. by zentara
in thread Tk and realtime logging. by injunjoel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found