博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MyQThread new
阅读量:6990 次
发布时间:2019-06-27

本文共 4144 字,大约阅读时间需要 13 分钟。

#!/usr/bin/env python# -*- coding: utf-8 -*-"""@version: 001@author: jianpan@file: MyQThread.py@time: 2017/6/3 11:54"""from PyQt4.QtCore import *import Tkinter as tkimport multiprocessingimport osimport psutilclass MyQThread(QThread):    def __init__(self, parent=None):        super(MyQThread, self).__init__(parent)        self.working = True        self.num = 0    def __del__(self):        self.working = False        self.wait()        self.pid = 0    def run(self):        pass    def open(self):        try:            os.popen('taskkill /pid %s  -f' % (str(self.pid)))        except Exception, e:            print e        pool = multiprocessing.Pool(processes=1)        print os.getpid()        for i in xrange(1):            pool.apply_async(func,)  # 维持执行的进程总数为processes,当一个进程执行完毕后会添加新的进程进去        t = psutil.Process()        print "Process :", t.pid        pool.close()        children = t.children()        for child in children:            print('Child pid is {}'.format(child.pid))            self.pid = child.pid        # pool.join()  # 调用join之前,先调用close函数,否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束        print "Sub-process(es) done."def func():    root = WarningTK()class MyQThreadSleep60(QThread):    def __init__(self, parent=None):        super(MyQThreadSleep60, self).__init__(parent)        self.working = True        self.num = 0    def __del__(self):        self.working = False        self.wait()    def run(self):        while self.working == True:            file_str = 'File index {0}'.format(self.num)            self.num += 1            self.sleep(10)            self.emit(SIGNAL('output(QString)'), file_str)class MyQThread_30(QThread):    def __init__(self, parent=None):        super(MyQThread_30, self).__init__(parent)        self.working = True        self.num = 0    def __del__(self):        self.working = False        self.wait()    def run(self):        while self.working == True:            file_str = 'File index {0}'.format(self.num)            self.num += 1            self.sleep(20)            self.emit(SIGNAL('output(QString)'), file_str)class MyQThreadDelay(QThread):    def __init__(self, parent=None):        super(MyQThreadDelay, self).__init__(parent)        self.working = True        self.num = 0    def run(self):        os.popen('warning.mp3')        print 'finish'class MyQThread_Warning(QThread):    def __init__(self, parent=None):        super(MyQThread_Warning, self).__init__(parent)        self.working = True        self.num = 0    def run(self):        print '1'    def open(self):        self.root = WarningTK()        self.root.mainloop()    def getDlg(self):        return self.root.destroy    def close(self):        try:            self.root.quit()            self.root.destroy()        except Exception, e:            print eclass WarningTK(tk.Tk):    def __init__(self, master=None):        tk.Tk.__init__(self, master)        self.title('test')        self.withdraw()        screenwidth = self.winfo_screenwidth()        screenheight = self.winfo_screenheight() - 100        self.resizable(False, False)        # 添加组件        self.title("Warning!!")        frame = tk.Frame(self, relief=tk.RIDGE, borderwidth=3)        frame.pack(fill=tk.BOTH, expand=1)  # pack() 放置组件若没有则组件不会显示        # 窗口显示的文字、并设置字体、字号        label = tk.Label(frame, text="You have been working 30 minutes! Please have a break!!", \                         font="Monotype\ Corsiva -20 bold")        label.pack(fill=tk.BOTH, expand=1)        # 按钮的设置        self.button1 = tk.Button(frame, text="OK", font="Cooper -25 bold", fg="red", command=self.destroy)        self.button1.pack(side=tk.BOTTOM)        self.update_idletasks()        self.deiconify()  # now the window size was calculated        self.withdraw()  # hide the window again 防止窗口出现被拖动的感觉 具体原理未知?        self.geometry(            '%sx%s+%s+%s' % (self.winfo_width() + 10, self.winfo_height() + 10,                             (screenwidth - self.winfo_width()) / 2,                             (screenheight - self.winfo_height()) / 2))        self.deiconify()        self.mainloop()

转载于:https://www.cnblogs.com/jian-pan/p/6941246.html

你可能感兴趣的文章
PPP中的PAP和CHAP的区别
查看>>
基于CentOS5.5的SVN服务器搭建
查看>>
maven使用笔记
查看>>
JBoss配置使项目能在局域网其他机子上访问项目
查看>>
VIO概述 On-Manifold Preintegration for Real-Time Visual--Inertial Odometry
查看>>
CocoaPods升级安装三方库报错
查看>>
SpringBoot整合RabbitMQ实现微服务间的异步消息沟通
查看>>
pku1338 Ugly Numbers
查看>>
程序算法与人生选择 分类: 转载收藏 2013...
查看>>
牛客网校招全国统一模拟笔试(三月场)- Java方向
查看>>
Apache主站点配置
查看>>
[转]蓝牙开发
查看>>
C语言程序举例
查看>>
$.param()的实例应用
查看>>
web安全:xss && csrf
查看>>
数据保存(永久保存)方式
查看>>
POJ 3320 尺取法(基础题)
查看>>
如何使表格中的文字不换行?多出的字用“..."代替
查看>>
c# 进程间通信
查看>>
Word Ladder
查看>>