Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Re: Re: Re: Perl::Tk - Event sequencing question

by crabbdean (Pilgrim)
on May 01, 2004 at 04:41 UTC ( #349572=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Perl::Tk - Event sequencing question
in thread Perl::Tk - Event sequencing question

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; }

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://349572]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2018-03-25 02:21 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.