Hi Bou, I created this PyGtk class a little while ago, to do exactly what you describe: Do advanced stuff in a thread, and report seamless back to gtk using signals. There "recipe" also contains an example, but please tell me if you need more info. http://code.activestate.com/recipes/521881/
Regards, Thomas On Sun, Aug 30, 2009 at 5:26 PM, Bou Baris<bouba...@gmail.com> wrote: > I'm a new user of PyGTK. > I'm writing with Python and PyGTK a little software for decoding MKV > video files using external tool MKV TOOL UNIX. It's a simple graphical > front-end to ffmpeg and MKVTOOLNIX. > I use Ubuntu 9.04 shipped with Python 2.6.2 and PyGTK 2.x > > I've a problem (obviously). > > I've made a non blocking function (using subprocess.Popen and select) > for calling the external program MKVEXTRACT. When works, 'mkvextract' > reports its progress state as a percentage: > Progress: 0% > Progress: 1% > Progress: 2% > .... > > I want read 'mkvextract' stdout in a real-time (non-blocking) fashion, > decode progress number from string 'Progress: xx%' and control a PyGTK > ProgressBar. > > > This is the code and non-blocking is working (printing the progress to > console it's ok). > The problem is that when code run, I see in terminal the percentage > number decoded correctly (printed from my code, not by 'mkvextract', > see code below) but progress bar isn't moving. > Really ALL GUI is blocked. > It's look that Popen block GUI job until 'mkvextraxt' end. > When Popen/mkvextract ends its job, GUI restart to normal behaviour > and I see the progress bar to 100% > > > def mkv_dts_extraction(self,dtstrack,pgbar=None): > > command=[ 'mkvextract', \ > 'tracks', \ > self.INPUTFILE, \ > dtstrack + ':' + self.DTSFILENAME ] > > # start subprocess > proc = subprocess.Popen(command,stdout=subprocess.PIPE) > > # set non-blocking mode > outfile = proc.stdout > outfd = outfile.fileno() > file_flags = fcntl.fcntl(outfd, fcntl.F_GETFL) > fcntl.fcntl(outfd, fcntl.F_SETFL, file_flags | os.O_NDELAY) > > # use 'select' for reading > while True: > ready = select.select([outfd],[],[]) # wait for input > if outfd in ready[0]: > outchunk = outfile.read() > if outchunk == '' : > break > select.select([],[],[],.1) # give a little time for buffers to > fill > > perc = > re.compile("Progress:\s+(\d+)",re.IGNORECASE).findall(outchunk) > if len(perc) > 0: > completed = int(perc[len(perc)-1]) / 100.00 # take > last 'Progress' number > > print completed # this print WORKS: in terminal I can > see the percentage growing > > # progress bar DON'T WORK : GUI is blocked > pgbar.set_fraction(completed) > pgbar.show() > > err = proc.wait() > > return True > _______________________________________________ > pygtk mailing list pygtk@daa.com.au > http://www.daa.com.au/mailman/listinfo/pygtk > Read the PyGTK FAQ: http://faq.pygtk.org/ > -- Mvh. Thomas _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/