Okay, thanks merlyn and zentara in this node for their responses, it very much helped. Although what I was attempting to achieve could be seen in the TK::ExecuteCommand module I wanted to know and write how to output an open stream to a widget (notably a text Widget). By open stream I mean STDOUT or any open pipe, or Filehandle. The rest you can read in the responses and discussion of this node.

Outputting to a text widget is all fine and dandy if what you are reading and outputting is small, because the population of the data to gui is relatively fast. But try executing a script or outputting a large amount of data like a listing of your entire hard drive and your gui freezes until it finishes the read. For all intensive purpose your gui looks like its crapped itself, while its off busily working in the background. The event driven nature of TK means it will process this event before continuing and updating the display or the next event.

The TK::fileevent module is designed to execute a callback when a FileHandle becomes either writable or readable. Great sounds good!! Although, my problem came in the implementation of this, which you can read about in this node. Finally here is the solution below. The "$widget->idletasks" method helps with the updating of the display when the widget changes or in this case is populated with more data, which fixes the apparant freezing problem. Calling "idletasks" for the MainWindow or the text widget within the callback both worked although on the Text Widget would require less redraw and is most likely faster, hence the solution below. I found trying to call "idletasks" within the MainLoop didn't work.

Below is the final solution. Hope that helps.

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
#!/usr/bin/perl use warnings; use strict; use Tk; use IO::Handle; open(CHILD, "e:\\cygwin\\bin\\ls -laR c: |") or die "Can't open: $!"; my $mw = new MainWindow; my $t = $mw->Scrolled("Text", -width => 80, -height => 25, -wrap => 'n +one'); $t->pack(-expand => 1); CHILD->autoflush(1); $mw->fileevent('CHILD', 'readable', [\&fill_text_widget, $mw]); MainLoop; sub fill_text_widget { my ($widget) = @_; if (eof(CHILD)) { $widget->fileevent('CHILD', "readable", undef); # cancel bindi +ng return ; } if (sysread ('CHILD', $_, 1028)) { $t->insert('end', $_); # Append the data read $t->yview('end'); $widget->bell; } else { # sysread returned undef. Problem with file $widget->fileevent('CHILD', "readable", undef); # cancel bindi +ng } $t->idletasks; }

In reply to Re: Perl::TK - fileevent and script execution theory by crabbdean
in thread Perl::TK - fileevent and script execution theory by crabbdean

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.