tags:

views:

81

answers:

2

I have a couple of questions.

I have an algorithm that will generate a couple of pictures in python that must be displayed on a form. I am using PyGt for this. My question is: where should I run my code? Right from the initializer? In that case from what I tested, the form won't show up.

  • Should I set up a timer in the constructor that starts my algorithm half a second later?
  • Will running the algorithm freeze my form making it impossible to see the picture itself? I don't mind that the buttons, checkboxes, etc freeze while it is computing, as long as the current picture is still visible.
  • Should I use something like c#'s OnFormLoad()? If yes, how can I set it? Through connect()?
  • How does threading work on python? I've heard, but I'm not too sure about it, that it was a pain to deal with. Is it? In c# it is as easy as writing 4 lines. I'd like to use it if possible, but if it is going to be hard to implement it I can live without it.

Thanks

+1  A: 

You can run the algorithm in a separate thread, placing the data into a Queue when finished. The main thread (GUI) will periodically sample the queue and display the data when it arrives.

Eli Bendersky
+4  A: 

You might want to check the Mandelbrot example.

Basically the idea is to use a worker thread to do the heavy computations (I'd suggest a QThread to ease the communication to the main thread by using signals/slots), then once the work is done emit a signal with the computed data and have the main thread paint it. You can also render the image in the worker thread if you like.

Idan K