Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

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


Comment on Re: Re: Re: Re: Perl::Tk - Event sequencing question
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://349572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2014-07-23 17:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (148 votes), past polls