Commit 2133ac4b authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Separated Graph and MainThread

parent b4447145
This diff is collapsed.
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
\ No newline at end of file
from time import sleep
from PyQt5.QtCore import QThread, QTimer
from interfaces.Mock import Interface
from threads.Graph import Graph
class MainThread(QThread):
def __init__(self, ui, parent=None):
super(MainThread, self).__init__(parent)
self.ui = ui
self.interface = Interface()
self.data = []
self.graph = Graph(self.ui.mainGraph, 100)
def run(self):
self.timer = QTimer()
self.timer.timeout.connect(self._updateGraph)
self.timer.start(100)
self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
self.graph.start()
thread_instance = QThread()
thread_instance.start()
thread_instance.exec_()
def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
self._log("[DEBUG]", self.ui.samplingCBox.currentText())
self.graph.setInterval(MAP[self.ui.samplingCBox.currentIndex()])
def _updateGraph(self):
self._log("DEBUG", "Loop")
self.ui.mainGraph.clear()
self.data.append(self.interface.read())
self.ui.mainGraph.plot(self.data)
def _log(self, level, msg):
self.ui.consoleView.setText("{} {}\n{}".format(level, msg, self.ui.consoleView.text()))
print(self.ui.consoleView.size())
\ No newline at end of file
def _log(self, tag, msg):
self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text()))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment