in reply to Give me my gui back!

It would probably be easier to help if you showed us your code. The relevant bits at least.

It sounds like you already know that the problem is you are attempting to subvert the event loop... as for the best solution... well, that depends.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
To be continued
by Bagarre (Sexton) on Nov 18, 2003 at 03:01 UTC
    I'm going to post here real quick and then pick it up tomorrow morning..

    sauoq, The snipet of code that pg posted is pretty close to the idea except, i need to be able to pause/resume/exit the 'for' loop from the gui at will..

    I could post an example code tomorrow of the way I am doing it now. The whole program is sitting at about 2,000 lines total... I'll have to scratch something basic to give you a better idea of it.

    My head is a little too foggy right now to work on it anymore. :(

    PodMaster, I thought about learning wxPerl as my gui choice but, decided on Tk becasue I could find more documentation on it. Maybe I should go back and give it a second look after I go thru your code you posted.

    As a reference, I've been writing in PERL for the last four years or so with no formal programming schools. Everything I've learned has been on my own... From the seat of my pants or pulled out of a near by place. :) That being said, sometimes I miss the easier ways of doing things. I appreciate the help folks! -David www.packet-security.com
      The snipet of code that pg posted is pretty close to the idea except, i need to be able to pause/resume/exit the 'for' loop from the gui at will..

      Building on pg's example, adding pause and resume is fairly simple:

      use Tk; use Tk::ProgressBar; use strict; use warnings; my $count; my $pause = 0; my $mw = new MainWindow(-title => "demo"); $mw->Button(-command => [\&a_long_process, \$count], -text => "A Long Process")->pack(); $mw->Button(-text => 'Quit', -command => sub{exit})->pack(); $mw->Button(-text => 'Pause', -command => sub{$pause = 1})->pack(); $mw->Button(-text => 'Resume', -command => sub{$pause = 0})->pack(); my $pb = $mw->ProgressBar( -from => 0, -to => 100000, -blocks => 100000, -colors => [0, 'green', 30000, 'yellow' , 60000, 'red'], -variable => \$count )->pack(); MainLoop; sub a_long_process { my $hash = {}; for (0..100000) { $hash->{$_} = $_; $count ++; $mw->update(); if ($pause) { while(1){ select(undef,undef,undef,0.1); last unless $pause; $mw->update(); } } } }

      I used select for subsecond sleeping, Time::HiRes could also be used.