PyQtgraph x QTimer
-
Hi all;
Now, another problem..
When i run pyqtgraph...self.frame = PlotWidget(Dialog) .... self.timer1 = QTimer() self.timer1.timeout.connect(self.showtime) self.timer1.start() self.timer2 = QTimer() self.timer2.timeout.connect(self.showspo2) self.timer2.start(250) def showtime(self): time=QDateTime.currentDateTime() timeDisplay=time.toString(....) self.label.setText(timeDisplay) def showspo2(self): spo2=sum(....) self.label2.setText(str(spo2)) self.frame.plot(str(spo2))
... the window open and the labels works, but the graphic doesn't. The error that appears on the output is:
if y is None or len(y) == 0: # empty data is represented as None
TypeError: len() of unsized object.Note:
The graphic should be data(y) vs time(x). -
@DAMSdevnation
Since the error shows Python code not in your own, isn't this something elsewhere in PyQtgraph to ask in a PyQtGraph forum? Or is it your own code and you don't show it? -
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from pyqtgraph import PlotWidget, plot
import pyqtgraph
import time
import os
import label_teste
import max30100mx30 = max30100.MAX30100()
mx30.enable_spo2()class Ui_Dialog(object):
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(1400, 350) self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(60, 180, 381, 81)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(18) self.label.setFont(font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setObjectName("label") self.label.setStyleSheet("background-color: rgb(71, 71, 71);") self.label.setStyleSheet("color: rgb(55, 55, 127);") self.label2 = QtWidgets.QLabel(Dialog) self.label2.setGeometry(QtCore.QRect(60, 50, 381, 81)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(18) self.label2.setFont(font) self.label2.setAlignment(QtCore.Qt.AlignCenter) self.label2.setObjectName("label2") self.label3 = QtWidgets.QLabel(Dialog) self.label3.setGeometry(QtCore.QRect(60, 100, 381, 81)) font = QtGui.QFont() font.setFamily("Arial") font.setPointSize(18) self.label3.setFont(font) self.label3.setAlignment(QtCore.Qt.AlignCenter) self.label3.setObjectName("label3") self.frame_6 = PlotWidget(Dialog) self.frame_6.setGeometry(QtCore.QRect(500, 40, 830, 280)) self.frame_6.setStyleSheet("background-color: rgb(79, 79, 79);") self.frame_6.setFrameShape(QtWidgets.QFrame.StyledPanel) self.frame_6.setFrameShadow(QtWidgets.QFrame.Raised) self.frame_6.setObjectName("frame_6") self.frame_6.setLabel('left', "<span style=\"color:white;font-size:20px\">SpO2 (%)</span>") self.timer = QTimer() self.timer.setInterval(20) self.timer.timeout.connect(self.showbpm) self.timer.start(500) self.timer2 = QTimer() self.timer2.setInterval(0) self.timer2.timeout.connect(self.showtime) self.timer2.start(100) self.timer3 = QTimer() self.timer3.setInterval(20) self.timer3.timeout.connect(self.showspo2) self.timer3.start(250) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "Dialog")) self.label.setText(_translate("Dialog", "TextLabel")) self.label2.setText(_translate("Dialog", "TextLabel2")) self.label3.setText(_translate("Dialog", "TextLabel3")) def showtime(self): time=QDateTime.currentDateTime() timeDisplay=time.toString('dd/MM/yyyy hh:mm:ss dddd') self.label.setText(timeDisplay) def showbpm(self): mx30.read_sensor() bpm=14000/((1)+sum(mx30.buffer_red)/len(mx30.buffer_red)/100) if (bpm>220): bpm ='NA' self.label2.setText(str(bpm)[:5]) def showspo2(self): mx30.read_sensor() spo2=sum(mx30.buffer_ir)/len(mx30.buffer_ir)/100 self.label3.setText(str(spo2)[:4]) self.frame_6.plot(str(spo2))
from pyqtgraph import PlotWidget
if name == "main":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_()) -
@JonB said in PyQtgraph x QTimer:
@DAMSdevnation
Since the error shows Python code not in your own, isn't this something elsewhere in PyQtgraph to ask in a PyQtGraph forum? Or is it your own code and you don't show it?if y is None or len(y) == 0: # empty data is represented as None TypeError: len() of unsized object.
-
But how i say, X-axis (time) and Y-axis (data)?