通过文本文件将8 pyqtgraph嵌入QT.ui

时间:2019-05-22 09:23:20

标签: python-3.x

首先,我希望您有耐心,因为我是这个GUI应用程序的新手。我已经为Windows 7创建了GUI。这里我有8组传感器数据,我将绘制所有8个传感器的图。 QT GUI上的数据。有了基本的UI后,我使用pyuic5将.ui文件转换为.py文件,并且能够打开它。.这里的问题是,每当我给出一些采样频率和偏移量时,然后基于传感器选择我需要绘制实时图1。我无法在此处整合图表        2.我不知道如何为我的实时数据整合代码        3.请帮助如何编写后端代码以给出采样频率,偏移量        4.如何单击传感器数据以及如何根据传感器选择绘制图形。

######this is my test data###############

# -*- coding: utf-8 -*-
import time
import xlrd
file_location="maximum.xlsx"
workbook=xlrd.open_workbook(file_location)
sheet=workbook.sheet_by_index(0)
try:
    while(1):
        for r in range(1,sheet.nrows):
            print(sheet.ncols)
            file = open("tst.txt", "r")
            #print("hey file")
            print(file.read())
            file.closed
            data = sheet.row_values(r)
            #print("hey data")
##            print data
            with open("tst.txt","w") as f:
                for i in data:
                    f.write(str(i))
                    f.write("\n")
            time.sleep(1)
except KeyboardInterrupt:
    pass

############### tis is GUI code for my application################

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'tan1.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(795, 359)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.listView = QtWidgets.QListView(self.centralwidget)
        self.listView.setGeometry(QtCore.QRect(10, 20, 491, 281))
        self.listView.setObjectName("listView")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(530, 260, 80, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(620, 260, 80, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(520, 10, 251, 291))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label = QtWidgets.QLabel(self.frame)
        self.label.setGeometry(QtCore.QRect(140, 6, 101, 20))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.frame)
        self.label_2.setGeometry(QtCore.QRect(150, 40, 51, 20))
        self.label_2.setObjectName("label_2")
        self.Sensor1 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1.setGeometry(QtCore.QRect(30, 70, 74, 21))
        self.Sensor1.setObjectName("Sensor1")
        self.Sensor1_2 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_2.setGeometry(QtCore.QRect(30, 90, 74, 21))
        self.Sensor1_2.setObjectName("Sensor1_2")
        self.Sensor1_3 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_3.setGeometry(QtCore.QRect(30, 110, 74, 21))
        self.Sensor1_3.setObjectName("Sensor1_3")
        self.Sensor1_4 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_4.setGeometry(QtCore.QRect(30, 130, 71, 21))
        self.Sensor1_4.setObjectName("Sensor1_4")
        self.Sensor1_5 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_5.setGeometry(QtCore.QRect(30, 150, 74, 21))
        self.Sensor1_5.setObjectName("Sensor1_5")
        self.Sensor1_6 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_6.setGeometry(QtCore.QRect(30, 170, 74, 21))
        self.Sensor1_6.setObjectName("Sensor1_6")
        self.Sensor1_7 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_7.setGeometry(QtCore.QRect(30, 190, 74, 21))
        self.Sensor1_7.setObjectName("Sensor1_7")
        self.Sensor1_8 = QtWidgets.QCheckBox(self.frame)
        self.Sensor1_8.setGeometry(QtCore.QRect(30, 210, 71, 21))
        self.Sensor1_8.setObjectName("Sensor1_8")
        self.lineEdit = QtWidgets.QLineEdit(self.frame)
        self.lineEdit.setGeometry(QtCore.QRect(20, 10, 113, 21))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.frame)
        self.lineEdit_2.setGeometry(QtCore.QRect(20, 40, 113, 20))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.frame.raise_()
        self.listView.raise_()
        self.pushButton.raise_()
        self.pushButton_2.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 795, 21))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuAbout = QtWidgets.QMenu(self.menubar)
        self.menuAbout.setObjectName("menuAbout")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionOpen = QtWidgets.QAction(MainWindow)
        self.actionOpen.setObjectName("actionOpen")
        self.actionSave_As = QtWidgets.QAction(MainWindow)
        self.actionSave_As.setObjectName("actionSave_As")
        self.actionScreenshot = QtWidgets.QAction(MainWindow)
        self.actionScreenshot.setObjectName("actionScreenshot")
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.menuFile.addAction(self.actionOpen)
        self.menuFile.addAction(self.actionSave_As)
        self.menuFile.addAction(self.actionScreenshot)
        self.menuFile.addAction(self.actionExit)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuAbout.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "Plot"))
        self.pushButton_2.setText(_translate("MainWindow", "Pause"))
        self.label.setText(_translate("MainWindow", "Sampling Frequency"))
        self.label_2.setText(_translate("MainWindow", "Offset"))
        self.Sensor1.setText(_translate("MainWindow", "Sensor1"))
        self.Sensor1_2.setText(_translate("MainWindow", "Sensor2"))
        self.Sensor1_3.setText(_translate("MainWindow", "Sensor3"))
        self.Sensor1_4.setText(_translate("MainWindow", "Sensor4"))
        self.Sensor1_5.setText(_translate("MainWindow", "Sensor5"))
        self.Sensor1_6.setText(_translate("MainWindow", "Sensor6"))
        self.Sensor1_7.setText(_translate("MainWindow", "Sensor7"))
        self.Sensor1_8.setText(_translate("MainWindow", "Sensor8"))
        self.menuFile.setTitle(_translate("MainWindow", "File"))
        self.menuAbout.setTitle(_translate("MainWindow", "About"))
        self.actionOpen.setText(_translate("MainWindow", "Open"))
        self.actionSave_As.setText(_translate("MainWindow", "Save As"))
        self.actionScreenshot.setText(_translate("MainWindow", "Screenshot"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

0 个答案:

没有答案