[pygtk] Updating a TextBuffer line by line

Laszlo Pandy laszlok2 at gmail.com
Fri Jan 23 03:57:30 WST 2009


Try calling the main loop. Since you are always waiting for the
process to send you more data, the GUI does not get a chance to update
itself. The insert_at_cursor will insert the text, and cause a redraw
event will be send. You can use gtk.main_iteration() to force the
event to be processed immediately.

Here is what your loop should look like:

while command.poll() is None:
     line = command.stdout.readline()
     self.txtbuffer.insert_at_cursor(line)
     while gtk.events_pending():
          gtk.main_iteration()


Hope it helps,
Laszlo

2009/1/22 Daniel Roesler <diafygi at gmail.com>:
> Howdy again,
>
> I am running into a problem displaying stdout from a subprocess
> command. I have a loop that checks to see if the subprocess is still
> active, then reads a line in from stdout and sends it to the text
> buffer. However, I can't seem to get my text buffer to print except
> when the command ends. Obviously, I'm missing some logic behind how
> loops work with pygtk.
>
> Here's my code:
> ---------------------------
> command = subprocess.Popen(cmd, stdout=subprocess.PIPE)
>
> while command.poll() is None:
>      line = command.stdout.readline()
>      self.txtbuffer.insert_at_cursor(line)
> ---------------------------
>
> Any ideas on how to read stdout line by line with subprocesses?
>
> Avast!
> Daniel Roesler
> diafygi at gmail.com
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>


More information about the pygtk mailing list