Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread Finished Event in Python

I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form.

The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GUI thread to do something from inside the drawing thread.

I could do it using one thread but the program halts.

I used to do it in C# using a BackgroundWorker which had an event for finishing.

Is there a way to do such thing in Python? or should I hack into the main loop of PyQt application and change it a bit?

like image 444
mpcabd Avatar asked Apr 11 '26 14:04

mpcabd


1 Answers

In the samples with PyQt-Py2.6-gpl-4.4.4-2.exe, there's the Mandelbrot app. In my install, the source is in C:\Python26\Lib\site-packages\PyQt4\examples\threads\mandelbrot.pyw. It uses a thread to render the pixmap and a signal (search the code for QtCore.SIGNAL) to tell the GUI thread its time to draw. Looks like what you want.

like image 159
Jeff Youel Avatar answered Apr 13 '26 05:04

Jeff Youel