# -*- coding: utf-8 -*-
import os

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets


class Ui_MainWindow(QtWidgets.QMainWindow):
    def setupUi(self):
        self.setObjectName("MainWindow")
        self.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")
        self.choose_file = QtWidgets.QPushButton(self.centralwidget)
        self.choose_file.setGeometry(QtCore.QRect(180, 20, 301, 81))
        self.choose_file.setObjectName("choose_file")
        self.choose_mutifile = QtWidgets.QPushButton(self.centralwidget)
        self.choose_mutifile.setGeometry(QtCore.QRect(180, 110, 301, 81))
        self.choose_mutifile.setObjectName("choose_mutifile")
        self.choose_dir = QtWidgets.QPushButton(self.centralwidget)
        self.choose_dir.setGeometry(QtCore.QRect(180, 200, 301, 91))
        self.choose_dir.setObjectName("choose_dir")
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(180, 300, 301, 91))
        self.pushButton_4.setObjectName("pushButton_4")
        self.menubar = QtWidgets.QMenuBar(self)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 30))
        self.menubar.setObjectName("menubar")
        self.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(self)
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)
        self.setCentralWidget(self.centralwidget)

        self.set_connect()

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

    def set_connect(self):
        self.choose_file.clicked.connect(self.slot_chooseFile)
        self.choose_mutifile.clicked.connect(self.slot_btn_chooseMutiFile)
        self.choose_dir.clicked.connect(self.slot_btn_chooseDir)
        self.pushButton_4.clicked.connect(self.slot_btn_saveFile)

    def slot_chooseFile(self):  # 槽函数
        fileName, fileType = QtWidgets.QFileDialog.getOpenFileName(self, "选取文件", os.getcwd(),
                                                                   "All Files(*);;Text Files(*.txt *.log)")
        print(fileName)
        print(fileType)

        if fileName_choose == "":
            print("\n取消选择")
            return

    def slot_btn_chooseMutiFile(self):
        files, filetype = QFileDialog.getOpenFileNames(self,
                                                       "多文件选择", os.getcwd(),
                                                       "All Files (*);;PDF Files (*.pdf);;Text Files (*.txt *.log)")

        if len(files) == 0:
            print("\n取消选择")
            return

        print("\n你选择的文件为:")
        for file in files:
            print(file)
        print("文件筛选器类型: ", filetype)

    def slot_btn_saveFile(self):
        fileName_choose, filetype = QFileDialog.getSaveFileName(self, "文件保存", os.getcwd(),
                                                                "All Files (*);;Text Files (*.txt)")

        if fileName_choose == "":
            print("\n取消选择")
            return

        print("\n你选择要保存的文件为:")
        print(fileName_choose)
        print("文件筛选器类型: ", filetype)

    def slot_btn_chooseDir(self):
        dir_choose = QFileDialog.getExistingDirectory(None, "选取文件夹", "")

        if dir_choose == "":
            print("\n取消选择")

        else:
            print("\n你选择的文件夹为:")
            print(dir_choose)

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.choose_file.setText(_translate("MainWindow", "选择文件"))
        self.choose_mutifile.setText(_translate("MainWindow", "选择多个文件"))
        self.choose_dir.setText(_translate("MainWindow", "选择目录"))
        self.pushButton_4.setText(_translate("MainWindow", "保存文件"))


if __name__ == "__main__":