UOS python+pyqt5实现HDD测试

发布时间:2023年12月30日
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'hdd.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


import sys
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore
from PyQt5.Qt import QTimer
import logging
import subprocess
from subprocess import Popen
import os
import json
import configparser

class Ui_HddTestMainFrm(QWidget):
    def __init__(self):
        super().__init__()
        self.config = configparser.ConfigParser()  # 创建对象
        self.disk_info = []  # 硬盘信息
        self.Usb_info = []  # Usb信息
        self.StorageName = []  # 所有存储器名称
        self.testArgs = []  # 测试参数信息
        self.testStandardArgs = ''  # 测试标准参数
        self.itemName=''#项目名称
        self.itemFailSleepExit=0#项目Fail延时退出
        self.testHddCount=0#测试硬盘数
        self.testBrand=[]#测试品牌集
        self.testReads=[]#测试速率
        self.testSize=[]#测试容量

        self.readHddCount=0#读取硬盘数
        self.readBard=''#读取品牌集合信息
        self.readReads=''#读取速率集合信息
        self.readSize=''#读取容量

        self.nowSleep=0#当前延时

        # 生成日志信息
        self.logger = logging.getLogger('my_logger')  # 步骤1 创建日志记录器
        self.logger.setLevel(logging.DEBUG)  # 步骤2 将指定日志级别
        self.file_handler = logging.FileHandler('./log/log.txt')  # 步骤3 创建文件处理器
        self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')  # 步骤4 创建格式化器
        self.file_handler.setFormatter(self.formatter)  # 步骤4 将格式化器添加到处理器
        self.logger.addHandler(self.file_handler)  # 步骤5 将处理器添加到日志记录器

        # 读取配置
        self.config.read('./Conf/config.conf', encoding='utf-8')  # 读取配置文件,如果配置文件不存在则创建

        #读取测试配置
        self.itemName=self.config.get('TestItemNameArrays','HddTestName')
        self.itemFailSleepExit=int(self.config.get('TestItemWinFrmSleepExit','HddTest'))#项目测试Fail延时退出
        self.testArgs = self.ReadJsonInfo('./Conf/TestArgs.json')  # 读取测试参数信息
        
        #读取标准值
        if self.ReadJsonTestArgs(self.itemName)==True:
            #print(self.testStandardArgs)
            testArgs=[]#测试参数
            testArgs=self.testStandardArgs.split('|')
            self.testHddCount=int(testArgs[0])#读取的数量
            self.testSize=testArgs[1].split(',')#容量
            self.testBrand=testArgs[2].split(',')#硬盘品牌 
            self.testReads=testArgs[3].split(',')#测试速率
            #print('testHddCount',self.testHddCount)
            #print('testBrand',self.testBrand)
            #print('testReads',self.testReads)
            self.setupUi()
            if self.Get_disk_Info()==True:
                # 同步当前时间
                    # 创建一个定时器,用于更新QLCDNumber的时间
                self.timer = QTimer()
                self.timer.timeout.connect(self.update_time)
                self.timer.start(1000)  # 每隔1000毫秒(1秒)更新一次时间


        #self.verticalLayout_8.addLayout(sub_layout3)


    #获取硬件设备信息
    def Get_disk_Info(self):
        try:
            self.disk_info.clear()#清空USB设备装置信息
            self.Usb_info.clear()#清空硬盘装置信息
            if self.GetDirectoryAllFileName('/sys/block'):
                for deviceName in self.StorageName:
                    self.ReadStorageInfo('/dev/'+deviceName)
                i=0
                passcount=0
                disk_layout = QHBoxLayout()
                #devicePath, size, reads, type, brand, testResult, serial_Number, fW, power_Cycles, power_On_Hours, temperature

                for dsinfo in self.disk_info:#遍历硬盘读取
                    isSizePass=False
                    isReadsPass=False
                    isBrandPass=False
                    self.readSize=dsinfo['Size']+','
                    self.readBard=dsinfo['Brand']+','
                    self.readReads=dsinfo['reads']+','
                    if self.testSize[i]==dsinfo['Size']:
                        isSizePass=True
                    if self.testBrand[i]==dsinfo['Brand']:
                        isBrandPass=True
                    #if self.testReads[i]==dsinfo['reads']:
                    #    isReadsPass=True
                    #print(dsinfo['reads'],isReadsPass)
                    if isSizePass==True and isBrandPass==True:
                        passcount += 1

                    win=Ui_Form(dsinfo['DevicePath'],dsinfo['Size'],dsinfo['reads'],dsinfo['Type'],dsinfo['Brand'],dsinfo['Serial_Number'],dsinfo['FW'],dsinfo['Power_Cycles'],dsinfo['Power_On_Hours'],dsinfo['Temperature'],isSizePass,isBrandPass)
                    disk_layout.addWidget(win)
                    i+=1
                    if i%2==0:
                        self.verticalLayout_8.addLayout(disk_layout)
                        disk_layout=QHBoxLayout()
                if disk_layout.count()>0:
                    self.verticalLayout_8.addLayout(disk_layout)

                self.readHddCount=len(self.disk_info)
                readValue=str(str(self.readHddCount))+'|'+self.readSize[:-1]+'|'+self.readBard[:-1]+'|'+self.readReads[:-1]
                if passcount==self.testHddCount:
                    self.lbl_log.setStyleSheet("color:green;")
                    self.lbl_log.setText('PASS')
                    self.UpdateJsonTestArgs(self.itemName,readValue,'PASS')

                    # 同步当前时间
                    # 创建一个定时器,用于更新QLCDNumber的时间
                    #self.timer = QTimer()
                    #self.timer.timeout.connect(self.update_time)
                    #self.timer.start(1000)  # 每隔1000毫秒(1秒)更新一次时间
                    #time.sleep(3)
                    return True
                    #sys.exit(0)
                else:
                    font = QtGui.QFont()
                    font.setPointSize(12)
                    self.lbl_log.setFont(font)
                    self.lbl_log.setStyleSheet("color:red;")
                    self.lbl_log.setText('read:'+readValue+'\n'+'args:'+self.testStandardArgs+'\nFail!!')
                    self.UpdateJsonTestArgs(self.itemName, readValue, 'FAIL')
                    #time.sleep(self.itemFailSleepExit)
                    #sys.exit(1)
                    return False
            else:
                self.ShowLog("Get Disk Device Name Is Empty!!", False)
                sys.exit(1)
        except Exception as e:
            self.ShowLog("Get Disk Info Err:" + str(e),False)
            sys.exit(1)

    #同步当前时间
    def update_time(self):
        # 获取当前时间
        #current_time = QTime.currentTime()
        self.nowSleep+=1
        if self.nowSleep==self.itemFailSleepExit:
            sys.exit(0)
        #current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        # 将当前时间显示在QLCDNumber上


    def setupUi(self):
        self.setObjectName("HddTestMainFrm")
        self.resize(737, 453)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("IMAGE/hdd.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.setWindowIcon(icon)
        self.verticalLayout_9 = QtWidgets.QVBoxLayout(self)
        self.verticalLayout_9.setObjectName("verticalLayout_9")
        self.verticalLayout_6 = QtWidgets.QVBoxLayout()
        self.verticalLayout_6.setObjectName("verticalLayout_6")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.lbl_Logo = QtWidgets.QLabel(self)
        self.lbl_Logo.setText("")
        self.lbl_Logo.setPixmap(QtGui.QPixmap("IMAGE/logo.jpg"))
        self.lbl_Logo.setObjectName("lbl_Logo")
        self.horizontalLayout_3.addWidget(self.lbl_Logo)
        self.lbl_Title = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setPointSize(23)
        self.lbl_Title.setFont(font)
        self.lbl_Title.setObjectName("lbl_Title")
        self.horizontalLayout_3.addWidget(self.lbl_Title)
        self.verticalLayout_6.addLayout(self.horizontalLayout_3)
        self.verticalLayout_8 = QtWidgets.QVBoxLayout()
        self.verticalLayout_8.setObjectName("verticalLayout_8")
        self.verticalLayout_6.addLayout(self.verticalLayout_8)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.groupBox = QtWidgets.QGroupBox(self)
        font = QtGui.QFont()
        font.setPointSize(13)
        self.groupBox.setFont(font)
        self.groupBox.setObjectName("groupBox")
        self.verticalLayout_10 = QtWidgets.QVBoxLayout(self.groupBox)
        self.verticalLayout_10.setObjectName("verticalLayout_10")
        self.lbl_log = QtWidgets.QLabel(self.groupBox)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.lbl_log.setFont(font)
        self.lbl_log.setStyleSheet("background-color: rgb(0, 0, 0);\n""color: rgb(255, 170, 0);")
        self.lbl_log.setAlignment(QtCore.Qt.AlignCenter)
        self.lbl_log.setObjectName("lbl_log")
        self.verticalLayout_10.addWidget(self.lbl_log)
        self.horizontalLayout_4.addWidget(self.groupBox)
        self.verticalLayout_6.addLayout(self.horizontalLayout_4)
        self.verticalLayout_9.addLayout(self.verticalLayout_6)

        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
        self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint)  # 只显示最小化按钮和关闭按钮

    #读取项目参数信息,itemName:项目名称
    def ReadJsonTestArgs(self,itemName):
        try:
            self.testArgs=self.ReadJsonInfo('./Conf/TestArgs.json')
            for js in self.testArgs:
                if itemName in js['ItemName']:
                    self.testStandardArgs=js['Standard']
                    return True
            self.ShowLog('Read TestArgs.json ItemName:'+itemName+' Info Is Empty!!',False)
            sys.exit(1)
        except Exception as e:
            self.ShowLog("Read TestArgs.json ItemName:"+itemName+" Info Err:" + str(e),False)
            sys.exit(1)

    #更新测试参数json,itemName:项目名称,readValue:读取值,testResult:测试结果
    def UpdateJsonTestArgs(self,itemName,readValue,testResult):
        try:
            updateTestArgs=[]#更新的测试参数
            self.testArgs=self.ReadJsonInfo('./Conf/TestArgs.json')
            for js in self.testArgs:
                if itemName in js['ItemName']:
                    js['Read']=readValue#读取的值
                    js['TestResult']=testResult#测试结果
                    updateTestArgs.append(js)
                else:
                    updateTestArgs.append(js)
            with open("./Conf/TestArgs.json", "w") as write_file:
                json.dump(updateTestArgs, write_file)
            return True
        except Exception as e:
            self.ShowLog("Read TestArgs.json ItemName:"+itemName+" Info Err:" + str(e),False)
            sys.exit(1)

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("HddTestMainFrm", "HddTest"))
        self.lbl_Title.setText(_translate("HddTestMainFrm", "【HDD Test】"))
        self.groupBox.setTitle(_translate("HddTestMainFrm", "【日志】"))
        self.lbl_log.setText(_translate("HddTestMainFrm", "待测试"))

    #禁止设整窗体大小
    def resizeEvent(self, event):
        # 获取当前窗口的大小
        current_size = self.size()

        # 设置窗口的最大大小和最小大小,使其无法通过鼠标调整
        self.setMaximumSize(current_size)
        self.setMinimumSize(current_size)

        # 调用父类的resizeEvent方法,以便正常调整窗口大小
        super().resizeEvent(event)

    # 定义一个函数使得函数窗口居中显示
    def Center(self):
        # 获取屏幕尺寸
        screen_geometry = app.desktop().availableGeometry()
        # 计算窗口居中位置
        x = (screen_geometry.width() - self.width()) // 2
        y = (screen_geometry.height() - self.height()) // 2
        # 设置窗口位置
        self.move(x, y)

    #打印的信息
    def ShowLog(self,log,isPass):
        try:
            if isPass == True:
                self.lbl_log.setStyleSheet("color:green;")
                self.logger.info(str(log))
            else:
                self.lbl_log.setStyleSheet("color:red;")
                self.logger.error(str(log))
            self.lbl_log.setText(str(log))
        except Exception as e:
            print("\033[1;31m" + str(e) + " \033[0m")
            sys.exit(1)

    #获取目录下所有文件名
    def GetDirectoryAllFileName(self,DirectoryName):
        try:
            self.StorageName.clear()#清空存储器信息
            # 获取指定目录下所有文件名
            file_names = os.listdir(DirectoryName)

            # 遍历读取所有文件名称
            for file_name in file_names:
                self.StorageName.append(file_name)

            if len(self.StorageName)>0:
                return True
            else:
                return False
        except Exception as e:
            self.ShowLog("Read "+DirectoryName+" Directory Info Err:" + str(e),False)
            sys.exit(1)

    #读取存储器设备信息
    def ReadStorageInfo(self,devicePath):
        try:
            #devicePath:设备路径名称、Size:存信器大小、Type:储寄器类存、Barand:品牌规格、ID_SERIAL:设备通讯信息、DevLinks:设备连接信息
            tempStorageInfo={'DevicePath':'N/A','Size':'N/A','Type':'N/A','Brand':'N/A','DeviceId':'N/A','reads':'N/A',
            'Serial_Number':'N/A','FW':'N/A','Power_Cycles':'N/A','Power_On_Hours':'N/A','Temperature':'N/A'}#临时的存储器信息
            tempStorageInfo['DevicePath']=devicePath#设备路径名称
            ID_SERIAL=self.RuncmdGetInfo('udevadm info --query=property --name='+devicePath+' | grep "ID_SERIAL="')
            DEVLINKS =self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "DEVLINKS="')
            ID_BUS =self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "ID_BUS="')
            DEVPATH=self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "DEVPATH="')
            DiskSize=self.RuncmdGetInfo("fdisk -l | grep 'Disk '"+devicePath)
            DiskSize=DiskSize[DiskSize.find(':')+2:DiskSize.find(',')]
            ID_PART_TABLE_TYPE = self.RuncmdGetInfo('udevadm info --query=property --name=' + devicePath + ' | grep "ID_PART_TABLE_TYPE="')
            tempStorageInfo['Brand']=ID_SERIAL[ID_SERIAL.find('=')+1:]
            tempStorageInfo['Brand']=tempStorageInfo['Brand'][:tempStorageInfo['Brand'].find('_')]#厂商
            tempStorageInfo['Size']=DiskSize#存储器大小
            #tempStorageInfo['DevLinks']=DEVLINKS[DEVLINKS.find('=')+1:]
            if len(ID_BUS)>0:
                temp=DEVPATH[DEVPATH.find('/usb')+1:DEVPATH.find('/host')]
                tempStorageInfo['Type']=temp[:temp.find('/')]#设备类型
                tempStorageInfo['DeviceId']=temp[len(tempStorageInfo['Type'])+1:]#硬件ID
                self.Usb_info.append(tempStorageInfo)
            else:
                reads = self.RuncmdGetInfo('hdparm -tT ' + devicePath + ' | grep "Timing buffered disk reads"')
                reads = reads[reads.find('=') + 2:]
                tempStorageInfo['reads'] = reads  # 读写的速率
                tempStorageInfo['DeviceId']=DEVLINKS[DEVLINKS.find('uuid.')+5:DEVLINKS.find('uuid.')+5+36]#UUID
                Serial_Number=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Serial Number:"')
                tempStorageInfo['Serial_Number']=Serial_Number[Serial_Number.find(':')+23:]#硬盘SN条码
                FW=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Firmware Version:"')
                tempStorageInfo['FW']=FW[FW.find(':')+20:]#硬盘FW
                Power_Cycles=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Power Cycles:"')
                tempStorageInfo['Power_Cycles']=Power_Cycles[Power_Cycles.find(':')+24:]#重启次数
                Power_On_Hours=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Power On Hours:"')
                tempStorageInfo['Power_On_Hours']=Power_On_Hours[Power_On_Hours.find(':')+22:]#通电时间
                Temperature=self.RuncmdGetInfo('smartctl -a '+devicePath+' | grep "Temperature:"')
                tempStorageInfo['Temperature']=Temperature[Temperature.find(':')+25:]#温度
                tempStorageInfo['Type']=ID_PART_TABLE_TYPE[ID_PART_TABLE_TYPE.find('=')+1:]#设备类型
                self.disk_info.append(tempStorageInfo)
        except Exception as e:
            self.ShowLog("Read "+devicePath+" Device Info Err:" + str(e),False)
            sys.exit(1)

    #执行命令行,并获取信息
    def RuncmdGetInfo(self,cmd):
        try:
            readcmdinfo=Popen([cmd],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            #获取子进程输出
            stdout,stderr=readcmdinfo.communicate()
            #将输出转换成字符串
            return stdout.decode("utf-8").strip()#返回数据
        except Exception as e:
            self.ShowLog("Run Cmd Get Info Err:" + str(e), False)
            sys.exit(1)

    #读取json信息
    def ReadJsonInfo(self,fileName):
        try:
            if os.path.exists(fileName):
                f=open(fileName,'r',encoding='utf-8')
            return json.loads(f.read())
        except Exception as e:
            self.ShowLog("Read "+fileName+" Err:" + str(e),False)
            sys.exit(1)

    def closeEvent(self, event):
        # 创建一个消息框,上面有两个按钮:“是”和“否”
        #reply = QMessageBox.question(self, '退出', "你确定要退出吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        # 如果用户点击了“是”,则执行event.accept()来关闭窗口
        #if reply == QMessageBox.Yes:
        #    event.accept()
        #    sys.exit(1)
        #else:
            # 如果用户点击了“否”,则忽略event,不关闭窗口
        #    event.ignore()
        sys.exit(1)

class Ui_Form(QWidget):
    #devicePath:设备路径名称、size:存储器大小、reads:速率、type:存储器类型、barand:品牌规格、testResult:测试结果、serial_Number:设备SN、power_Cycles:设备开关机次数
    #power_On_Hours:设备通电时间、temperature:设备温度,isSizePass:大小PASS,isBrandPass:品牌规格PASS,isReadsPass:速率PASS,
    def __init__(self,devicePath,size,reads,type,brand,serial_Number,fW,power_Cycles,power_On_Hours,temperature,isSizePass,isBrandPass):
        super().__init__()
        self.setWindowFlags(Qt.FramelessWindowHint)  # 设置窗口标志来隐藏标题栏
        self.setupUi()
        #设置参数
        self.lbl_Title.setText("【"+devicePath+" HDD Test】")
        self.lbl_Size.setText("硬盘容量:"+size+"G")
        if isSizePass==True:
            self.lbl_Size.setStyleSheet("color:green;")
        else:
            self.lbl_Size.setStyleSheet("color: red;")
        self.lbl_Barand.setText("品牌规格:"+brand)
        if isBrandPass==True:
            self.lbl_Barand.setStyleSheet("color:green;")
        else:
            self.lbl_Barand.setStyleSheet("color: red;")
        self.lbl_Rate.setText("读写速率:"+reads)
        self.lbl_Type.setText("设备类型:"+type)
        if isSizePass==True and isBrandPass==True:
            self.lbl_Result.setText('PASS')#测试结果PASS
            self.lbl_Result.setStyleSheet("color:green;")
        else:
            self.lbl_Result.setText('Fail') #测试结果PASS
            self.lbl_Result.setStyleSheet("color: red;")

        self.lbl_Serial_Number.setText("Serial Number: "+serial_Number)
        self.lbl_Firware_Version.setText("Firmware Version:"+fW)
        self.lbl_Power_Cycles.setText("Power Cycles:"+power_Cycles)
        self.lbl_Power_On_Hours.setText("Power On Hours:"+power_On_Hours+"H")
        self.lbl_Temperature.setText("Temperature:"+temperature+" Celsius")


    def setupUi(self):
        self.setObjectName("Form")
        self.resize(362, 210)
        self.gridLayout = QtWidgets.QGridLayout(self)
        self.gridLayout.setObjectName("gridLayout")
        self.lbl_Title = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(16)
        self.lbl_Title.setFont(font)
        self.lbl_Title.setStyleSheet("background-color: rgb(170, 170, 127);")
        self.lbl_Title.setAlignment(QtCore.Qt.AlignCenter)
        self.lbl_Title.setObjectName("lbl_Title")
        self.gridLayout.addWidget(self.lbl_Title, 0, 0, 1, 1)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label_2 = QtWidgets.QLabel(self)
        self.label_2.setText("")
        self.label_2.setPixmap(QtGui.QPixmap("IMAGE/SSD.png"))
        self.label_2.setAlignment(QtCore.Qt.AlignCenter)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout.addWidget(self.label_2)
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.lbl_Size = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.lbl_Size.setFont(font)
        self.lbl_Size.setObjectName("lbl_Size")
        self.verticalLayout_2.addWidget(self.lbl_Size)
        self.lbl_Barand = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.lbl_Barand.setFont(font)
        self.lbl_Barand.setObjectName("lbl_Barand")
        self.verticalLayout_2.addWidget(self.lbl_Barand)
        self.lbl_Rate = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.lbl_Rate.setFont(font)
        self.lbl_Rate.setObjectName("lbl_Rate")
        self.verticalLayout_2.addWidget(self.lbl_Rate)
        self.lbl_Type = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setPointSize(8)
        self.lbl_Type.setFont(font)
        self.lbl_Type.setObjectName("lbl_Type")
        self.verticalLayout_2.addWidget(self.lbl_Type)
        self.horizontalLayout.addLayout(self.verticalLayout_2)
        self.groupBox = QtWidgets.QGroupBox(self)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(10)
        self.groupBox.setFont(font)
        self.groupBox.setObjectName("groupBox")
        self.lbl_Result = QtWidgets.QLabel(self.groupBox)
        self.lbl_Result.setGeometry(QtCore.QRect(10, 19, 82, 36))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(12)
        self.lbl_Result.setFont(font)
        self.lbl_Result.setStyleSheet("background-color: rgb(0, 0, 0);\n""color: rgb(0, 255, 0);")
        self.lbl_Result.setAlignment(QtCore.Qt.AlignCenter)
        self.lbl_Result.setObjectName("lbl_Result")
        self.horizontalLayout.addWidget(self.groupBox)
        self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.label_7 = QtWidgets.QLabel(self)
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(12)
        self.label_7.setFont(font)
        self.label_7.setStyleSheet("background-color: rgb(0, 255, 127);")
        self.label_7.setAlignment(QtCore.Qt.AlignCenter)
        self.label_7.setObjectName("label_7")
        self.verticalLayout_3.addWidget(self.label_7)
        self.horizontalLayout_3.addLayout(self.verticalLayout_3)
        self.verticalLayout_5 = QtWidgets.QVBoxLayout()
        self.verticalLayout_5.setObjectName("verticalLayout_5")
        self.lbl_Serial_Number = QtWidgets.QLabel(self)
        self.lbl_Serial_Number.setObjectName("lbl_Serial_Number")
        self.verticalLayout_5.addWidget(self.lbl_Serial_Number)
        self.lbl_Firware_Version = QtWidgets.QLabel(self)
        self.lbl_Firware_Version.setObjectName("lbl_Firware_Version")
        self.verticalLayout_5.addWidget(self.lbl_Firware_Version)
        self.lbl_Power_Cycles = QtWidgets.QLabel(self)
        self.lbl_Power_Cycles.setObjectName("lbl_Power_Cycles")
        self.verticalLayout_5.addWidget(self.lbl_Power_Cycles)
        self.lbl_Power_On_Hours = QtWidgets.QLabel(self)
        self.lbl_Power_On_Hours.setObjectName("lbl_Power_On_Hours")
        self.verticalLayout_5.addWidget(self.lbl_Power_On_Hours)
        self.lbl_Temperature = QtWidgets.QLabel(self)
        self.lbl_Temperature.setObjectName("lbl_Temperature")
        self.verticalLayout_5.addWidget(self.lbl_Temperature)
        self.horizontalLayout_3.addLayout(self.verticalLayout_5)
        self.horizontalLayout_2.addLayout(self.horizontalLayout_3)
        self.gridLayout.addLayout(self.horizontalLayout_2, 2, 0, 1, 1)

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

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("Form", "HDD Array Test"))
        self.lbl_Title.setText(_translate("Form", "【/dev/sda HDD Test】"))
        self.lbl_Size.setText(_translate("Form", "硬盘容量:265G"))
        self.lbl_Barand.setText(_translate("Form", "品牌规格:BIWIN CE480Y2D100-256G"))
        self.lbl_Rate.setText(_translate("Form", "读写速率:280G/S"))
        self.lbl_Type.setText(_translate("Form", "设备类型:gpt"))
        self.groupBox.setTitle(_translate("Form", "【测试结果】"))
        self.lbl_Result.setText(_translate("Form", "PASS"))
        self.label_7.setText(_translate("Form", "其它信息"))
        self.lbl_Serial_Number.setText(_translate("Form", "Serial Number: 2325051516538"))
        self.lbl_Firware_Version.setText(_translate("Form", "Firmware Version:2325051516538"))
        self.lbl_Power_Cycles.setText(_translate("Form", "Power Cycles:140"))
        self.lbl_Power_On_Hours.setText(_translate("Form", "Power On Hours:140"))
        self.lbl_Temperature.setText(_translate("Form", "Temperature:44 Celsius"))


if __name__=='__main__':
    app=QApplication(sys.argv)
    win=Ui_HddTestMainFrm()
    win.Center()  # 居中
    win.show()
    sys.exit(app.exec_())

UI展示:

文章来源:https://blog.csdn.net/u013934107/article/details/135282154
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。