Graph.py 813 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
from time import sleep
from PyQt5.QtCore import QThread
from interfaces.Mock import Interface

class Graph(QThread):
    def __init__(self, graph, interval, parent=None):
        super(Graph, self).__init__(parent)
        self.running = True
        self.interval = interval/1000.0
        self.interface = Interface()
        self.dataX = [0]
        self.dataY = [0]
        self.plot = graph.plot()

    def run(self):
        print("RUNNING")
        while self.running:
            self.dataX.append(self.dataX[-1] + self.interval)
            self.dataY.append(self.interface.read())
            self.plot.setData(self.dataX, self.dataY)
            sleep(self.interval)

    def setInterval(self, interval):
        self.interval = interval/1000.0

    def stop(self):
        self.running = False