title: Method is still running after closing window
body: <p>I'm having trouble trying to undersand how the window objects work. I have a real time plot on a secundary window via matplotlib. This plot updates every second with the new calculated values.
  What I expect is the method to stop running whenever I close this 2nd window and restarts when I reopen it. I'm able to reset the array values when I'm closing the 2nd window but as indicated, this method calculating the values is still running.</p>
  <p>This is my code (originally using a sensor, I modified this to generate random numbers instead):</p>
  <pre><code>from PyQt5 import QtCore
  from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
  import sys
  import random
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  from matplotlib.figure import Figure
  
  
  # The main window 
  class Window(QWidget):
      def __init__(self):
          super().__init__()
   
          self.setGeometry(200,200, 400,300)
          self.setWindowTitle('Test')
          self.demo = None
          
          self.create_buttons()
          
      def create_buttons(self):
          btn1 = QPushButton('Open window', self)
          btn1.setGeometry(100,100, 100,100)
          btn1.clicked.connect(self.open_w)
          
      def open_w(self):
          if self.demo is None:
              self.demo = AppDemo()
          self.demo.show()
          
  # Second window, where I plot the data
  class AppDemo(QWidget):
      def __init__(self):
          super().__init__()
          self.resize(650, 500)
          self.plotwidget = QWidget(self)
          self.chart = Matplotlibwidget()
          self.chart.plot_widget(self.plotwidget, self.chart)
          
      def closeEvent(self, event):
          event.accept()
          func.start_lists()
          print('Window closed')
          
  # My widget for my graph        
  class Matplotlibwidget(FigureCanvas):
      def __init__(self, parent=None):
          fig = Figure()
          self.axes = fig.add_subplot(111)
          
          FigureCanvas.__init__(self, fig)
          self.setParent(parent)
          FigureCanvas.updateGeometry(self)      
      
      def plot_widget(self, canvasWidget, graph):
          self.layoutvertical = QVBoxLayout(canvasWidget)
          self.layoutvertical.addWidget(graph)        
          timer = QtCore.QTimer(self)
          timer.timeout.connect(self.plotting)
          timer.start(1000)
                
      def plotting(self):
          self.y = func.calculate()
          func.appends(self.y)
          self.axes.cla()
          self.axes.plot(func.x, func.y)
          self.draw()
  
  # This is a generic class I use to calculate the data, originally this is a class for my sensor
  class FuncTime ():
      def __init__(self):
          self.start_lists()
           
      def start_lists(self):
          self.x, self.y = [0], [1]
          
      def calculate(self):
          return self.y[-1] + self.y[-1] * random.uniform(-0.1, 0.1)
          
      def appends(self, y):
          print(self.x[-1], ', ', self.y[-1])
          self.x.append(self.x[-1] + 1)
          self.y.append(y)
  
    
  app = QApplication(sys.argv)
  func = FuncTime()
  window = Window()
  window.show()
  sys.exit(app.exec_())
  </code></pre>