Bagarre has asked for the wisdom of the Perl Monks concerning the following question:
I think I have somethig close to what I am doing.
Instead of sleep x; imagine those are various Win32::Lanman calls that take from 1 to 5 seconds each.
I changed it to a Pulldown Menu to better show the lag in the gui. It's almost bearable if I tear off the menu and pepper my code with $mw->update(); but, that seems like cheating.
Any comments on how I'm trying to do this or my code in general are more than welcome.
Here's what I did:
#! c:\perl\bin\perl.exe use Tk; use Tk::ProgressBar; use strict; # Had to turn off because of how I build %Items use warnings; my $pause = 0; my $count = 0; my %Items; # Just to build the hash. It's actualy a nest of other data under it. # {'status'}.. {'message'}.. {'tasks'}.. {'history'}[$histcount++].... + until ($count >= 10 ) { $Items{$count}{'status'} = "1"; $count++; } my $mw = new MainWindow(-title => "demo"); $mw->configure(-menu => my $menubar = $mw->Menu); my $control = $menubar->cascade(-label => "~Control"); $control->command( -label => "Run", -command => \&a_long_process ); $control->command( -label => "Pause", -command => sub {$pause = 1;} ); $control->command( -label => "Resume", -command => sub {$pause = 0; } ); $control->command( -label => "Run", -command => sub{exit;}); my $F_Status = $mw->Frame( -relief => 'groove')->pack(-side => 'bott +om', -expand => 1, -fill => 'x'); $F_Status->Label(-text => ' Status:')->pack( -side => 'left'); $F_Status->Label(-textvariable => \$pause )->pack( -side => 'left'); my $F_Status_Target; # Build P-Bars foreach (keys %Items ) { $F_Status_Target = $mw->Frame( -relief => 'raised', -borderwidth => 1); $F_Status_Target->pack( -side => 'bottom' ); $F_Status_Target->Label( -text => $_, -width => 5 )->pack( -side => +'left'); $F_Status_Target->ProgressBar( -from => 0, -to => 500, -blocks => 500, -colors => [0, 'blue'], -variable => \$Items{$_}{'p_bar'} )->pack( -side => 'left'); $Items{$_}{'p_bar'} = 10; # Initial set } MainLoop; sub a_long_process { foreach $_ (keys %Items ) { print "$_\n"; sleep 5; # In my case, map a drive, copy a file, schedule a task.. +.. $Items{$_}{'p_bar'} = 100; $mw->update(); sleep 2; # In my case, map a drive, copy a file, schedule a task.. +.. $Items{$_}{'p_bar'} = 300; $mw->update(); sleep 4; # In my case, map a drive, copy a file, schedule a task.. +.. $Items{$_}{'p_bar'} = 500; $mw->update(); if ($pause) { while(1) { select(undef,undef,undef,0.1); last unless $pause; $mw->update(); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Give me my gui back!
by pg (Canon) on Nov 18, 2003 at 01:40 UTC | |
|
Re: Give me my gui back!
by PodMaster (Abbot) on Nov 18, 2003 at 01:57 UTC | |
|
Re: Give me my gui back!
by sauoq (Abbot) on Nov 18, 2003 at 01:32 UTC | |
by Bagarre (Sexton) on Nov 18, 2003 at 03:01 UTC | |
by Anonymous Monk on Nov 18, 2003 at 04:15 UTC | |
|
Re: Give me my gui back!
by etcshadow (Priest) on Nov 18, 2003 at 01:51 UTC | |
|
Re: Give me my gui back!
by zentara (Cardinal) on Nov 18, 2003 at 15:15 UTC | |
by Bagarre (Sexton) on Nov 18, 2003 at 19:28 UTC | |
by iburrell (Chaplain) on Nov 19, 2003 at 00:14 UTC | |
by Anonymous Monk on Nov 19, 2003 at 10:41 UTC | |
by Anonymous Monk on Nov 19, 2003 at 10:44 UTC | |
|
Re: Why not replace MainLoop?
by Anonymous Monk on Nov 19, 2003 at 01:39 UTC | |
by Bagarre (Sexton) on Nov 19, 2003 at 13:47 UTC |