Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Perl TK

by JojoLinkyBob (Scribe)
on May 10, 2001 at 04:45 UTC ( [id://79305]=note: print w/replies, xml ) Need Help??


in reply to Perl TK

Ah Yes, I had this problem before, here's a quick-and-dirty progress bar script that uses and example
#progress bar that monitors a compile, #by counting .o's periodically use Tk; sub tick; $total_objects = 303; $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("\\as900\\code\\build\\*.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;

This gives you the capability of a timer callback.
Desert coder

Replies are listed 'Best First'.
Re: Re: Perl TK
by HamNRye (Monk) on May 10, 2001 at 21:28 UTC

    Just making sure I have this right....

    A script that might look like this:

    use Tk; my_long_sub { print "You can't kill me!\n"; sleep 60; my_long_sub(); } $main = MainWindow->new; $main->Button( -text "Start Long Sub", -command \&my_long_sub)->pack;

    Could (and should?) be written thusly:

    use Tk; $seconds = 60; not_a_long_sub { print "You can't kill me!\n"; #sleep 60; <-Replacing this with an after #my_long_sub(); <-After handles the call } $main = MainWindow->new; $main->Button( -text "Start Long Sub", -command \&not_a_long_sub)->pac +k; $main->after($seconds * 1000, \&not_a_long_sub);

    This assumes the after counts in Milliseconds. (Like Tk)

    Sorry to work this out in public, but I wanted to get my brain around it quick.... If anyone gathers the notion that I havent grokked this fully, let me know.

      That looks efficient to me.
      Desert coder

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found