in reply to Re^3: Tk + threads
in thread Tk + threads
Thanks again! I'll take a look at that. Meanwhile, further work with your original suggestion has produced something like this (not complete):
my $Q = new Thread::Queue; my $mw = MainWindow->new(); my $run_button = $mw -> Button(-text => "Run Programs", -command=> sub { threads->create(\&runprogs, $Q)->detach(); &view_out; + }); sub runprogs { # run the main script my $pipe = IO::Pipe->new(); $pipe->reader("$script $args 2>&1"); $Q->enqueue( $_ ) while <$pipe>; $Q->enqueue ( undef ); sleep; } sub view_out { # create display window my $top = $mw-> Toplevel(); my $label = $top -> Label(-text=>"Script output",-relief=>"groove")- +>pack(); my $ro = $top->Scrolled('ROText', -width => 60, -height=>20, -scroll +bars=>"e")->pack(); # continuously display output while (my $thingy = $Q->dequeue_nb()) { last unless (defined $thingy); $ro->insert("end", "$thingy"); $ro->update(); sleep 1; } # add close button my $close = $top -> Button(-text=>"Close window", -command => sub { +destroy $top; })->pack(); }
This works, but if I omit the "sleep" from &runprogs, or have a return in there then all manner of horrible things happen. Presumably this is because I have misunderstood how this all works and cocked up the queueing somehow.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Tk + threads
by BrowserUk (Patriarch) on Jan 10, 2006 at 18:24 UTC | |
by knirirr (Scribe) on Jan 11, 2006 at 09:27 UTC |