[pygtk] Asynchronous access at output of os.popen() call

togix togix at libero.it
Thu Aug 21 17:09:00 WST 2008


Hi everyone,
at the end I'm close to the solution, thanks to both Albert and Pádraig for the suggestions.

Here is my PyGTK interface, modified importing the “subProcess.py” by Pádraig and workinf on process.outdata for displaying the output:
[code]
      ...
      process = subProcess.subProcess(cmd)
      while process.read(3) == 1:
            # process the output of called program
            textbuffer.insert_at_cursor("\n*" + process.outdata + "* [" + time.asctime() + "]")		
            while gtk.events_pending():
                  gtk.main_iteration(False)
            process.outdata = ""
      ...
[/code]

And with this part of code will keep the scroll at the bottom of the box (useful to always see the new lines):
[code]
      ...
      sw = gtk.ScrolledWindow()
      textview = gtk.TextView()
      vadj = sw.get_vadjustment()
      vadj.connect('changed', lambda a, s=sw: rescroll(a,s))
      def rescroll(adj, scroll):
            adj.set_value(adj.upper-adj.page_size)
            scroll.set_vadjustment(adj)
      ...
[/code]

Cheers,
Claudio




More information about the pygtk mailing list