Pyside2在子线程中发射信号,主线程中做出响应

class UI_Combin_Docx(QThread):

    messbox_text = Signal(str, str)
    clear_text = Signal()

    def __init__(self):
        super().__init__()
        self.doc = conbin_Docx()

        # 存储选择的单个文件路径
        self.Single_filePath = list()
        # 实例化

        # 保证每次都是从相同的目录开始
        self.sel_root_path = "c:\\"

        # 创建主窗口
        self.creat_window()
        self.btn_select_file.clicked.connect(self.SelFile)
        self.btn_start_combin.clicked.connect(self.Startcombine)

        self.messagebox = QMessageBox(self.window)

        self.messbox_text.connect(self.showMessage)
        self.clear_text.connect(self.clear_Viewtext)
    
    # 这里的参数个数需要信号中的定义参数个数一致
    @Slot(str,str)
    def showMessage(self,title,text):
        self.FilaView.insertPlainText("Combine Complete\n")
        self.messagebox.information(
            self.window,
            title,
            text)

    # 需在主线程中清理界面文件信息,补课在子线程中清理
    @Slot()
    def clear_Viewtext(self):
        self.FilaView.clear()
    
        # 保存文件的操作
    def SaveFile(self,sel_filePath, SavefilePath):

        for file in sel_filePath:
            # self.FilaView.insertPlainText(file)
            # self.FilaView.insertPlainText("\n")
            self.doc.combine_docx(SavefilePath, file)

            if file == sel_filePath[-1]:
                self.messbox_text.emit('合并完成', '合并完成,文件保存在{0}'.format(SavefilePath))
                print("文件合并完毕")
                self.clear_text.emit()
                time.sleep(3)
    
    # 线程启动自动执行run
    def run(self):
        self.SaveFile(self.Single_filePath,self.TempPath)

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值