[PyQt] Working with os.popen and qprogressdialog

Andreas Pakulat apaku at gmx.de
Wed Mar 12 19:23:10 GMT 2008


On 12.03.08 20:11:20, Ulf Röttger wrote:
> Am Montag 10 März 2008 20:09:27 schrieb Andreas Pakulat:
> > This should execute an ls -l /usr/share/home and show a progressbar
> > while that is done.  However you'll probably need to play around a bit
> > with escaping rules when you want to use pipes in the command.
> 
> Hello, I recently had to work around a similar problem, I use a not very 
> elegant trick, but so far it works, maybe it helps a bit, though it is not 
> what you want finally with QProcess.
> 
> stdin, stdout = os.popen2('command') 
> # or use stdout = os.popen('command', 'r')
> #  stdout = output of process called with 'command' - it's as if piped to the 
> standard output.
> for line in stdout: # for stdout is a filelike object
> 	print line  # at least do something with / for each line, 
> 
> this prevents following code to be processed before the command above has 
> finished ;)

Right and it also prevents the event loop from being processed, so you
get the same result as with

dialog.show()
dialog.hide()

If you want to have a progress bar shown while your process is executed,
there's only one correct way:

dialog.show()
<return to the event loop>....

And at some point your process has to notify you that its finished, then
you can call dialog.hide()

Andreas

-- 
Expect the worst, it's the least you can do.


More information about the PyQt mailing list