I am building a GUI with PyQt4. At the moment I have a OpenGLWidget()
that displays geometry at every N-th time step from Solver()
that is in a different thread. I added new graph window - GraphWidget()
to plot "some interesting" data. In Solver()
I use a signal to refresh Open GL widget - self.updateGL()
. I have connected the existing signal to also redraw FigureCanvasQTAgg
but nothing is drawn.
Here is the class SimulationControlWidget:
class SimulationControlWidget(self):
self.OpenGLWidget = OpenGLWidget() #opengl widget
self.GraphWidget = GraphWidget() #plot widget with matplotib
# solver in new thread
self.solver = Solver()
self._solver_thread = QThread()
self._solver_thread.start()
self.solver.moveToThread(self._solver_thread)
# signals
#this signal is OK
OKself.solver.solveODE.repaintGL_signal.signal_repaintGL.connect(self.OpenGLWidget.updateGL)
#this signal is not OK
self.solver.solveODE.repaintGL_signal.signal_repaintGL.connect(self.GraphWidget.plot_graph)
Here is the class GraphWidget:
class GraphWidget(QtGui.QWidget):
def __init__(self, MBD_system=[], parent=None, flags=0):
super(GraphWidget, self).__init__(parent)
self.fig = Figure((8.0, 4.0), dpi=100)
self.canvas = FigureCanvas(self.fig)
self.axes = self.fig.add_subplot(111)
# added button to manually execute function plot_graph()
self.plot_button = QtGui.QPushButton("&Show")
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.canvas)
self.layout.addWidget(self.plot_button)
self.canvas.draw()
# signal to plot data with button self.plot_button
self.plot_button.clicked.connect(self.plot_graph)
def plot_graph(self):
print 'plotting graph!'
self.axes.cla()
self.axes.plot(np.random.rand(10, 2))
self.canvas.draw()
The problem I have is: if I manually click on the button self.plot_button
the function plot_graph()
is executed (random data is plotted correctly and text plotting_graph!
is printed in eclipse pydev console). But if I try to execute function plot_graph()
with signal only text plotting_graph!
is printed in console and no data is plotted. I have also noticed if I use signal, the function plot_graph()
is executing (due to signal) after the simulation has stopped. What should be the solution? I can also put the link to the entire code if it will be more useful. I think I will have to synchronize this...but how?