继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

python pyqt5画面实现

lovingseapeak
关注TA
已关注
手记 3
粉丝 0
获赞 1

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


# Form implementation generated from reading ui file 'e:\NDC借調処理\python\src\StyleLayout.ui'

#

# Created by: PyQt5 UI code generator 5.13.0

#

# WARNING! All changes made in this file will be lost!



import sys

import os

import images_rc

import xlrd

import win32com.client

import time


from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5.QtCore import *

from PyQt5.QtGui import *

from PyQt5.QtWidgets import *

from CalculateSalary import CalculateSalary



class Ui_Management(object):

  

    def setupUi(self, Management):


        icon = QtGui.QIcon()

        icon.addPixmap(QtGui.QPixmap(":/img/logo.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)


        Management.setObjectName("Management")

        Management.resize(579, 593)

        Management.setStyleSheet("background-image: url(:/img/img.jpg);")

        Management.setWindowIcon(icon)


        # 窗口垂直设计,画面控件随窗口变化而变化(自适应)

        self.verticalLayout_3 = QtWidgets.QVBoxLayout(Management)

        self.verticalLayout_3.setObjectName("verticalLayout_3")

        

        # 文件处理层

        self.groupBox1 = QtWidgets.QGroupBox(Management)

        font = QtGui.QFont()

        font.setPointSize(16)

        font.setBold(True)

        font.setItalic(True)

        font.setWeight(75)

        self.groupBox1.setFont(font)

        self.groupBox1.setStyleSheet("color: rgb(85, 170, 255);")

        self.groupBox1.setObjectName("groupBox1")

        self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox1)

        self.verticalLayout.setContentsMargins(-1, -1, -1, 9)

        self.verticalLayout.setSpacing(6)

        self.verticalLayout.setObjectName("verticalLayout")

        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()

        self.horizontalLayout_3.setObjectName("horizontalLayout_3")


        # 选择目标文件路径

        self.folderSourceLabel = QtWidgets.QLabel(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.folderSourceLabel.setFont(font)

        self.folderSourceLabel.setStyleSheet("color: rgb(0, 0, 0);")

        self.folderSourceLabel.setObjectName("folderSourceLabel")

        self.horizontalLayout_3.addWidget(self.folderSourceLabel)


        # 在文本框显示文件夹路径内容

        self.pathEdit = QtWidgets.QLineEdit(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.pathEdit.setFont(font)

        self.pathEdit.setStyleSheet("background-color: rgb(255, 255, 255);""color: rgb(0, 0, 0);")

        self.pathEdit.setObjectName("pathEdit")

        self.horizontalLayout_3.addWidget(self.pathEdit)


        # 浏览按钮

        self.searchButton = QtWidgets.QPushButton(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.searchButton.setFont(font)

        self.searchButton.setStyleSheet("color: rgb(200, 97, 84);")

        self.searchButton.setCheckable(False)

        self.searchButton.setAutoRepeat(False)

        self.searchButton.setAutoExclusive(False)

        self.searchButton.setFlat(False)

        self.searchButton.setObjectName("searchButton")

        self.horizontalLayout_3.addWidget(self.searchButton)

        self.horizontalLayout_3.setStretch(0, 1)

        self.horizontalLayout_3.setStretch(1, 5)

        self.horizontalLayout_3.setStretch(2, 1)

        self.verticalLayout.addLayout(self.horizontalLayout_3)

        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()

        self.horizontalLayout_2.setObjectName("horizontalLayout_2")


        # 按下浏览按钮

        self.searchButton.clicked.connect(self.searchButtonClick)


        # 选择年月label

        self.selectYearMonthLabel = QtWidgets.QLabel(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.selectYearMonthLabel.setFont(font)

        self.selectYearMonthLabel.setStyleSheet("color: rgb(0, 0, 0);")

        self.selectYearMonthLabel.setObjectName("selectYearMonthLabel")

        self.horizontalLayout_2.addWidget(self.selectYearMonthLabel)


        # 显示日期edit

        self.yearMonthEdit = QtWidgets.QDateEdit(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.yearMonthEdit.setFont(font)

        self.yearMonthEdit.setStyleSheet("color: rgb(0, 0, 0);")

        self.yearMonthEdit.setCalendarPopup(True)

        self.yearMonthEdit.setObjectName("yearMonthEdit")

        self.yearMonthEdit.setDateTime(QDateTime.currentDateTime())

        self.horizontalLayout_2.addWidget(self.yearMonthEdit)

        self.horizontalLayout_2.setStretch(0, 1)

        self.horizontalLayout_2.setStretch(1, 6)

        self.verticalLayout.addLayout(self.horizontalLayout_2)

        self.horizontalLayout = QtWidgets.QHBoxLayout()

        self.horizontalLayout.setObjectName("horizontalLayout")


        # 处理类别label

        self.dealWithKindLabel = QtWidgets.QLabel(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.dealWithKindLabel.setFont(font)

        self.dealWithKindLabel.setStyleSheet("color: rgb(0, 0, 0);")

        self.dealWithKindLabel.setObjectName("dealWithKindLabel")

        self.horizontalLayout.addWidget(self.dealWithKindLabel)


        # 施策费前CheckBox

        self.shiCeBefore = QtWidgets.QCheckBox(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.shiCeBefore.setFont(font)

        self.shiCeBefore.setStyleSheet("color: rgb(0, 0, 0);")

        self.shiCeBefore.setObjectName("shiCeBefore")

        self.horizontalLayout.addWidget(self.shiCeBefore)


        # 施策费后CheckBox

        self.shiCeLater = QtWidgets.QCheckBox(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.shiCeLater.setFont(font)

        self.shiCeLater.setStyleSheet("color: rgb(0, 0, 0);")

        self.shiCeLater.setObjectName("shiCeLater")

        self.horizontalLayout.addWidget(self.shiCeLater)


        # 其它情况CheckBox

        self.other = QtWidgets.QCheckBox(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.other.setFont(font)

        self.other.setStyleSheet("color: rgb(0, 0, 0);")

        self.other.setObjectName("other")

        self.horizontalLayout.addWidget(self.other)

        self.horizontalLayout.setStretch(0, 1)

        self.horizontalLayout.setStretch(1, 2)

        self.horizontalLayout.setStretch(2, 2)

        self.horizontalLayout.setStretch(3, 2)

        self.verticalLayout.addLayout(self.horizontalLayout)


        # 开始处理按钮

        self.startButton = QtWidgets.QPushButton(self.groupBox1)

        font = QtGui.QFont()

        font.setPointSize(12)

        self.startButton.setFont(font)

        # "background-color: rgb(67, 211, 255);\n""border:3px solid #5f92b2;\n""border-radius:5px;\n"

        self.startButton.setStyleSheet("color: rgb(200, 97, 84);")

        self.startButton.setCheckable(False)

        self.startButton.setAutoRepeat(False)

        self.startButton.setAutoExclusive(False)

        self.startButton.setFlat(False)

        self.startButton.setObjectName("startButton")

        self.verticalLayout.addWidget(self.startButton)

        self.verticalLayout_3.addWidget(self.groupBox1)


        


        # 按下开始处理按钮

        self.startButton.clicked.connect(self.startButtonClick)

        

        # 处理结果层

        self.groupBox2 = QtWidgets.QGroupBox(Management)

        font = QtGui.QFont()

        font.setPointSize(16)

        font.setBold(True)

        font.setItalic(True)

        font.setUnderline(False)

        font.setWeight(75)

        font.setStrikeOut(False)

        self.groupBox2.setFont(font)

        self.groupBox2.setStyleSheet("color: rgb(85, 170, 255);")

        self.groupBox2.setObjectName("groupBox2")

        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox2)

        self.verticalLayout_2.setObjectName("verticalLayout_2")


        # 显示具体处理后的详细信息tablewidget

        self.resultMessage = QtWidgets.QTableWidget(self.groupBox2)

        font = QtGui.QFont()

        font.setPointSize(12)

        font.setBold(False)

        font.setItalic(False)

        font.setWeight(50)

        self.resultMessage.setFont(font)

        self.resultMessage.setTabletTracking(False)

        self.resultMessage.setAcceptDrops(False)

        self.resultMessage.setToolTip("")

        self.resultMessage.setStatusTip("")

        self.resultMessage.setAutoFillBackground(False)

        self.resultMessage.setStyleSheet("color: rgb(112, 189, 255);")

        self.resultMessage.setInputMethodHints(QtCore.Qt.ImhNone)

        self.resultMessage.setLineWidth(1)

        self.resultMessage.setAutoScroll(True)

        self.resultMessage.setProperty("showDropIndicator", True)

        self.resultMessage.setDragEnabled(False)

        self.resultMessage.setAlternatingRowColors(True)

        self.resultMessage.setShowGrid(True)

        self.resultMessage.setWordWrap(True)

        self.resultMessage.setCornerButtonEnabled(True)

        self.resultMessage.setRowCount(2)

        self.resultMessage.setColumnCount(2)

        self.resultMessage.setObjectName("resultMessage")

        self.resultMessage.horizontalHeader().setVisible(True)

        self.resultMessage.horizontalHeader().setCascadingSectionResizes(False)

        self.resultMessage.horizontalHeader().setDefaultSectionSize(100)

        self.resultMessage.horizontalHeader().setHighlightSections(True)

        self.resultMessage.horizontalHeader().setMinimumSectionSize(34)

        self.resultMessage.horizontalHeader().setSortIndicatorShown(False)

        self.resultMessage.horizontalHeader().setStretchLastSection(True)

        self.resultMessage.verticalHeader().setVisible(True)

        self.resultMessage.verticalHeader().setCascadingSectionResizes(False)

        self.resultMessage.verticalHeader().setDefaultSectionSize(30)

        self.resultMessage.verticalHeader().setHighlightSections(False)

        self.resultMessage.verticalHeader().setSortIndicatorShown(False)

        self.resultMessage.verticalHeader().setStretchLastSection(False)

        # 不可编辑

        self.resultMessage.setEditTriggers(QTableView.NoEditTriggers)

        self.verticalLayout_2.addWidget(self.resultMessage)

        self.verticalLayout_3.addWidget(self.groupBox2)


        # 开始处理加载label

        self.label = QtWidgets.QLabel(Management)

        # self.label.setScaledContents(True)

        

        self.label.setGeometry(QtCore.QRect(250,150,40,40))


        self.label.setObjectName("label")

        self.label.hide()



        self.retranslateUi(Management)

        QtCore.QMetaObject.connectSlotsByName(Management)


    def retranslateUi(self, Management):

        _translate = QtCore.QCoreApplication.translate

        Management.setWindowTitle(_translate("Management", "NCIT人事管理工具"))


        self.groupBox1.setTitle(_translate("Management", "文件处理"))

        self.folderSourceLabel.setText(_translate("Management", "请选择目标路径"))

        self.searchButton.setText(_translate("Management", "浏览"))


        self.selectYearMonthLabel.setText(_translate("Management", "请选择年月"))

        self.yearMonthEdit.setDisplayFormat(_translate("Management", "yyyy/MM"))


        self.dealWithKindLabel.setText(_translate("Management", "处理类别"))

        self.shiCeBefore.setText(_translate("Management", "施策费前"))

        self.shiCeLater.setText(_translate("Management", "施策费后"))

        self.other.setText(_translate("Management", "其它"))


        self.startButton.setText(_translate("Management", "开始处理"))


        self.groupBox2.setTitle(_translate("Management", "处理结果"))

        self.resultMessage.setSortingEnabled(False)


        # self.frame1 = QFrame(self)

        # self.verticalLayout = QVBoxLayout(self.frame1)

        # self.pushButton_quit = QPushButton()

        # self.pushButton_quit.setText("回到主页面")

        # self.verticalLayout.addWidget(self.pushButton_quit)

        # self.frame1.setVisible(False)

        # self.startButton.clicked.connect(self.on_pushButton_enter_clicked)

        # self.pushButton_quit.clicked.connect(self.on_pushButton_enter_clicked_1)

        # self.tipwin  = None




    # 按下浏览按钮事件

    def searchButtonClick(self):


        folderPath = QFileDialog.getExistingDirectory(None, "选择文件夹路径", "C:\\")

        self.pathEdit.setText(folderPath)


    # 处理文件按钮事件

    def startButtonClick(self):

        # 获取时间并转换成string型

        dateTime = self.yearMonthEdit.date().toString(Qt.ISODate)

        # 获取路经并转换成string型

        pathString = self.pathEdit.displayText()

        # checkbox的选择状态,并转换成bool(布尔)型

        # 施策费前

        checkFlg_Before = bool(self.shiCeBefore.checkState())

        # 施策费后

        checkFlg_Later = bool(self.shiCeLater.checkState())

        # 其它

        checkFlg_other = bool(self.other.checkState())


       

        self.label.show()

        

        self.gif = QMovie(":/img/down2.gif")

        

        # self.label.setScaledContents(True)

        self.label.setMovie(self.gif)

        self.label.setStyleSheet("background-color:white;")

        self.gif.start()




        # 创建文件处理(计算薪资)实例化

        makeSalary = CalculateSalary(pathString,dateTime)

        # 为用户提供处理过程中的提示信息

        # splash = QtWidgets.QSplashScreen(QtGui.QPixmap(":/img/downloadprocess.png"))

        

        if(checkFlg_Before == True and checkFlg_Later == False and checkFlg_other== False):

            # 为用户提供处理过程中的提示信息并显示


        


        

            






            # splash.show()

            # splash.showMessage("文件正在处理中...", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)

            # time.sleep(5)

            # 调用计算薪资类的makeSalaryInfo()方法

            makeSalary.makeSalaryInfo()

            # 处理结束信息提示

            # QtWidgets.QMessageBox.information(None, "提示", "文件处理成功")

            QtWidgets.QMessageBox.information(None, "提示", makeSalary.result_message)

            

            

            

            # 横向标题排列,如果使用setVerticalHeaderLabels则是纵向排列标题

            self.resultMessage.setHorizontalHeaderLabels(['文件名','操作']) 

            x = r"E:\NDC借調処理\10月\01_input\BJ_工资分配201910_借调.xlsx"

            y = r"D:\备份\Book2.xlsx"

            # items=[[x, ""], [y, ""]]

            items=[[x, ""]]

            items.append([y, ""])

            # 注意上面列表中数字加单引号,否则下面不显示(或者下面str方法转化一下即可)

            for i in range(len(items)):

                item=items[i]


                for j in range(len(item)):

                    # 添加按钮

                    if  j!=1:

                        item = QTableWidgetItem(str(items[i][j]))

                        self.resultMessage.setItem(i, j, item)

                    #最后一列添加控件

                    else: 

                        btn = QPushButton("查看文件")

                        btn.setDown(True)

                        # btn.setStyleSheet("QPushButton{margin:3px};")

                        btn.setStyleSheet("border:3px solid #5f92b2;""color: rgb(200, 97, 84);")

                        

                        self.resultMessage.setCellWidget(i, j, btn)

                        btn.clicked.connect(self.showFileContentBtnClick)

            # QTableWidget读取数据写死

            # self.model = QStandardItemModel()

            # self.model.setHorizontalHeaderLabels(["文件名","操作"])

            # for row in range(100):

            #     for column in range(2):

            #         item = QStandardItem("row %s ,column %s"%(row, column))

                    

            #         self.model.setItem(row, column, item)

            # self.DetailContent.setModel(self.model)

        elif(checkFlg_Later == True and checkFlg_Before == False and checkFlg_other == False ):

            QtWidgets.QMessageBox.information(None, "提示", "施策费后" + makeSalary.result_message)


        elif(checkFlg_other == True and checkFlg_Before == False and checkFlg_Later == False):

            QtWidgets.QMessageBox.information(None, "提示", "其它情况" + makeSalary.result_message)


        elif((checkFlg_Before == True and checkFlg_Later == True) or 

        (checkFlg_Before == True and checkFlg_other == True) or 

        (checkFlg_Later == True and checkFlg_other == True) or 

        (checkFlg_Before == True and checkFlg_Later == True and checkFlg_other == True)):

            

            QtWidgets.QMessageBox.information(None, "提示", "全选")


        else:

            

            QtWidgets.QMessageBox.warning(None, "警告", "请选择处理类别")

        self.label.hide()

            


    # 打开文件,查看文件内容

    def showFileContentBtnClick(self):

        # filename = QFileDialog.getOpenFileName(None, "open", r"D:\备份\Book2.xlsx")

        # print (filename[0])

        # os.startfile(filename[0])

        try:

            # 打开没有密码的excel文件

            path = r"D:\备份\Book2.xlsx"

            os.startfile(path)

        except:

            # 打开带有密码的Excel文件

            xlApp = win32com.client.Dispatch("Excel.Application")

            path = r"E:\NDC借調処理\10月\01_input\BJ_工资分配201910_借调.xlsx"

            password = "FP201910"

            xlwb = xlApp.Workbooks.Open(path, 2, True, None, None, password)

            xlwb = xlApp.Workbooks.Open(path)


    


if __name__ == "__main__":


    app = QtWidgets.QApplication(sys.argv)

    widget = QtWidgets.QWidget()

    ui = Ui_Management()

    ui.setupUi(widget)

    widget.show()

    sys.exit(app.exec_())



打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP