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.3 KB
|
Line | |
---|
1 | class Phase:
|
---|
2 |
|
---|
3 | """
|
---|
4 |
|
---|
5 | This class is a representation of a single phase inside a timer
|
---|
6 |
|
---|
7 | """
|
---|
8 |
|
---|
9 | def __init__(self, title, duration):
|
---|
10 |
|
---|
11 | """
|
---|
12 |
|
---|
13 | creates the variables associated with that class
|
---|
14 |
|
---|
15 | :type title: string
|
---|
16 | :param title: Name of phase
|
---|
17 |
|
---|
18 | :type duration: int
|
---|
19 | :param duration: Duration in seconds
|
---|
20 |
|
---|
21 | """
|
---|
22 |
|
---|
23 | self.title = title
|
---|
24 | self.duration = duration
|
---|
25 | self.state = "initial"
|
---|
26 | self.time_left = self.duration
|
---|
27 |
|
---|
28 |
|
---|
29 | def __str__(self):
|
---|
30 |
|
---|
31 | """
|
---|
32 |
|
---|
33 | Human readable representation of all attributes
|
---|
34 |
|
---|
35 | :return: human readable representation of all attributes
|
---|
36 | :rtype: String
|
---|
37 |
|
---|
38 | """
|
---|
39 |
|
---|
40 | return ("-->" + self.title + "\nDuration=" +
|
---|
41 | str(self.duration) + "\n")
|
---|
42 |
|
---|
43 | def abort(self):
|
---|
44 | self.state = "finished"
|
---|
45 |
|
---|
46 | def start(self):
|
---|
47 | self.state = "running"
|
---|
48 |
|
---|
49 | def pause(self):
|
---|
50 | self.state = "paused"
|
---|
51 |
|
---|
52 | def running(self):
|
---|
53 | return self.state == "running"
|
---|
54 | # return self.time_left > 0
|
---|
55 |
|
---|
56 | def finished(self):
|
---|
57 | return self.state == "finished"
|
---|
58 |
|
---|
59 | def paused(self):
|
---|
60 | return self.state == "paused"
|
---|
61 |
|
---|
62 | def tick(self, duration):
|
---|
63 | self.time_left -= duration
|
---|
64 |
|
---|
65 | if self.time_left <= 0:
|
---|
66 | self.time_left = 0
|
---|
67 | self.state = "finished"
|
---|
Note:
See
TracBrowser
for help on using the repository browser.