-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleTimer.py
33 lines (27 loc) · 870 Bytes
/
simpleTimer.py
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
import time
class Timer():
def __init__(self):
self.lastTime = time.time()
self.isPaused = False
self.goPause = False
self.timePaused = 0.0
def getTimer(self):
returnTime = None
if self.isPaused:
if not self.goPause:
self.goPause = True
self.timePaused = time.time() - self.lastTime
returnTime = self.timePaused
else:
returnTime = self.timePaused
else:
returnTime = time.time() - self.lastTime
return returnTime
def pauseTimer(self):
self.isPaused = True
def resumeTimer(self):
if self.isPaused:
self.lastTime += (time.time() - self.lastTime) - self.timePaused
self.isPaused = False
def resetTimer(self):
self.lastTime = time.time()