I hope someone can help me with this.

Problem: I have a window widget (window2) that has a progress bar and a
textview.  I want to show the output of the child process that I launch
inside the textview.  Right now when I run the program, window2 pops up
totally blank (no widgets displayed at all) but does indeed hide when the
child process finishes.  If I should comment out the io_watch_add line for
gobject.IO_IN then window2 pops up nicely with a running progress bar and
closes when the child process is finished.

In short: What do I need to do in order to get the text being generated by
my child process to show up in the textview?

Here are the relevant parts of the script  (let me know if I should post the
entire script ... it's only 161 lines):


import pygtk
import gtk
import gtk.glade
import gobject
import os
import sys

textview = wTree.get_widget('textview1')
textbuffer=textview.get_buffer()

keep_pulsing = True

def cstdout_hup_callback(fd, condition):
    global keep_pulsing, textbuffer
    if condition == gobject.IO_HUP:
        keep_pulsing=False
    return keep_pulsing

def cstdout_in_callback(fd, condition):
    global keep_pulsing, textbuffer
    if condition == gobject.IO_IN:
        #text = fd.read(1024)  <-- this is not reading text from the fd.  My
workaround for now is below.
        text = "blah ... \n"
        iter = textbuffer.get_end_iter()
        textbuffer.insert(iter, text)
    return keep_pulsing

def update_progress_callback():
    global keep_pulsing
    if keep_pulsing:
        progressbar.pulse()
    else:
        write_status("Done")
        window2.hide()
    return keep_pulsing

def run_command(command):
    global keep_pulsing
    keep_pulsing=True
    (cpid, cstdin, cstdout, cstderr) =
gobject.spawn_async(command,flags=gobject.SPAWN_DO_NOT_REAP_CHILD,standard_output=True)
    gobject.timeout_add(150, update_progress_callback)
    gobject.io_add_watch(cstdout, gobject.IO_HUP, cstdout_hup_callback)
    gobject.io_add_watch(cstdout, gobject.IO_IN, cstdout_in_callback)
    window2.show()
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to