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):
while self.running:
self.dataX.append(self.dataX[-1] + self.interval)
self.plot.setData(self.dataX, self.dataY)
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 PyQt5.QtCore import QThread, QTimer
from threads.Graph import Graph
from interfaces.Mock import Interface
class MainThread(QThread): class MainThread(QThread):
def __init__(self, ui, parent=None): def __init__(self, ui, parent=None):
super(MainThread, self).__init__(parent) super(MainThread, self).__init__(parent)
self.ui = ui self.ui = ui
self.interface = Interface() = [] = []
self.graph = Graph(self.ui.mainGraph, 100)
def run(self): def run(self):
self.timer = QTimer() self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate)
self.timer.timeout.connect(self._updateGraph) self.graph.start()
thread_instance = QThread() thread_instance = QThread()
thread_instance.start() thread_instance.start()
thread_instance.exec_() thread_instance.exec_()
def _updateSamplingRate(self):
MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000]
self._log("[DEBUG]", self.ui.samplingCBox.currentText())
def _updateGraph(self): def _log(self, tag, msg):
self._log("DEBUG", "Loop") self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text()))
self.ui.mainGraph.clear() \ No newline at end of file
def _log(self, level, msg):
self.ui.consoleView.setText("{} {}\n{}".format(level, 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