source: flowtimer/scripts/Schedule.py@ 2bf0518

guix
Last change on this file since 2bf0518 was 99dee0f, checked in by Enrico Schwass <ennoausberlin@…>, 10 months ago

initial

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[99dee0f]1class Schedule:
2
3 def __init__(self, phase_list):
4 self.progressbar = None
5 self.currentValue = 0
6 self.phase_list = phase_list
7 self.current_phase = phase_list[0]
8 self.state = "initial"
9
10 def start(self):
11 self.state = "running"
12 self.current_phase.start()
13
14 def pause(self):
15 self.state = "paused"
16
17 def running(self):
18 return self.state == "running"
19
20 def is_paused(self):
21 return self.state == "paused"
22
23 def abort(self):
24 self.current_phase.abort()
25 self.state = "finished"
26
27 def finished(self):
28 if (self.current_phase.finished()) and (self.phase_list[-1] == self.current_phase):
29 self.state = "finished"
30 return True
31 else:
32 return False
33
34 def skip(self):
35 if self.current_phase_is_final():
36 self.abort()
37 else:
38 index = self.phase_list.index(self.current_phase)
39 self.current_phase = self.phase_list[index+1]
40
41 def current_phase_is_final(self):
42 index = self.phase_list.index(self.current_phase)
43 return index == (len(self.phase_list) - 1)
44
45 def tick(self, duration):
46 if not self.finished():
47 self.current_phase.tick(duration)
48 if self.current_phase.finished():
49 if self.current_phase_is_final():
50 self.abort()
51 else:
52 self.skip()
53 return True
Note: See TracBrowser for help on using the repository browser.