[PyQt] Working with os.popen and qprogressdialog
Andreas Pakulat
apaku at gmx.de
Mon Mar 10 08:26:21 GMT 2008
On 09.03.08 16:21:05, JMiahMan wrote:
>
>
> Andreas Pakulat-2 wrote:
> >
> > Thats because while you run your process the event loop is not run and
> > thus no painting updates are being done. I suggest to take a look at
> > QProcess as that one sends the output in an asynchronous way and thus
> > allows the event loop to update the paintings.
>
> I apologize I have no clue what you're saying It sounds kinda like a RTFM
> response. I've taken a look at the Qprocess class (and the QT Class page in
> general) but being very new at this and programming in general I understand
> just about as much as what you said above.
And in fact I was partly wrong :) os.popen doesn't actually block until
the command is finished, but also returns immediately. And thats exactly
your problem, the code flow you have is:
show dialog
start a child process (only starts, doesn't wait for it to finish)
hide dialog
As you can see in fact this is almost the same as doing just
show dialog
hide dialog
because forking a child process is normally really fast.
So what you probably really want is to find out when your child process
is done doing what it wants to do. I'm not sure how to do that with
standard python process management.
However you can do this easily with QProcess. Check the api docs there
are samples how to run any command you want via QProcess. Looking at
your command string you probably need to prepends a /usr/bin/sh -c "..."
as you're executing shell functions (such as sleep) and QProcess doesn't
use a shell when executing the commands.
QProcess then has signals which you can connect to your own slots which
notify you when the process you started has exited. So the flow would
then become
show dialog
start process via qprocess
<process runs and also the Qt event loop, which draws the dialog>
QProcess signals that the process exited
hide dialog (in the slot connected to the signal)
Andreas
--
You will overcome the attacks of jealous associates.
More information about the PyQt
mailing list