kosta5
kosta5

Reputation: 1138

python threads gui

I have a small issue when working with PyQt4 and threading package:

My code looks like this:

def goForwardToSamples(self):
    self.main.dataSet = DataSetProvider(self.main.sourceFile)
    self.ui = Ui_NeuralPredictor2()
    self.ui.setupUi(self)
    ParalelGui(self.ui).start()
    self.connectSignalsWindow2()
def connectSignalsWindw2(self):
   # DOING SOME REAL SERIOUS COMPUTATION ...

=> now def run(self): in ParalelGui class looks like this:

def run(self):
    self.gui.show()

=> I just want to test if my GUI will run paralel with the computation.

I feel I know what the problem is. I have a QtableView that is being filled with data where I wrote (DOING SOME REAL SERIOUS COMPUTATION..). That QtableView is of course part of ui that I am sending to ParalelGui thread to be shown. I am not really sure how to make it work... Basically I would like to have a part of GUI threaded and already shown while the other part is being filled up dynamically in different thread.

What happens now is the typical 'you didnt thread your gui freeze' ... help much appreciated

Upvotes: 1

Views: 649

Answers (1)

jdi
jdi

Reputation: 92637

Even though your example is highly limited, I am going to take a stab at what I think you are doing here...

To me, it seems like you are doing things backwards and trying to show your gui in a thread while doing heavy computation in your main thread?

What you really should be doing is creating and showing your gui in the main thread, and running heavy computation in a separate worker thread. This worker thread can then emit a signal when data is ready, which your main thread can connect to and quickly update your table. This way you don't block your main thread. The rule of thumb is never do anything heavy in the main thread. Its meant for the GUI and its events.

Also, make sure you are using the QThread class and not the python threading module.

Upvotes: 3

Related Questions