-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise_list.py
More file actions
116 lines (89 loc) · 3.08 KB
/
Copy pathexercise_list.py
File metadata and controls
116 lines (89 loc) · 3.08 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
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
import csv
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivy.uix.screenmanager import Screen
from kivymd.icon_definitions import md_icons
from kivymd.app import MDApp
from kivymd.uix.list import OneLineIconListItem, OneLineListItem
from kivymd.uix.screen import MDScreen
Builder.load_string(
'''
<ExerciseListItem>
# IconLeftWidget:
# icon: root.icon
#
MDLabel:
text: root.exercise_name
<ExerciseList>
MDBoxLayout:
MDIconButton:
icon: "close"
pos_hint: {"right": 1, "top": 1}
on_release: root.close_replace()
MDBoxLayout:
orientation: 'vertical'
spacing: dp(10)
padding: dp(20)
MDBoxLayout:
adaptive_height: True
MDIconButton:
icon: 'magnify'
MDTextField:
id: search_field
hint_text: 'Search exercise'
on_text: root.search_exercises(self.text, True)
RecycleView:
id: rv
key_viewclass: 'viewclass'
key_size: 'height'
RecycleBoxLayout:
padding: dp(10)
default_size: None, dp(48)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
'''
)
class ExerciseListItem(OneLineListItem):
exercise_name = StringProperty()
def on_release(self):
app = MDApp.get_running_app()
app.root.get_screen('testpage').replace_card_with_exercise(self.exercise_name)
class ExerciseList(MDScreen):
def __init__(self, **kwargs):
super(ExerciseList, self).__init__(**kwargs)
self.load_exercises()
# self.close_replace()
def load_exercises(self, text="", search=False):
self.ids.rv.data = []
with open('all_exercises_final.csv',
newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader)
for row in reader:
exercise_name = row[1]
self.ids.rv.data.append({
'viewclass': 'ExerciseListItem',
'text': exercise_name,
'exercise_name': exercise_name
})
def search_exercises(self, text="", search=False):
self.ids.rv.data = []
with open('all_exercises_final.csv',
newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader)
for row in reader:
exercise_name = row[1]
if text.lower() in exercise_name.lower():
self.ids.rv.data.append({
'viewclass': 'ExerciseListItem',
'text': exercise_name,
'exercise_name': exercise_name
})
def select_exercise(self, exercise_name):
homepage = self.manager.get_screen('testpage')
homepage.replace_card_with_exercise(exercise_name)
def close_replace(self):
self.manager.current = 'testpage'