hxp
4 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#-*- coding: GBK -*-
#µ¹¼ÆÊ±Æ÷£¬¿ÉÒÔÉèÖõ¹¼ÆÊ±ÃëÊý£¬ÊÇ·ñĬÈÏ¿ªÊ¼£¬ÊÇ·ñÖØ¸´
# author: Alee
# Date: 2011.9.1
# history:  2011.9.1     Created
 
import time
 
class Timer(object):
    #sec£º¼ÆÊ±Æ÷µÄµ¹Êý¼ÆÊ±ÃëÊý
    #bStart£º³õʼÊÇ·ñÆô¶¯µ¹¼ÆÊ±
    #rep£º´Ë¼ÆÊ±Æ÷ÊÇ·ñÖØ¸´
    def __init__(self, sec, bStart = False, rep = False ):
        self.sec = sec
        self.bStart = bStart
        self.rep = rep
        if self.bStart:
            self.Start()
 
    def Start( self ):
        self.bStart = True
        self.starttime = time.time()
 
    def Stop( self ):
        self.bStart = False
 
    def _Process( self ):
        pass
 
    def Tick( self ):
        if not self.bStart:
            return
        if time.time() - self.starttime > self.sec:
            self._Process()
            if self.rep:
                self.Start()