[pygtk] Hi, all! I'm new to the list. How can I create please a frontend for a TUI command?

Roberto Cavada cavada at fbk.eu
Tue Oct 28 19:43:13 WST 2008


Néstor Amigo Cairo wrote:

> Ok! I have tested this, and it only works at the end of the execution
> of the command, 

There is a problem in the way you create your watcher's callback. 
You have to use a function, a method or a lambda. Try with this 
version of 'do_format'. It will also handle pipe error conditions.
#-------------------------------------------
   def do_format(self, widget, textbuffer):

     def watcher(source, condition, buf):
       if condition == gobject.IO_IN:
         buf.insert(buf.get_end_iter(), source.readline())
         return True # keep it watching
       # error condition
       buf.insert(buf.get_end_iter(), "<process died>\n")
       return False # stop watching

     proc = subprocess.Popen(("./prueba.sh"),
                             shell=False,
                             stdout=subprocess.PIPE,
                            )
     gobject.io_add_watch(proc.stdout,
                          gobject.IO_IN | gobject.IO_ERR | 
gobject.IO_HUP,
                          watcher, textbuffer)
     return
#-------------------------------------------

Hope that helps.
r.




More information about the pygtk mailing list