Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: [Tkx] Buffering/Updating issue for text element

by zentara (Archbishop)
on Aug 27, 2010 at 11:31 UTC ( #857669=note: print w/ replies, xml ) Need Help??


in reply to [Tkx] Buffering/Updating issue for text element

I'm not a Tkx guru, but you should never use "sleep" in a GUI app, as it will interfere with the eventloop. As others have pointed out, you can hack around a sleep statement usage, with "$mw->updates" sprinkled around, but that is a poor way to write the code.

Almost always, you avoid the problem by setting up a timer, rather than use sleep. Try taking the sleep(1) out of your code, and see if that speeds up the text inserts. A timer in Tkx would look something like the following.

See Tkx repeat in case you are forced to use after to simulate repeat. I don't know if Tkx has a repeat

# untested pseudocode sub start{ my @ids = (1..10); # repeat may not be available in Tkx.... see link above Tkx::repeat(1000, sub { my $id = shift @ids; if ($id <= 10){ $txt_processed_domains->configure(-state => "normal"); $txt_processed_domains->insert_end( "$id => Available\n" ); $txt_processed_domains->configure(-state => "disabled"); } else { Tkx::tk___messageBox( -message => "Completed!" ); } }); }

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


Comment on Re: [Tkx] Buffering/Updating issue for text element
Download Code
Re^2: [Tkx] Buffering/Updating issue for text element
by Gangabass (Priest) on Aug 28, 2010 at 00:19 UTC
    Thanks for Tkx::repeat but i use sleep only to show the issue. In real code i have HTTP request and text insert after it.
      Not to be picky about it, but don't even use sleep to demonstrate a slowdown..... in a GUI it completely gives you bad behavior.

      Here is one way to make a non-blocking delay without sleep

      #!/usr/bin/perl use warnings; use strict; use Tk; $|=1; my $count = 0; my $loop = 0; my $mw = new MainWindow(); $mw->Label( -textvariable => \$count )->pack; $mw->Button( -text => 'Start', -command => \&long_job ) ->pack( -side => 'left' ); $mw->Button( -text => 'Stop', -command => sub { $loop = 0; print "$cou +nt\n"; } ) ->pack( -side => 'left' ); MainLoop(); sub long_job { my $var; my $timer = $mw->repeat(1000, sub{$var++} ); $loop =1; while($loop){ $loop++; $mw->waitVariable(\$var); $count++; } DoOneEvent(); }

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
        Isn't that a pirate site?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://857669]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-10-31 16:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (221 votes), past polls