I have written a small GUI with qtdesigner and python which should display in real-time the trajectory of one particle in a matplotlib figure. So I have something like:
class DesignerMainWindow(QtGui.QMainWindow, Ui_MplMainWindow):
"""Customization for Qt Designer created window"""
def __init__(self, parent = None):
# initialization of the superclass
super(DesignerMainWindow, self).__init__(parent)
# setup the GUI --> function generated by pyuic4
self.setupUi(self)
self.niter = 30
#... other initializations
def run(self):
# set xo, yo with initial particle position
for t in range(self.niter):
# set new particle position in x, y
self.mpl.canvas.ax.plot([xo, x], [yo, y], '-b')
self.mpl.canvas.draw()
print x, y, t, self.niter
xo = x
yo = y
My problem is that the figure is updated only when the function "run()" is finished, despite the call to "draw()" inside the loop. Thus I have only the final trajectory and not the full movie...
Does anyone has an idea on how to force the graph update from within this function/loop ?
Thanks.
Try to call QCoreApplication.processEvents()
at the end of for
loop.