Re: Perl::TK - fileevent and script execution theoryby crabbdean (Pilgrim)
|on Mar 14, 2004 at 12:19 UTC||Need Help??|
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.
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