Im creating a GUI (graphical user interface) that read 3 sensors and display 2 as lcd and plot the other. I have been able to create the GUI with the elements required and start measuring when I press a botton. But it only work with the plotting system. I have not been able to make the other 2 displays work. In resume I have not been able to understand how the update system work. Note, By now everything is working with random numbers then i will change the update to take the elements that I need.
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import random
from math import*
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.central_widget = QtGui.QStackedWidget()
self.setCentralWidget(self.central_widget)
self.login_widget = LoginWidget(self)
self.login_widget.button.clicked.connect(self.plotter)
self.central_widget.addWidget(self.login_widget)
def plotter(self):
self.data =[0]
self.start = time.time()
self.curve = self.login_widget.plot.getPlotItem().plot()
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.updater)
self.timer.start(0)
def updater(self):
self.data.append(self.data[-1]+0.2*(0.5-random.random()))
self.curve.setData(self.data)
self.end = time.time()
self.login_widget.Temperatura.display(self.data[-1])
self.login_widget.etanol.display(self.end-self.start)
class LoginWidget(QtGui.QWidget):
def __init__(self, parent=None):
super(LoginWidget, self).__init__(parent)
layout = QtGui.QVBoxLayout()
hbox1 = QtGui.QHBoxLayout()
hbox2 = QtGui.QHBoxLayout()
hbox3 = QtGui.QHBoxLayout()
self.button = QtGui.QPushButton('Start')
self.button2 = QtGui.QPushButton('Save')
self.plot = pg.PlotWidget()
self.setLayout(layout)
self.Temperatura = QtGui.QLCDNumber(self)
self.Temperatura.setStyleSheet("QWidget { background-color: rgb(100, 100, 255) }")
self.etanol = QtGui.QLCDNumber(self)
self.WindowSize = QtGui.QLabel("Temperature")
self.SampPts = QtGui.QLabel("% Ethanol")
layout.addLayout(hbox1)
hbox1.addWidget(self.button2)
hbox1.addWidget(self.button)
layout.addLayout(hbox2)
hbox2.addWidget(self.WindowSize)
hbox2.addWidget(self.SampPts)
layout.addLayout(hbox3)
hbox3.addWidget(self.Temperatura)
hbox3.addWidget(self.etanol)
layout.addWidget(self.plot)
if __name__ == '__main__':
app = QtGui.QApplication([])
window = MainWindow()
window.show()
app.exec_()
The expected result is that wen i press the button all the elements should show different random numbers and start plotting. by now it's only start plotting. I don't like the LCD Widget, if you know another please tell me.
thank!