[Tutor] TCL fileevent --> Python ???
Evgeny Roubinchtein
eroubinc@u.washington.edu
Sun, 29 Aug 1999 15:59:38 -0700 (PDT)
I am teaching myself Tkinter by rewriting the examples in "Practical
Programming in TCL and Tk" in Python. They have a sample application
which runs a command and captures and displays the commands output in a
Text widget. The user types the command in an Entry widget, clicks the
"Run" button and then "it cooks". I am stuck on translating the "Run"
button's callback; the TCL code is:
proc Run {} {
global command input log btnRun
# command -- is the text user typed in the Entry widget
# log -- is the Text widget in which the command's output is captured
# btnRun -- is the "Run" button
if [catch {open "| $command |& cat"} input] {
# some kind of error happened
$log insert end $input\n
} else {
# opened the pipe OK
fileevent $input readable Log # call Log whenever something
# comes in from the pipe
# how do you say something similar
# in Python?
$log insert end $command\n
$btnRun config -text Stop -command Stop
}
}
Well, I am sort of stumped on translating "fileevent": looking at its
man page, it behaves just like the TK/Tkinter's "bind" method, except
that "bind" calls a procedure when there's an X event, and "filevent"
calls procedure when some input is waiting to be read, so the read
won't 'block', so the application doesn't look "frozen" to the user.
Looking through Python library I didn't find anything I could use "out
of the box", I think if I started a new thread (or used fork) I could
have one process/thread handling the input from the pipe and the other
handling the button clicks -- I will play with that idea but if this
sounds like something someone has done before, I would love to hear
from them.
Thank you
--
Evgeny Roubinchtein, eroubinc@u.washington.edu
...................
..... REALITY.SYS Corrupted - Unable to recover Universe