pyqt5 简单项目(优化版)

import sys
from PyQt5.QtCore import QProcess
from PyQt5.QtWidgets import QApplication,\
    QWidget,\
    QMessageBox,\
    QPushButton,\
    QHBoxLayout,\
    QVBoxLayout,\
    QLineEdit,\
    QTextEdit

class QtApp:

    def __init__(self):
        super().__init__()

        self.window=QWidget()
        self.hlayout=QHBoxLayout()
        self.vlayout=QVBoxLayout()
        self.process=QProcess()

        self.process.readyReadStandardOutput.connect(self.read)

    def read(self):
        output = self.process.readAllStandardOutput().data().decode()
        return output

class MainApp(QtApp):

    def __init__(self):
        super().__init__()
        self.window.setWindowTitle("生产实习")
        self.window.resize(500, 500)
        self.window.setLayout(self.vlayout)

        self.button1=QPushButton(self.window)
        self.button1.setText("训练")
        self.button1.clicked.connect(self.inface)

        self.button2=QPushButton(self.window)
        self.button2.setText("识别")
        self.button2.clicked.connect(self.is_my_face)

        self.text1=QTextEdit(self.window)
        self.text1.setPlaceholderText("控制台输出")

        self.hlayout.addWidget(self.button1)
        self.hlayout.addWidget(self.button2)
        self.vlayout.addLayout(self.hlayout)
        self.vlayout.addWidget(self.text1)

    def inface(self):
        self.atest = ATest()
        self.atest.window.show()

    def is_my_face(self):
        self.process.start("python3 is_my_face.py")
        QMessageBox.about(self.window, "结果", "识别结束")

    def test(self):
        self.process.start("python jiemian.py")

    def read(self):
        output=super().read()
        self.text1.append(output)

class ATest(QtApp):

    def __init__(self):
        super().__init__()
        self.window.setWindowTitle("训练模块")
        self.window.resize(500,500)
        self.window.setLayout(self.hlayout)

        self.button1=QPushButton(self.window)
        self.button1.setText("录入人脸")
        self.button1.clicked.connect(self.get_my_faces)

        self.button2=QPushButton(self.window)
        self.button2.setText("训练网络")
        self.button2.clicked.connect(self.train_faces)

        self.button3=QPushButton(self.window)
        self.button3.setText("录入其他人脸")
        self.button3.clicked.connect(self.set_other_faces)

        self.hlayout.addWidget(self.button1)
        self.hlayout.addWidget(self.button2)
        self.hlayout.addWidget(self.button3)

    def get_my_faces(self):
        self.face=Face()
        self.face.window.show()

    def set_other_faces(self):
        self.oface=OFace()
        self.oface.window.show()

    def train_faces(self):
        self.trains=Train()
        self.trains.window.show()

class Face(QtApp):

    def __init__(self):
        super().__init__()
        self.window.setWindowTitle("人脸录入模块")
        self.window.setLayout(self.vlayout)
        self.window.resize(300,300)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("录入数量(默认为30张)")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.faces)

        self.text2=QTextEdit(self.window)
        self.text2.setPlaceholderText("控制台输出")

        self.hlayout.addWidget(self.text1)
        self.hlayout.addWidget(self.button1)

        self.vlayout.addLayout(self.hlayout)
        self.vlayout.addWidget(self.text2)

    def faces(self):
        command="python3 get_my_faces.py"
        if self.text1.text():
            command+=" --n "+self.text1.text()
        self.process.start(command)
        QMessageBox.about(self.window, "结果", "录入结束")

    def read(self):
        output=super().read()
        self.text2.append(output)

class OFace(QtApp):

    def __init__(self):
        super().__init__()
        self.window.setWindowTitle("人脸录入模块")
        self.window.setLayout(self.vlayout)
        self.window.resize(300,300)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("录入数量(默认为30张)")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.faces)

        self.text2=QTextEdit(self.window)
        self.text2.setPlaceholderText("控制台输出")

        self.hlayout.addWidget(self.text1)
        self.hlayout.addWidget(self.button1)

        self.vlayout.addLayout(self.hlayout)
        self.vlayout.addWidget(self.text2)

    def faces(self):
        command="python3 set_other_faces.py"
        if self.text1.text():
            command+=" --n "+self.text1.text()
        self.process.start(command)
        QMessageBox.about(self.window, "结果", "录入结束")

    def read(self):
        output=super().read()
        self.text2.append(output)

class Train(QtApp):

    def __init__(self):
        super().__init__()
        self.window.setWindowTitle("参数设置模块")
        self.window.resize(350,200)
        self.window.setLayout(self.vlayout)

        self.text1=QLineEdit(self.window)
        self.text1.setPlaceholderText("设置batch_size,默认为3")

        self.text2=QLineEdit(self.window)
        self.text2.setPlaceholderText("模型准确度,默认为0.3")

        self.text3=QLineEdit(self.window)
        self.text3.setPlaceholderText("最少模型训练次数,总次数为10,默认为3")

        self.text4=QTextEdit(self.window)
        self.text4.setPlaceholderText("控制台输出")

        self.button1=QPushButton(self.window)
        self.button1.setText("确认")
        self.button1.clicked.connect(self.train)

        self.vlayout.addWidget(self.text1)
        self.vlayout.addWidget(self.text2)
        self.vlayout.addWidget(self.text3)
        self.vlayout.addWidget(self.button1)
        self.vlayout.addWidget(self.text4)

    def train(self):
        command="python3 train_faces.py"
        if self.text1.text():
            command+=" --b "+self.text1.text()

        if self.text2.text():
            command += " --a " + self.text2.text()

        if self.text3.text():
            command += " --c " + self.text3.text()

        self.process.start(command)
        QMessageBox.about(self.window, "结果", "训练结束")

    def read(self):
        output=super().read()
        self.text4.append(output)

if __name__=="__main__":
    app=QApplication(sys.argv)

    maap=MainApp()
    maap.window.show()

    sys.exit(app.exec_())
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值