BreakBad
29th January 2013, 18:12
(PyQt 4.8, Python 2.7)
After reading through the following I'm still left a bit puzzled as to which approach to attempt to utilize for my situation. Any advice would be appreciated.
Keeping_the_GUI_Responsive (http://www.qtcentre.org/wiki/index.php?title=Keeping_the_GUI_Responsive)
I have a module, flp.so library to which I have no control over. It takes a function as a constructor argument, and performs a complex/long calculation when invoking the run() method. Here I subclassed QThread, and invoke flp.run inside the thread's run method. In turn the flp module will invoke the callback method, which emits a signal. I catch the signal back in my main thread, and update a model for a QTreeView and update a QProgressBar.
def my_runner(QThread):
def __init__(self,callback=None):
self.callback = callback
def callback(self):
# f_runner.f_output is array that is appended every iteration of f_runner.run()
emit(SIGNAL('update_main'),self.f_runner.f_output. pop())
def run(self):
import flp
self.f_runner = flp.f_runner(callback=self.callback)
self.f_runner.run()
However, the GUI is not very responsive, as the signals are probably stacking up and the events can't be processed fast enough. I try to avoid invoking QApplication.processEvents(), but tried it here and very bad things happen.
I have been rethinking this design but have gotten stuck. Eventually I would like the main thread GUI to be responsive while this thread is working and updating the progress bar and table view in the main.
TYVM for reading.
After reading through the following I'm still left a bit puzzled as to which approach to attempt to utilize for my situation. Any advice would be appreciated.
Keeping_the_GUI_Responsive (http://www.qtcentre.org/wiki/index.php?title=Keeping_the_GUI_Responsive)
I have a module, flp.so library to which I have no control over. It takes a function as a constructor argument, and performs a complex/long calculation when invoking the run() method. Here I subclassed QThread, and invoke flp.run inside the thread's run method. In turn the flp module will invoke the callback method, which emits a signal. I catch the signal back in my main thread, and update a model for a QTreeView and update a QProgressBar.
def my_runner(QThread):
def __init__(self,callback=None):
self.callback = callback
def callback(self):
# f_runner.f_output is array that is appended every iteration of f_runner.run()
emit(SIGNAL('update_main'),self.f_runner.f_output. pop())
def run(self):
import flp
self.f_runner = flp.f_runner(callback=self.callback)
self.f_runner.run()
However, the GUI is not very responsive, as the signals are probably stacking up and the events can't be processed fast enough. I try to avoid invoking QApplication.processEvents(), but tried it here and very bad things happen.
I have been rethinking this design but have gotten stuck. Eventually I would like the main thread GUI to be responsive while this thread is working and updating the progress bar and table view in the main.
TYVM for reading.