zoukankan      html  css  js  c++  java
  • MyQThread

    # coding=utf-8
    from PyQt4.QtCore import *
    import Tkinter as tk
    import os
    import time
    
    class 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()
    
        def run(self):
            while self.working == True:
                file_str = 'File index {0}'.format(self.num)
                self.num += 1
                self.sleep(10)
                # print 'jianpan'
                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):
            # filename = r'music_delay.mp3'
            # mp3 = mp3play.load(filename)
            # mp3.play()
            # time.sleep(mp3.seconds())
            # print mp3.isplaying()
            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 e
    
    
    class 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()
    
    
    
  • 相关阅读:
    Windows7 如何添加excel,word到鼠标右键
    Java程序安装失败
    交换机
    Hbase
    Hive
    Hdoop
    PL/SQL连不上,报 ORA-12170:TNS 连接超时
    Error in invoking target 'mkldflags ntcontab.o nnfgt.o' of mkdefile '/u01/app/oracle/product/11.2.0
    用js 的for循环打印三角形,提取水仙花数,求本月多少天
    JS循环、数组与练习题
  • 原文地址:https://www.cnblogs.com/jian-pan/p/6934847.html
Copyright © 2011-2022 走看看