from datetime import datetime from time import sleep, time from sys import exit from PyQt5.QtCore import QThread, QTimer from PyQt5.QtWidgets import QMessageBox, QApplication from threads.Graph import Graph from config import Config from util.Timer import Timer class MainThread(): def __init__(self, ui, timer): #super(MainThread, self).__init__(parent) self.ui = ui self.data = [] self.graph = Graph(self.ui, 500, self._log) #self.upTimer = Timer() #self.downTimer = Timer(delay=10) try: self.config = Config() except FileNotFoundError: self._fatal("Arquivo de configuração não encontrado!") self.graphTimer = timer self.graphTimer.timeout.connect(self.graph.updateGraphs) self.graphTimer.start(self.graph.interval) self.ui.samplingCBox.currentIndexChanged.connect(self._updateSamplingRate) self.ui.playPause.clicked.connect(self._playPause) def _updateSamplingRate(self): MAP = [100, 200, 500, 1000, 1500, 2000, 2500, 5000, 10000] self._log("[DEBUG]", self.ui.samplingCBox.currentText()) self.graphTimer.stop() self.graphTimer.start(MAP[self.ui.samplingCBox.currentIndex()]) self.graph.interval = MAP[self.ui.samplingCBox.currentIndex()] def _fatal(self, msg): error = QMessageBox() error.setText(msg) error.setWindowTitle("Erro") error.exec() exit(-1) def _log(self, tag, msg): self.ui.consoleView.setText("{} {}\n{}".format(tag, msg, self.ui.consoleView.text())) if "FATAL" in tag: self._fatal(msg) def _playPause(self): if self.graph.running: self.graphTimer.stop() self.graph.running = False self.ui.playPause.setText("REINICIAR") else: self.graph.running = True self.graphTimer.start(self.graph.interval) self.ui.playPause.setText("PAUSA") def _finalize(self): pass def _updateTimers(self): if self.upTimer.active: self.upTimer.update() if self.downTimer.active: self.downTimer.update() #self.ui.currentTimeLabel.setText(datetime.now().strftime("%H:%M:%S")) #self.ui.timerLabel.setText(self.upTimer.getTimeString()) #self.ui.regTimerLabel.setText(self.downTimer.getTimeString()) def _startTimer(self): btn = self.sender() timer = self.upTimer if btn == self.ui.startTimerButton else self.downTimer if btn.text() == "Iniciar": self.ui.startTimeLabel.setText(datetime.now().strftime("%H:%M:%S")) btn.setText("Parar") timer.start() else: btn.setText("Iniciar") timer.stop() self.graph.addMarker(datetime.now().strftime("%H:%M:%S")) def _stopTimer(self): if self.sender == self.ui.stopTimerButton: self.upTimer.stop() self.upTimer.clear() else: self.downTimer.stop() self.downTimer.clear()