I have a perl script with a pTk text window being fed input from a single POE session (POE::Wheel::FollowTail) and want to destroy it while keeping the GUI up and running.
I can't seem to make this happen (see code below). When I hit the Stop button, the perl script exits. Also, if the input file is big enough, and you hit the stop button before its all been read, the stop button seems to have no effect. I suspect I'm doing something stupid here, but just can't see it.
Any help appreciated!
Thanks
-Craig
use strict; use warnings; use Tk; # This MUST come before use POE... use POE; use POE::Wheel::FollowTail; # Use any nearby file for input... my $ifile = shift || die "Missing input file"; _displayData(); print STDERR "STARTING to process data...\n"; _processData($ifile); POE::Kernel->run; exit; sub _processData{ my $ifile=shift || die "Missing input file"; POE::Session->create( inline_states=>{ _start=>sub { print "Session ", $_[SESSION]->ID, " has started.\n"; $_[KERNEL]->alias_set("myClient"); my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; $_[HEAP]->{wheel}=POE::Wheel::FollowTail->new( Seek=>0, Filename=>$ifile, InputEvent=>'display', ); }, display => sub{ InputEvent=>$_[KERNEL]->post(Display=>data=>$_[ARG0]), }, sendStop => sub{ print "Stopping file input\n"; my $heap = $_[HEAP]; delete $heap->{wheel}; }, }, ), } sub _displayData{ my $text; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set("Display"); my $kernel=$_[KERNEL]; my $top = $poe_main_window; $top->Button(-text=>"Stop", -command=>sub{ stop($kernel)})-> pack(-side=>'bottom'); $text = $top->Scrolled('Text', -scrollbars=>'osow', -wrap=>'none')-> pack(-fill=>'both',-side=>'left', -expand=>1); }, data=>sub{ $text->insert(end=>$_[ARG0] . "\n"); $text->update; }, }); } sub stop{ my $ker = shift; if ($ker){ print STDERR "Sending sendStop to myClient\n"; $ker->call("myClient","sendStop"); } }
In reply to Confusion with POE & pTk by cmv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |