Hello Monks-

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

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.