Commit 2baf4f8a authored by Alisson Claudino's avatar Alisson Claudino

Separação em Classes e Adição do grafico numa GUI

parent cab73176
from PyQt5 import QtCore,QtGui,QtWidgets # importação de classes
import pyqtgraph
import serial
import time
import sys
from mainwindow import Ui_MainWindow
class GUI(Ui_MainWindow):
def __init__(self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
class SerialManager(object):
def __init__(self):
self.ser = serial.Serial('/dev/ttyACM0', 115200) # Inicialização da Serial com baudrate 115200bps
self.ser.setDTR(False) # Reset do arduino para reinicio da leitura
time.sleep(0.022)
self.ser.setDTR(True)
self.ser.readline() # Primeiro valor da serial sai com lixo
def read(self):
if(self.ser.inWaiting()==0):
pass
return self.ser.read()
class Graph(pyqtgraph.GraphicsLayout):
index=0
def __init__(self,x_range,y_range,x_size,y_size,color):
self.x_range = x_range
self.y_range = y_range
self.x_size = x_size
self.y_size = y_size
self.p1 = self.addPlot()
self.curve1 = p1.plot(pen=color)
self.setPreferredSize(x_size,y_size)
self.p1.setXRange(0,x_range,padding=0)
self.p1.setYRange(0, y_range, padding=0)
self.x1=[]
self.y1=[]
def updateGraph(self,value):
y1.append(value)
index += 1
if len(y1)>x_range-1:
del y1[0]
self.index = x_range
else:
x1.append(index)
self.curve1.setData(x1,y1)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QMainWindow()
prog = GUI(dialog)
dialog.show()
sys.exit(app.exec_())
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(703, 460)
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.CentralGraph = QtWidgets.QGraphicsView(self.centralWidget)
self.CentralGraph.setGeometry(QtCore.QRect(160, 20, 481, 361))
self.CentralGraph.setObjectName("CentralGraph")
self.ForceDisp = QtWidgets.QLabel(self.centralWidget)
self.ForceDisp.setGeometry(QtCore.QRect(60, 200, 57, 17))
self.ForceDisp.setObjectName("ForceDisp")
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 703, 23))
self.menuBar.setObjectName("menuBar")
self.menuXuxuzinho = QtWidgets.QMenu(self.menuBar)
self.menuXuxuzinho.setObjectName("menuXuxuzinho")
MainWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(MainWindow)
self.mainToolBar.setObjectName("mainToolBar")
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
self.statusBar = QtWidgets.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)
self.menuBar.addAction(self.menuXuxuzinho.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "SADAM - Análise de Dados"))
self.ForceDisp.setText(_translate("MainWindow", "TextLabel"))
self.menuXuxuzinho.setTitle(_translate("MainWindow", "Arquivo"))
def sceneSelector(self,scene):
self.CentralGraph.setScene(scene)
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