Commit 28d55da4 authored by Alisson Claudino's avatar Alisson Claudino

Padronização das interfaces e gráficos genéricos com n eixos

parent b4282bcb
This diff is collapsed.
This diff is collapsed.
......@@ -5,60 +5,72 @@ import time
class Graph(PlotItem):
index = 0
def __init__(self,x_sampling, x_range, y1_min, y1_max, y2_min, y2_max, x_size, y_size, color1, color2, name1, name2):
def __init__(self,x_sampling, x_range, n_axis, y_min, y_max, x_size, y_size, color, name,unit):
super(Graph, self).__init__()
self.x_sampling=1
self.x_range = x_range/x_sampling
self.y1_min = y1_min
self.y1_max = y1_max
self.y2_min = y2_min
self.y2_max = y2_max
self.x_size = x_size
self.y_size = y_size
self.color1 = color1
self.color2 = color2
self.name1 = name1
self.name2 = name2
self.curve1 = self.plot(pen=color1, name=self.name1)
self.curve2 = self.plot(pen=color2, name=self.name2)
self.curve = []
self.axis = []
self.y=[]
self.curve.append(self.plot(pen=color[0], name=name[0]))
self.axis.append(AxisItem("left",color[0]))
self.axis[0].setLabel(name[0], unit[0])
self.axis[0].setRange(y_min[0], y_max[0])
y_axis = [0]
self.y.append(y_axis)
try:
for n in range(1,n_axis):
self.curve.append(self.plot(pen=color[n], name=name[n]))
self.axis.append(AxisItem("right",color[n]))
self.axis[n].setLabel(name[n],unit[n])
self.axis[n].setRange(y_min[n],y_max[n])
self.y.append(y_axis)
print(y_axis)
except Exception as e:
print(e)
self.axisTime = AxisItem("bottom", 'w')
self.axis2 = AxisItem("right", color2)
self.axis1 = AxisItem("left", color1)
self.axis1.setLabel(self.name1,'Tonf')
self.axis2.setLabel(self.name2,'mV')
self.axisTime.setLabel("Tempo", 's')
self.axisTime.setRange(0, x_range)
self.x=[]
self.x.append(0)
self.showAxis("left", False)
self.showAxis("bottom", False)
self.axisTime.setRange(0,x_range)
self.axis1.setRange(y1_min,y1_max)
self.axis2.setRange(y2_min,y2_max)
self.showAxis("left",False)
self.showAxis("bottom",False)
self.setMinimumSize(x_size,y_size)
self.setMinimumSize(x_size, y_size)
self.setXRange(0, self.x_range, padding=0)
self.setYRange(min(self.y1_min,self.y2_min), max(self.y1_max,self.y2_max), padding=0)
self.x1 = []
self.y1 = []
self.y2 = []
self.timeant = time.time()
self.setYRange(min(y_min), max(y_max), padding=0)
self.timeant = time.time()
def updateGraph(self, y1, y2):
def updateGraph(self, y):
# print(time.time()-self.timeant)
self.y1.append(y1)
self.y2.append(y2)
if len(self.y1) > self.x_range + 1:
self.y1.pop(0)
self.y2.pop(0)
for n in range(0,len(y)):
print(y[n])
print(self.y[n])
self.y[n].append(y[n])
if len(self.y[0]) > self.x_range+1 :
for n in range(0,len(y)):
self.y[n].pop(0)
self.index = self.x_range
else:
self.x1.append(self.index)
self.x.append(self.index)
self.index = self.index + 1
self.curve1.setData(self.x1, self.y1)
self.curve2.setData(self.x1, self.y2)
#self.timeant = time.time()
for n in range(0,len(y)):
self.curve[0].setData(self.x, self.y[0])
self.timeant = time.time()
from datetime import datetime
from PyQt5 import QtWidgets,QtCore
from PyQt5 import QtWidgets,QtCore,QtGui
class InterfaceTimer(object):
def __init__(self):
self.startTimerButton = QtWidgets.QPushButton()
self.pauseTimerButton = QtWidgets.QPushButton()
self.stopTimerButton = QtWidgets.QPushButton()
self.startRegTimerButton = QtWidgets.QPushButton()
self.stopRegTimerButton = QtWidgets.QPushButton()
self.regTimerLabel=QtWidgets.QLabel()
self.screenTimerLabel = QtWidgets.QLabel()
self.timerLabel = QtWidgets.QLabel()
self.currentTimeLabel = QtWidgets.QLabel()
self.currentTimer = QtCore.QTimer()
self.regTimer=QtCore.QTimer()
self.MainWindow=QtWidgets.QDialog()
self.regTimerLabel.setText("0 s")
self.regTimerLabel.setText("0.0 s")
self.timerLabel.setText("0.0 s")
self.timeValue=0
self.regTimerValue=0
self.regTimerValue=1000
def linkActions(self):
self.startTimerButton.pressed.connect(self.startScreenTimer)
self.pauseTimerButton.pressed.connect(self.playPauseScreenTimer)
self.stopTimerButton.pressed.connect(self.stopScreenTimer)
self.currentTimer.timeout.connect(self.updateCurrentTime)
self.startRegTimerButton.pressed.connect(self.startRegressiveTimer)
self.stopRegTimerButton.pressed.connect(self.startRegressiveTimer)
self.stopRegTimerButton.pressed.connect(self.stopRegressiveTimer)
self.currentTimer.start(500)
self.screenTimerFlag = False
def startRegressiveTimer(self):
try:
if(self.regTimerLabel.text().split(" ",3)[1]=="s"):
self.regTimerValue=self.regTimerLabel.text().split(" ",3)[0]
else:
self.regTimerValue=self.regTimerLabel.text()
print(self.regTimerValue)
self.regTimerValue=float(self.regTimerValue)
except(IndexError):
self.regTimerValue=self.regTimerLabel.text()
self.regTimerValue.split(" ", 3)
self.regTimerValue=float(self.regTimerValue[0])
except(ValueError):
print(self.regTimerLabel.text)
except(ValueError,TypeError):
error=QtWidgets.QMessageBox(self.MainWindow)
error.setText("Valor Inválido! Definindo valor padrão de 1000 segundos")
error.setWindowTitle("ERRO!")
error.exec()
self.regTimerValue = 1000
print(self.regTimerValue)
self.regTimerValue = float(self.regTimerValue)
self.regTimer=QtCore.QTimer()
self.regTimer.timeout.connect(self.updateRegTimer)
......@@ -55,53 +71,39 @@ class InterfaceTimer(object):
self.regTimer.stop()
self.startRegTimerButton.setText("Iniciar")
self.startRegTimerButton.pressed.disconnect()
self.startRegTimerButton.pressed.connect(startRegressiveTimer)
self.startRegTimerButton.pressed.connect(self.startRegressiveTimer)
self.regTimerLabel.setText("0.00 s")
def updateRegTimer(self):
while(self.regTimerValue!=0):
if(self.regTimerValue>=0.1):
self.regTimerValue -= 0.1
self.regTimerLabel.setText("%.1f seg"%self.regTimerValue)
self.regTimerLabel.setText("%.1f s"%self.regTimerValue)
def startScreenTimer(self):
self.timeValue = 0
self.screenTimer = QtCore.QTimer()
self.screenTimer.timeout.connect(self.updateScreenTimer)
self.screenTimer.start(100)
self.startTimerButton.setText("Reiniciar")
self.pauseTimerButton.setText("Pausar")
self.screenTimerFlag = True
def playPauseScreenTimer(self):
self.startTimerButton.setText("Reiniciar")
if (self.pauseTimerButton == "Iniciar"):
self.startScreenTimer()
if (self.screenTimerFlag == True):
self.screenTimer.stop()
self.screenTimerFlag = False
self.pauseTimerButton.setText("Continuar")
else:
try:
self.screenTimer.start(100)
self.screenTimerFlag = True
self.pauseTimerButton.setText("Pausar")
except:
self.startScreenTimer()
self.startTimerButton.pressed.disconnect()
self.startTimerButton.pressed.connect(self.pauseScreenTimer)
self.startTimerButton.setText("Pausar")
def pauseScreenTimer(self):
self.screenTimer.stop()
self.startTimerButton.setText("Continuar")
self.startTimerButton.pressed.disconnect()
self.startTimerButton.pressed.connect(self.startScreenTimer)
def stopScreenTimer(self):
self.screenTimer.stop()
self.screenTimerLabel.setText("0.00 seg")
self.timerLabel.setText("0.00 s")
self.timeValue = 0
self.screenTimerFlag = False
self.startTimerButton.setText("Iniciar")
self.pauseTimerButton.setText("Iniciar")
def updateScreenTimer(self):
self.timeValue += 0.1
self.screenTimerLabel.setText("%.1f seg" % self.timeValue)
self.timerLabel.setText("%.1f s" % self.timeValue)
def updateCurrentTime(self):
self.currentTime = (str(datetime.now().time()))
......
This diff is collapsed.
......@@ -473,29 +473,12 @@ border:1px solid rgb(123, 0, 129);</string>
<property name="title">
<string>Timer</string>
</property>
<widget class="QPushButton" name="startTimerButton">
<property name="geometry">
<rect>
<x>170</x>
<y>30</y>
<width>51</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(53, 53, 53);
border: 1px solid rgb(44, 0, 47);</string>
</property>
<property name="text">
<string>Iniciar</string>
</property>
</widget>
<widget class="QGroupBox" name="timerGBox">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>141</width>
<width>211</width>
<height>71</height>
</rect>
</property>
......@@ -521,14 +504,45 @@ border: 1px solid rgb(44, 0, 47);
font: 75 12pt &quot;Noto Serif&quot;;</string>
</property>
<property name="text">
<string>10.2674 s</string>
<string>0.00 s</string>
</property>
</widget>
<widget class="QPushButton" name="startTimerButton">
<property name="geometry">
<rect>
<x>130</x>
<y>10</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(53, 53, 53);
border: 1px solid rgb(44, 0, 47);</string>
</property>
<property name="text">
<string>Iniciar</string>
</property>
</widget>
<widget class="QPushButton" name="stopTimerButton">
<property name="geometry">
<rect>
<x>130</x>
<y>40</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(53, 53, 53);
border: 1px solid rgb(44, 0, 47);</string>
</property>
<property name="text">
<string>Parar</string>
</property>
</widget>
<zorder>timerLabel</zorder>
<zorder>startTimerButton</zorder>
<zorder>stopTimerButton</zorder>
</widget>
<widget class="QGroupBox" name="currentTimeGBox">
<widget class="QGroupBox" name="startTimeGBox">
<property name="geometry">
<rect>
<x>240</x>
......@@ -543,7 +557,7 @@ font: 75 12pt &quot;Noto Serif&quot;;</string>
<property name="title">
<string>Horário de Início</string>
</property>
<widget class="QLabel" name="currentTimeLabel">
<widget class="QLabel" name="startTimeLabel">
<property name="geometry">
<rect>
<x>30</x>
......@@ -562,7 +576,7 @@ font: 14pt &quot;Noto Serif&quot;;</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="horaAtualGBox">
<widget class="QGroupBox" name="currentTimeGBox">
<property name="geometry">
<rect>
<x>240</x>
......@@ -577,7 +591,7 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<property name="title">
<string>Horário Atual</string>
</property>
<widget class="QLabel" name="horaAtualLabel">
<widget class="QLabel" name="currentTimeLabel">
<property name="geometry">
<rect>
<x>30</x>
......@@ -596,29 +610,12 @@ font: 14pt &quot;Noto Serif&quot;;</string>
</property>
</widget>
</widget>
<widget class="QPushButton" name="stopTimerButton">
<property name="geometry">
<rect>
<x>170</x>
<y>70</y>
<width>51</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color:rgb(53, 53, 53);
border: 1px solid rgb(44, 0, 47);</string>
</property>
<property name="text">
<string>Parar</string>
</property>
</widget>
<widget class="QGroupBox" name="regTimerGBox">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>141</width>
<width>211</width>
<height>71</height>
</rect>
</property>
......@@ -628,7 +625,24 @@ border: 1px solid rgb(44, 0, 47);</string>
<property name="title">
<string>Cont. Regressivo</string>
</property>
<widget class="QLabel" name="regTimerLabel">
<widget class="QPushButton" name="startRegTimerButton">
<property name="geometry">
<rect>
<x>130</x>
<y>10</y>
<width>51</width>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">border: 1px solid rgb(255,255,255);
background-color:rgb(53, 53, 53)</string>
</property>
<property name="text">
<string>Iniciar</string>
</property>
</widget>
<widget class="QLineEdit" name="regTimerLabel">
<property name="geometry">
<rect>
<x>20</x>
......@@ -643,35 +657,15 @@ border: 1px solid rgb(255,255,255);
color:rgb(255,255,255);
font: 75 12pt &quot;Noto Serif&quot;;</string>
</property>
<property name="text">
<string>10.2674 s</string>
</property>
</widget>
</widget>
<widget class="QPushButton" name="startRegTimerButton">
<property name="geometry">
<rect>
<x>170</x>
<y>120</y>
<width>51</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">border: 1px solid rgb(255,255,255);
background-color:rgb(53, 53, 53)</string>
</property>
<property name="text">
<string>Iniciar</string>
</property>
</widget>
<widget class="QPushButton" name="stopRegTimerButton">
<property name="geometry">
<rect>
<x>170</x>
<x>140</x>
<y>160</y>
<width>51</width>
<height>31</height>
<height>21</height>
</rect>
</property>
<property name="styleSheet">
......@@ -742,7 +736,7 @@ background-color:rgb(53, 53, 53)</string>
</rect>
</property>
<property name="text">
<string>/home/LAPMA/Pressao/1025565.pre</string>
<string>/home/LAPMA/Pressao/1025565.temp</string>
</property>
</widget>
<widget class="QGroupBox" name="ambientTempGBox">
......@@ -900,16 +894,6 @@ font: 14pt &quot;Noto Serif&quot;;</string>
</widget>
</widget>
</widget>
<zorder>CentralGraph</zorder>
<zorder>scaleBox</zorder>
<zorder>samplingBox</zorder>
<zorder>cronometroBox</zorder>
<zorder>prensaNameGBox</zorder>
<zorder>arquivoSalvoLabel</zorder>
<zorder>arqSalvoLabel</zorder>
<zorder>ambientTempGBox</zorder>
<zorder>amostragemBox_2</zorder>
<zorder>absolValGBox</zorder>
</widget>
<widget class="QStatusBar" name="menuStatusBar"/>
<widget class="QMenuBar" name="menuBar">
......@@ -921,15 +905,15 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuArquivo">
<widget class="QMenu" name="fileMenu">
<property name="title">
<string>Arquivo</string>
</property>
<addaction name="botaoAbrir"/>
<addaction name="botaoSalvar"/>
<addaction name="botaoSalvarComo"/>
<addaction name="openButton"/>
<addaction name="saveButton"/>
<addaction name="saveAsButton"/>
</widget>
<widget class="QMenu" name="menuEtapa">
<widget class="QMenu" name="stageMenu">
<property name="title">
<string>Etapa</string>
</property>
......@@ -937,32 +921,32 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<addaction name="alternaCalibraT"/>
<addaction name="alternaProc"/>
</widget>
<widget class="QMenu" name="menuPorta">
<widget class="QMenu" name="serialMenu">
<property name="title">
<string>Porta</string>
</property>
</widget>
<widget class="QMenu" name="menuPlay_Pause">
<widget class="QMenu" name="playPauseButton">
<property name="title">
<string>Iniciar/Pausar</string>
</property>
</widget>
<widget class="QMenu" name="menuTermopar">
<widget class="QMenu" name="ThermocoupleMenu">
<property name="title">
<string>Termopar</string>
</property>
</widget>
<widget class="QMenu" name="menuFinalizar">
<widget class="QMenu" name="finalizeButton">
<property name="title">
<string>Finalizar</string>
</property>
</widget>
<addaction name="menuArquivo"/>
<addaction name="menuEtapa"/>
<addaction name="menuPorta"/>
<addaction name="menuTermopar"/>
<addaction name="menuPlay_Pause"/>
<addaction name="menuFinalizar"/>
<addaction name="fileMenu"/>
<addaction name="stageMenu"/>
<addaction name="serialMenu"/>
<addaction name="ThermocoupleMenu"/>
<addaction name="playPauseButton"/>
<addaction name="finalizeButton"/>
</widget>
<action name="alternaCalibraP">
<property name="text">
......@@ -979,7 +963,7 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<string>Processamento</string>
</property>
</action>
<action name="botaoAbrir">
<action name="openButton">
<property name="enabled">
<bool>false</bool>
</property>
......@@ -1000,12 +984,12 @@ font: 14pt &quot;Noto Serif&quot;;</string>
<string>Salvar Como</string>
</property>
</action>
<action name="botaoSalvar">
<action name="saveButton">
<property name="text">
<string>Salvar</string>
</property>
</action>
<action name="botaoSalvarComo">
<action name="saveAsButton">
<property name="text">
<string>Salvar Como</string>
</property>
......
import serial
import serial.tools.list_ports
import time
from PyQt5 import QtWidgets
class SerialManager(object):
......@@ -21,4 +22,12 @@ class SerialManager(object):
if(self.ser.inWaiting()==0):
pass
self.ser.flushInput()
return self.ser.readline()
\ No newline at end of file
return self.ser.readline()
def serialListPanel(self, uiWindow):
uiWindow.usb = []
for i in range(0, len(self.portList)):
uiWindow.usb.append(QtWidgets.QAction(uiWindow.MainWindow))
uiWindow.usb[i].setText(self.portList[i].device)
uiWindow.usb[i].setCheckable(True)
uiWindow.serialMenu.addAction(uiWindow.usb[i])
\ No newline at end of file
......@@ -4,7 +4,7 @@ import sys
from PyQt5 import QtCore,QtGui,QtWidgets
from pyqtgraph import GraphicsLayout
from SerialManager import SerialManager
from CalibracaoT import Ui_MainWindow
from CalibracaoP import Ui_MainWindow
from Graph import Graph
import numpy as np
from math import sin,log
......@@ -19,22 +19,29 @@ class SystemEngine(object):
self.ser1.startPort(str(self.ser1.portList[0].device), 115200)
self.uiCalibra1 = Ui_MainWindow()
self.uiCalibra1.setupUi(self.dialog)
self.uiCalibra1.serialListPanel(self.ser1.portList)
self.prev_x_scale=100
self.x_scale=100
self.y1_min=0
self.y1_max=32700
self.y2_min=0
self.y2_max=10000
self.ser1.serialListPanel(self.uiCalibra1)
self.x_scale=10
self.nCurves = 2
self.y_min=[0,0]
self.y_max=[32700,10000]
self.color = ['r','g']
self.name = ["Força","Tensão no Calibrante"]
self.unit = ["Tonf","mV"]
self.layout=GraphicsLayout()
self.updateTimer()
self.graph = Graph(self.time[0]/1000,self.x_scale, self.y1_min, self.y1_max, self.y2_min, self.y2_max, 800, 500, 'r', 'g', "Força", "Tensão no Calibrante")
self.graph = Graph(self.time[0]/1000,self.x_scale,self.nCurves, self.y_min, self.y_max, 800, 500, self.color,self.name,self.unit)
self.layout.addItem(self.graph.axis[0],row=1,col=1,rowspan=1,colspan=1)
for n in range(1,self.nCurves):
self.layout.addItem(self.graph.axis[n],row=1,col=n+2,rowspan=1,colspan=1)
self.layout.addItem(self.graph.axis2,row=1,col=3,rowspan=1,colspan=1)
self.layout.addItem(self.graph.axis1,row=1,col=1,rowspan=1,colspan=1)
self.layout.addItem(self.graph.axisTime,row=2,col=2,rowspan=1,colspan=1)
self.layout.addItem(self.graph,row=1,col=2,rowspan=1,colspan=1)
self.layout.setMinimumSize(500, 600)
self.layout.setMaximumSize(500,600)
......@@ -52,7 +59,19 @@ class SystemEngine(object):
#self.layout.setMaximumSize(770,550)
self.scene.focusItem()
self.uiCalibra1.sceneSelector(self.scene)
self.sceneSelector(self.scene)
self.uiCalibra1.menuPlay_Pause = QtWidgets.QAction(self.dialog)
self.uiCalibra1.menuPlay_Pause.setText("Play")
self.uiCalibra1.menuPlay_Pause.setObjectName("menuPlay_Pause")
self.uiCalibra1.menuBar.addAction(self.uiCalibra1.menuPlay_Pause)
self.uiCalibra1.menuPlay_Pause.setCheckable(True)
self.uiCalibra1.menuPlay_Pause.toggled.connect(self.playPauseButtonAnimation)
self.uiCalibra1.linkActions()
self.dialog.showMaximized()
......@@ -68,22 +87,38 @@ class SystemEngine(object):
self.timer.start(100)
def playPauseButtonAnimation(self):
if (self.uiCalibra1.menuPlay_Pause.text() == "Play"):
self.uiCalibra1.menuPlay_Pause.setText("Pause")
self.uiCalibra1.startTimeLabel.setText(self.uiCalibra1.currentTimeLabel.text())
else:
self.uiCalibra1.menuPlay_Pause.setText("Play")
def sceneSelector(self, scene):
self.uiCalibra1.CentralGraph.setScene(scene)
self.uiCalibra1.CentralGraph.setBackgroundBrush(QtCore.Qt.black)
self.uiCalibra1.CentralGraph.setInteractive(False)
def updateData(self):
#print(time.time()-self.timeant)
if(self.uiCalibra1.menuPlay_Pause.isChecked()==True):
readData = self.ser1.read() # Lê o dado da serial
readData = readData.decode('utf8')
dado = readData.split(' ', 3)
dado = readData.split(' ', self.nCurves+1)
dado[len(dado)-1]=dado[len(dado)-1].split('\n',2)[0]
try:
self.uiCalibra1.forceLabel.setText(str(dado[0])+" Tonf")
self.uiCalibra1.calibratorLabel.setText(str(dado[1].split()[0])+" mV")
#self.uiCalibra1.forceLabel.setText(str(dado[0])+" Tonf")
#self.uiCalibra1.calibratorLabel.setText(str(dado[1].split()[0])+" mV")
pass
except IndexError:
print("Erro no Indice do Array Enviado pela Serial")
try:
self.graph.updateGraph(float(dado[0]),float(dado[1]))
except ValueError:
print("Erro nos Valores do Array Enviado pela Serial")
print(dado)
self.graph.updateGraph(dado)
except Exception as e:
print(e)
except IndexError:
print("Erro: Array inválido")
print(dado)
......
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