There are three general approaches to keeping your GUI responsive while doing work in the background:
- Timers -- Everything operates within the GUI thread and your work is done by having a timer
call some function in between GUI updates. This is the simplest and most common approach and is
very likely to be adequate (if written correctly) using either pyqtgraph or matplotlib. The drawback
of this approach is that if the work function takes a long time, the GUI will become unresponsive.
Pulling data from a camera and displaying it should not cause you problems, though.
- Threads -- In the case that your work function becomes too long, you can move some of the work
out to a separate thread. Importantly, you can NOT make changes to the GUI from a different thread.
Do as much work as possible, then send the results to the GUI thread to be displayed.
- Processes -- This is more or less the same approach as using threads, but has the advantage
that you may get better CPU utilization (read about the global interpreter lock in python), and
the disadvantage that communication between processes can be more cumbersome than between threads.
Pyqtgraph has built-in multiprocessing features to make this easier
(see pyqtgraph/examples/RemoteSpeedTest.py)
This topic is discussed extensively elsewhere, so I'll leave it at that.
With that in mind, there are a few problems with the code you have posted:
- You are generating and displaying a 3D data set (100-frame video) with every frame update.
This is the reason it appears to update so slowly. See pyqtgraph/examples/ImageItem.py and
VideoSpeedTest.py for examples of video done correctly.
- You are calling setImage from the worker thread; this may work sometimes, but expect it to crash.
A better approach is to generate the data in the worker, then send the data to the main GUI
thread to be displayed. The Qt documentation discusses threading in depth. (but as I mentioned
before, avoiding threads altogether would be even better)
Finally, one important rule to follow: If you are having performance issues, profile your code. You cannot fix the problem until you know what is causing it.