title: Live Plotting with PyQtGraph in PyQt4 #2
body: <p>First of all sorry for the lenght. I want to explain my problem as good as possible. I am quite new to Python and trying to make a plotting app using PyQtGraph embedded in PyQt4. Some days ago I got a really nice answer to my  <a href="https://stackoverflow.com/questions/41679063/live-plotting-with-pyqtgraph-in-pyqt4">plotting problem</a>, and my next step is to have two PyQtGraphs plot Widgets simoultaneously plotting in the same PyQt4's CentralWidget. By the same approach as in the link described, both plots work fine, but the GUI gets unresponsive. For overcoming this, I am aiming to use <a href="https://wiki.python.org/moin/PyQt/Threading,_Signals_and_Slots" rel="nofollow noreferrer">QThread</a>, and for that, I need to have my plotting functions in different classes. But I am messing with my variables, and can't see how: </p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  import pyqtgraph as pg
  import random
  
  
  class MainWindow(QtGui.QMainWindow):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.central_widget = QtGui.QStackedWidget()
          self.setCentralWidget(self.central_widget)
          self.login_widget = LoginWidget(self)
          self.login_widget.button.clicked.connect(Plots.plotter)
          self.central_widget.addWidget(self.login_widget)
  
  
  class LoginWidget(QtGui.QWidget):
      def __init__(self, parent=None):
          super(LoginWidget, self).__init__(parent)
          layout = QtGui.QHBoxLayout()
          self.button = QtGui.QPushButton('Start Plotting')
          layout.addWidget(self.button)
          self.plot = pg.PlotWidget()
          layout.addWidget(self.plot)
          self.setLayout(layout)
  
  
  class Plots(MainWindow):
  
      def print(self):
          print('hello World')
  
      def plotter(self):
          self.data = [0]
          self.curve = self.login_widget.plot.getPlotItem().plot()
          self.timer = QtCore.QTimer()
          self.timer.timeout.connect(self.updater)
          self.timer.start(0)
  
      def updater(self):
          self.data.append(self.data[-1]+0.2*(0.5-random.random()))
          self.curve.setData(self.data)
  
  if __name__ == '__main__':
      app = QtGui.QApplication([])
      window = MainWindow()
      window.show()
      app.exec_()
  </code></pre>
  
  <p>That gives me an error at Plots.plotter:</p>
  
  <pre><code>self.data = [0]
  AttributeError: 'bool' object has no attribute 'data'
  </code></pre>
  
  <p>If in the MainWindow class I substitute the 'button.connect' argument with Plots.print, it works fine. So I can see there is something wrong with the fact that I make an LoginWidget object in MainWindow, and then Plots inherits from MainWindow, calling that same LoginWidget object again. </p>
  
  <p>I have tried a proposed solution where the father (MainWindow) does not access the methods of the children (Plots). But if, from Plots, I want to call the class where I aim placing my thread in, I get the same error again....</p>
  
  <pre><code>import sys
  from PyQt4 import QtCore, QtGui
  import pyqtgraph as pg
  import random
  
  
  class LoginWidget(QtGui.QWidget):
      def __init__(self, parent=None):
          super(LoginWidget, self).__init__(parent)
  
          layout = QtGui.QHBoxLayout()
          self.button = QtGui.QPushButton('Start Plotting')
          layout.addWidget(self.button)
          self.plot = pg.PlotWidget()
          layout.addWidget(self.plot)
          self.setLayout(layout)
  
  
  class MainWindow(QtGui.QMainWindow):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.central_widget = QtGui.QStackedWidget()
          self.setCentralWidget(self.central_widget)
          self.login_widget = LoginWidget(self)
          self.central_widget.addWidget(self.login_widget)
  
  
  class Plots(MainWindow):
      def __init__(self, parent=None):
          super(Plots, self).__init__(parent=parent)
          self.login_widget.button.clicked.connect(MyThread.plotter)
  
  
  
  class MyThread(MainWindow):
      def __init__(self, parent=None):
          super(Aname, self).__init__(parent=parent)
  
      def print(self):
          print('hello World')
  
      def plotter(self):
          self.data = [0]
          self.curve = self.login_widget.plot.getPlotItem().plot()
          self.timer = QtCore.QTimer()
          self.timer.timeout.connect(self.updater)
          self.timer.start(0)
  
      def updater(self):
          self.data.append(self.data[-1]+0.2*(0.5-random.random()))
          self.curve.setData(self.data)
  
  
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      w = Plots()
      w.show()
      sys.exit(app.exec_())
  </code></pre>