forked from nicolashainak/Laby_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimerDemo.py
More file actions
59 lines (47 loc) · 1.5 KB
/
timerDemo.py
File metadata and controls
59 lines (47 loc) · 1.5 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from threading import Timer,Thread,Event
class PerpetualTimer():
def __init__(self,fps,tick):
self.fps=fps
self.tick = tick
self.thread = None #Timer(self.t,self.handle_function)
self.isrunning=False
self.run()
def handle_function(self):
#controle du temps depart stop decider combien on attend ou non +s=cancel et restart
# //regarder si on peu chanegr la valeur dans pyton du timer
assert self.thread is not None
assert self.isrunning
self.tick()
self.thread.cancel()
self.thread = Timer(1/self.fps,self.handle_function)
self.thread.start()
def set_fps(self,fps):
#convertir fps en seconde
self.fps=fps
if self.isrunning:
self.cancel()
self.start()
def run(self):
if (self.isrunning):
return
self.thread = Timer(1/self.fps,self.handle_function)
self.thread.start()
self.isrunning=True
def running(self):
return self.isrunning
#peut etre enlever
def start(self):
if (self.isrunning):
return
self.thread = Timer(1/self.fps,self.handle_function)
self.thread.start()
self.isrunning=True
def cancel(self):
if self.isrunning:
self.thread.cancel()
self.thread=None
self.isrunning=False
def printer():
print ('ipsem lorem')
#t = perpetualTimer(5,printer)
#t.start()