Folks-

I'm trying to write a GUI with Tk and POE, that simply reads in and parses text from a file, then puts up some GUI elements to represent the data. I want the data to be read in a line at a time, and for the data input, and GUI output to be done in real time (reason for POE). The GUI elements should always be active (ie the scroll bar should always scroll).

The program below shows my first attempt at a simple read-it-in-and-print-it-out scenario. This program seems to act strangely.

As you can see, I chose to use a single POE session (this may be the root of my problem), and use Tk's fileevent to handle the input. I assumed that POE would take care of sharing between reading input and doing GUI stuff (I suspect I'm wrong here for some reason).

When I run this, the Text window comes up blank, then I see the entire contents of the input file on STDOUT, then the Text window is updated.

Trying to scroll the Text window is very slow once all the text is there.

Whatever happened to the sleep?

I also don't understand why I should have to put "update" lines in there.

If I comment out the "update" lines, then the sleep get's hit, but the text window never shows up.

Any help or pointers is very much appreciated!

Thanks

-Craig

use English; use strict; use warnings; use Data::Dumper; use Tk; use POE; my $TXT; # Create file descriptor from input file name... my $infile = shift || die "Missing input file"; open(IFILE, "<$infile") || die "Cannot open $infile: $!"; my $IN = *IFILE{IO}; my $session = POE::Session->create( inline_states=>{ _start=>sub { $TXT = $poe_main_window->Scrolled('Text')->pack; $poe_main_window->update; $poe_main_window->fileevent ( $IN , 'readable', sub { _GetInput($IN) } ); }, }, ); # Create a dummy postback so the session won't die... my $subref = $session->postback('DontDie'); $poe_kernel->run(); sub _GetInput { my $ifile = shift || die "Missing File Descriptor"; if(eof($ifile)) { $poe_main_window->fileevent($ifile, 'readable', ''); return; } my $line = <$ifile> || die "Cannot read $!"; print STDERR $line; $TXT->insert('end', $line); $TXT->update; sleep 1; }

In reply to POE/Tk/Fileevent Strangeness 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.