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

# Form implementation generated from reading ui file 'video6.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.

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtCore import Qt
import time
from agency.crawl import main

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(300, 20, 200, 30))
        font = QtGui.QFont()
        font.setFamily("黑体")
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(100, 100, 100, 15))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(200, 100, 500, 20))
        self.lineEdit.setObjectName("lineEdit")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setEnabled(True)
        self.pushButton.setGeometry(QtCore.QRect(200, 200, 100, 30))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(600, 200, 100, 30))
        self.pushButton_2.setObjectName("pushButton_2")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(100, 150, 100, 15))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(200, 150, 500, 20))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(200, 60, 400, 20))
        font = QtGui.QFont()
        font.setFamily("arial")
        font.setPointSize(10)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(100, 60, 100, 20))
        font = QtGui.QFont()
        font.setFamily("黑体")
        font.setPointSize(10)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.pushButton_2.clicked.connect(self.lineEdit.clear)
        self.pushButton.clicked.connect(self.pushButton.hide)
        self.pushButton_2.clicked.connect(self.pushButton.show)
        self.pushButton.clicked.connect(self.slot1)
        self.pushButton_2.clicked.connect(self.slot2)
        self.pushButton.clicked.connect(send.run)
        self.pushButton_2.clicked.connect(self.lineEdit_2.clear)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "我的应用"))
        self.label.setText(_translate("MainWindow", "       爬取樱花AV"))
        self.label_2.setText(_translate("MainWindow", "请输入url："))
        self.lineEdit.setPlaceholderText(_translate("MainWindow", "https://yinghuaav.site/vodtype/27.html"))
        self.pushButton.setText(_translate("MainWindow", "执行"))
        self.pushButton_2.setText(_translate("MainWindow", "重构"))
        self.label_3.setText(_translate("MainWindow", "请输入个数："))
        self.lineEdit_2.setPlaceholderText(_translate("MainWindow", "一页24个视频大约3小时下载一页"))
        self.label_4.setText(_translate("MainWindow", "https://yinghuaav.run/vodtype/31.html"))
        self.label_4.setTextInteractionFlags(Qt.TextSelectableByMouse)#设置可复制
        self.label_5.setText(_translate("MainWindow", "复制网站 ："))

    def slot1(self, MainWindow):
        print('正在执行')
        self.label_5.setText("正在爬取")
        self.label_4.setText("请稍后.....")
        # print(self.pushButton.isVisible())
        # time.sleep(1)
        self.pushButton.hide()#隐藏
        # print(self.pushButton.isVisible())
        #main(self.lineEdit.text(),self.lineEdit_2.text())#获取输入·框的值self.lineEdit.text()
        main(self.lineEdit.text(),10)#获取输入·框的值self.lineEdit.text()
        # time.sleep(5)
        # self.pushButton.show()     #显示
        print(self.pushButton.isVisible())
        print('执行完成')

    def slot2(self, MainWindow):
        self.label_5.setText("复制网站：")
        self.label_4.setText("https://yinghuaav.run/vodtype/31.html")

# 信号对象
class QTypeSignal(QObject):
    # 定义一个信号
    sendmsg = pyqtSignal(object)

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

    def run(self):
        # 发射信号
        self.sendmsg.emit('Hello Pyqt5')

# 槽对象
class QTypeSlot(QObject):
    def __init__(self):
        super(QTypeSlot, self).__init__()
        # 槽对象里的槽函数

    def get(self, msg):
        print("QSlot get msg => " + msg)
        #main(url='https://yinghuaav.site/vodtype/27-%s.html')


import sys  #导入系统模块

def show_MainWindow():
    app = QtWidgets.QApplication(sys.argv)         #实例化QApplication类，作为GUI主程序入口
    MainWindow=QtWidgets.QMainWindow()             #创建MainWindow
    ui=Ui_MainWindow()                             #实例化ui类
    ui.setupUi(MainWindow)                         #设置窗口UI
    MainWindow.show()                              #显示窗口
    sys.exit(app.exec_())                          #当窗口创建完成时，需要结束主循环过程


if __name__=="__main__":
    send = QTypeSignal()
    slot = QTypeSlot()
    # 1
    print('--- 把信号绑定到槽函数 ---')
    send.sendmsg.connect(slot.get)
    show_MainWindow()