Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by crabbdean (Pilgrim)
on Mar 25, 2004 at 00:33 UTC ( [id://339599]=note: print w/replies, xml ) Need Help??


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

In reference to your last comments about piping to a text box, I've already posted a solution on how to do this. See this --> Re: Perl::TK - fileevent and script execution theory

The two solutions you mentioned above I've tried but this I found works best for short events that don't freeze the gui. My problem at current is an event that takes about 30 mins, a large "tar"ing process. Thanks anyway :-)

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: Perl::Tk - Event sequencing question

Replies are listed 'Best First'.
Re: Re: Re: Perl::Tk - Event sequencing question
by periapt (Hermit) on Apr 30, 2004 at 12:16 UTC
    Yeah, I've had that problem with long running processes too. I once tried to implement an archive process one file at a time with a counter updating the main screen but it was an ugly, inefficient thing. I went with a command line instead.

    Thanks for the link. It answered several questions I've had kicking around in the back of my mind. Maybe I'll be more motivated to try a solution sooner rather than later.

    PJ
      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found