|Perl: the Markov chain saw|
Perl::Tk - Event sequencing questionby crabbdean (Pilgrim)
|on Mar 23, 2004 at 11:59 UTC||Need Help??|
crabbdean has asked for the
wisdom of the Perl Monks concerning the following question:
Hi Fellow Monks,
This is more of a Perl::Tk theory question. In normal procedural-flow programming one event leads on from the next, the output it processed onto the screen or console - its pretty standard. Tk is event driven and I'm coming to terms with its nature and how to program it. In doing so one develops a different way of having to think about structuring a program. If you click a button, X-event happens, screen changes, new widget developed, a small action taken, next button pushed and so on and so on ...
But my theory questions begins here ... what is the best way to program a long procedural like flow in Tk???
1. Do a foreach loop and create and destroy a MainWindow for each directory. (Doesn't sound very gui pretty). In essence this is saying - to create a procedural like flow do you create and destroy the MainWindow to create the appearance of a procedural flow?
2. Can you get Tk to wait until one "fileevent" is done? Not sure how this would be achieved.
3. Do you string each event together via subroutines, creating a subroutine stack. That is, when one subroutine finishes it then calls the next tar, in effect creating a procedural-like flow from one subroutine to the next (replicating the procedural like flow of normal programming but giving the gui its fluid setp by step appearance?
For example I have a program that does a massive "tar" archiving. This requires calling the tar command using "fileevent" and then piping the output from all this to a text widget. "Fileevent" is used so the gui doesn't give the appearance of freezing. But my problem is I want to do consecutive tar's on different directories!!
In normal procedural-flow programming you'd do a "foreach" loop for each directory you want to tar. When one tar finishes it moves onto the next one. In Tk using "fileevent" this isn't possible because it doesn't suspend the background process, thereby keeping the gui "up-to-date". The event queuing is stuffed. Being event driven the "tar"'s get called rapidly in succession within the MainWindow and don't work.
How do I resolve this? I can give code but I think my explanation is enough for anyone who knows Tk.
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