OK...

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(); } } } }



Below is my original post
Hello all,

I just made a nice gui from Tk (first time) for a program I wrote. It allows you to load up a config file, designate tasks... and a bunch of status bars and other stuff. The problem is, when I press the "Run" button, the gui freezes until the program is done, and then updates all the status bars and such.
I need to fork off the 'run_program' subroutine so I can return to Mainloop() but, then I loose control of the child and I still don't know the status of the program. (Everything I need is an a hash of hashes that is being built as 'run_program' runs.
IPC::Shareable sounds like it would fix all of my problems but, I'm running Win32... Is there a way this easily?
I've been banging on this for the last two days and haven't come up with anything yet except for a very complex set of pipes between programs.

Thanks for any help
-David

In reply to Give me my gui back! by Bagarre

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.