Steve McClure schrieb:
On Sun, 2005-04-03 at 18:11 +0200, Marcus Habermehl wrote:
Steve McClure schrieb:
>On Fri, 2005-03-25 at 09:40 +0100, Marcus Habermehl wrote:
>> Steve McClure schrieb:
>>
>> >On Wed, 2005-03-23 at 15:27, Marcus Habermehl wrote:
>> >> Hi.
>> >>
>> >> I want to write the output of os.popen('command') to a gtk.TextView.
>> >>
>> >> But I don't know how. :(
>> >>
>> >> If I use
>> >>
>> >> for line in os.popen('command').readlines():
>> >> textview.insert_at_cursor(line)
>> >>
>> >> I must wait untils 'command' has finished.
>> >>
>> >> Is there a better way? Is it not possible to wrote the output directly
>> >> to a gtk.TextView?
>> >>
>> >> I have found some documentation about pipes or related things. But
>> >> because my english isn't very good I doesn't understand it realy.
>> >>
>> >> Have anyone a hint for me?
>> >
>> >Try looking at os.popen3
>> >
>> >You can do something like
>> >
>> [example]
>>
>> That isn't what I want. On your example I must wait until the command in
>> os.popen3 has finished.
>>
>> If the command need some minutes the user doesn't know what the script
>> doing. And I want that the user can see the output in "real-time".
>>
>> You know what I mean?
>
>Each time you read a line do:
> while gtk.events_pending():
> gtk.main_iteration()
>
>to make sure the text widget is updated. Is that what you mean?
>
[...]
How do you mean this?
Befor os.popen or after os.popen?
Normaly I use this:
while gtk.events_pending():
gtk.main_iteration()
for line in os.popen('do something').readlines():
tbuffer.insert_at_cursor(line)
Here I must wait until 'do something' has finished.
If I use the next example the command from os.popen will be executed two
times.
for line in os.popen('do something').readlines():
while gtk.events_pending():
gtk.main_iteration()
tbuffer.insert_at_cursor(line)
regards
Marcus
Try using readline() instead of readlines() on the pipe. I would create
the pipe in a separate line of code.
I have make some experiments. And I have found a answer to my problem. :)
child = pexpect.spawn('find /usr -type d')
while gtk.events_pending():
gtk.main_iteration()
line = child.readline()
while line:
while gtk.events_pending():
gtk.main_iteration()
tbuffer1.insert_at_cursor(line)
tview1.scroll_to_mark(tbmark1, 0.05, True, 0.0, 1.0)
line = child.readline()
regards
Marcus
_______________________________________________
pygtk mailing list pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/