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