You know after some thought and investigation it became apparant to me that if you have a long running process you always need to output the "fileevent" using the below subroutine. If not your gui freezes until the event finishes. Personally I think this subroutine should included as a feature or at least in the code given in the "fileevent" documentation considering it appears to be a common thing people want to do.
Essentially it goes like this ... create a widget to write to (a scrollable text box in your mainwindow $mw in this example), open your handle and call the fileevent ...
my $tx = $mw->Scrolled("Text", -width => 80,
-height => 25,
-wrap => 'none',
)->pack(-expand => 1,
-fill => 'both');
open(CHILD, "ls -laR |") or die "Can't open: $!";
CHILD->autoflush(1);
$mw->fileevent('CHILD', 'readable', [\&output, \*CHILD, $mw, $tx]);
Include the following subroutine to output what is streamed to the filehandle without freezing the GUI.
sub output {
my ($handle, $widget, $tx) = @_;
if (sysread ($handle, $_, 128)) {
$tx->insert('end', $_); # Append the data read
$tx->yview('end');
} else {
$tx->insert('end', "\nALL DONE\n");
$tx->yview('end');
$widget->fileevent($handle, "readable", undef); # cancel bindi
+ng
###----->>> Add in cancel routine here if you want to exit gra
+cefully
return;
}
$widget->idletasks;
}
|