-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
118 lines (95 loc) · 4.23 KB
/
main.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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from tokenize import group
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.graphics import Color, Line
from plans import Plan, Run
class RunPlanButton(Button):
pass
class RunBodyLayout(BoxLayout):
state_lbl = ObjectProperty(None)
run_lbl = ObjectProperty(None)
timer_lbl = ObjectProperty(None)
run_lst = ObjectProperty(None)
plan: Plan = None
def action_start(self):
self.plan.begin_workout()
self.plan.state_change_callback = self.update_state_label
self.plan.clock_event = Clock.schedule_interval(self.plan.update_state, 1)
def update_state_label(self, state, state_time):
minutes, seconds = divmod(int(state_time), 60)
self.state_lbl.text = f"{self.plan.name} {state.name}"
self.run_lbl.text = f"{len(self.plan)} runs left"
self.timer_lbl.text = f"{minutes:02}:{seconds:02}"
class RunBodyApp(App):
def build(self):
run_body = RunBodyLayout()
# Week 1
self.create_plan("W1D1", [Run(60, 90)] * 8, run_body)
self.create_plan("W1D2", [Run(60, 90)] * 8, run_body)
self.create_plan("W1D2", [Run(60, 90)] * 8, run_body)
# Week 2
self.create_plan("W2D1", [Run(90, 120)] * 6, run_body)
self.create_plan("W2D2", [Run(90, 120)] * 6, run_body)
self.create_plan("W2D3", [Run(90, 120)] * 6, run_body)
# Week 3
self.create_plan("W3D1", [Run(120, 120)] * 6, run_body)
self.create_plan("W3D2", [Run(120, 120)] * 6, run_body)
self.create_plan("W3D3", [Run(120, 120)] * 6, run_body)
# Week 4
self.create_plan("W4D1", [Run(180, 90)] * 5, run_body)
self.create_plan("W4D2", [Run(180, 90)] * 5, run_body)
self.create_plan("W4D3", [Run(180, 90)] * 5, run_body)
# Week 5
self.create_plan("W5D1", [Run(300, 180)] * 3, run_body)
self.create_plan("W5D2", [Run(480, 300)] * 2, run_body)
self.create_plan("W5D3", [Run(1200, 0)], run_body)
# Week 6
self.create_plan(
"W6D1", [Run(300, 180)] + [Run(480, 180)] + [Run(300, 180)], run_body
)
self.create_plan("W6D2", [Run(600, 180)] * 2, run_body)
self.create_plan("W6D3", [Run(1500, 0)], run_body)
# Week 7
self.create_plan("W7D1", [Run(1500, 0)], run_body)
self.create_plan("W7D2", [Run(1500, 0)], run_body)
self.create_plan("W7D3", [Run(1500, 0)], run_body)
# Week 8
self.create_plan("W8D1", [Run(1680, 0)], run_body)
self.create_plan("W8D2", [Run(1800, 0)], run_body)
self.create_plan("W8D3", [Run(2000, 0)], run_body)
return run_body
@staticmethod
def assign_plan(instance, run_body, plan):
run_body.plan = plan
run_body.update_state_label(plan.state, plan.state_time)
# Reset all buttons' borders to white
for button in run_body.run_lst.children:
button.canvas.before.remove_group('border')
with button.canvas.before:
Color(1, 1, 1, 1, group='border') # White color for the border
Line(width=2, rectangle=(button.x, button.y, button.width, button.height), group='border')
# change border of instance to red
button.canvas.before.remove_group('border')
with instance.canvas.before:
Color(1, 0, 0, 1, group='border') # Red color for the border
Line(width=2, rectangle=(instance.x, instance.y, instance.width, instance.height), group='border')
def create_plan(self, name, runs, run_body):
# populate plans
week_plan = Plan(name, runs, 20, 20)
run_plan = RunPlanButton(
text=f"[b]{week_plan.name}[/b]\n {week_plan}",
halign="center",
valign="middle",
text_size=(None, None),
size_hint_x=None,
)
run_plan.bind(on_press=lambda x: self.assign_plan(x, run_body, week_plan))
run_plan.bind(size=self.update_text_size)
run_body.run_lst.add_widget(run_plan)
def update_text_size(self, instance, value):
instance.text_size = (instance.width, None)
if __name__ == "__main__":
RunBodyApp().run()