-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_templates.py
204 lines (167 loc) · 5.92 KB
/
page_templates.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
'''Some templates'''
# import the kivy stuff
from kivy_imports import *
# import my stuff
from globals import *
from object_defs import *
from page_templates import *
from kivy_imports import Screen#, Clock
# from globals import release_keyboard_global
def release_keyboard_global(curr):
curr._keyboard = Window.request_keyboard(curr.parent._keyboard_closed, curr)
curr._keyboard.bind(on_key_up=curr.parent._on_keyboard_up)
Window.release_all_keyboards()
class SubPageBase(Screen):
def __init__(self,**kwargs):
super(SubPageBase,self).__init__(**kwargs)
self.page_name=None
self.prev_page=None
self.next_page=None
def chevron_left(self,next_pg='RiskAssesmentPage'):
self.parent.transition.direction="right"
self.parent.current=next_pg
def arrow_left(self):
self.parent.transition.direction="right"
self.parent.current=self.prev_page
def arrow_right(self):
self.parent.transition.direction="left"
self.parent.current=self.next_page
class SubPageTemplate(SubPageBase):
def __init__(self,**kwargs):
super(SubPageTemplate,self).__init__(**kwargs)
self.total_score=0
self.pct=0
self.num_questions=1 # hard-coded for speedy initialization
self.questions_dict={
0: {'q':'Example question\n[1/7]', 'response':0,'completed':False},
}
self.curr_question_num=0
self.curr_question=self.questions_dict[0]['q']
def init_subpage(self):
print ("init_subpage")
for item in self.ids:
print (item)
print()
def reset(self):
for i in range (self.num_questions):
self.questions_dict[i]['completed']=False
self.questions_dict[i]['response']=0
self.curr_question_num=0
def button_press(self,num):
print ("num: ",num)
# self.init_subpage()
self.questions_dict[self.curr_question_num]['response']=num
self.questions_dict[self.curr_question_num]['completed']=True
self.arrow_right()
def arrow_right(self):
print (self.questions_dict[self.curr_question_num])
if self.curr_question_num<self.num_questions-1:
self.curr_question_num+=1
self.ids['q_label'].text=self.questions_dict[self.curr_question_num]['q']
else:
self.parent.transition.direction="left"
self.parent.current=self.next_page
def arrow_left(self):
print (self.questions_dict[self.curr_question_num])
if self.curr_question_num>0:
self.curr_question_num-=1
self.ids['q_label'].text=self.questions_dict[self.curr_question_num]['q']
else:
self.parent.transition.direction="right"
self.parent.current=self.prev_page
def on_pre_enter(self):
self.curr_question_num=0
# self.ids['q_label'].text=self.questions_dict[self.curr_question_num]['q']
def update_score(self):
total=0
num_done=0
for i in range (self.num_questions):
print (self.questions_dict[i]['response'])
if self.questions_dict[i]['completed']:
total+=self.questions_dict[i]['response']
num_done+=1
pct=int(round(100*(num_done/self.num_questions),0))
self.pct=pct
pct_txt=str(pct)+'% Complete'
# self.parent.ids[self.next_page].score=total
# self.parent.ids[self.next_page].score=total
print (f"self.parent.ids[self.next_page].score: {self.parent.ids[self.next_page].score}")
return total, pct_txt
def on_pre_leave(self):
self.total_score,pct_txt=self.update_score()
print (f"total: {self.total_score}")
print (pct_txt)
self.parent.score_vars_dict[self.page_name]=self.total_score
# # def init_subpage(self):
# # self.num_tabs=len(self.tab_names)
# # for i in range(self.num_tabs):
# # self.responses_dict[i]=0
# # self.done_dict[i]=0
# # self.pct=-1
# def button_press(self,button):
# print ('pressed: ',button.text)
# self.responses_dict[self.curr_tab_num+1]=int(button.text)
# self.done_dict[self.curr_tab_num+1]=True
# self.arrow_right()
# def on_tab_switch(self, instance_tabs, instance_tab, instance_tab_label, tab_text):
# # get the tab icon.
# # count_icon = instance_tab.text
# self.curr_tab_num=int(instance_tab.text)-1
# # self.ids['android_tabs'].switch_tab(self.tab_names[self.curr_tab_num])
# def update_score(self):
# # total=0
# # for key,val in self.responses_dict.items():
# # total+=val
# # self.total_score=total
# total=-1
# # num_done=0
# # for k,v in self.done_dict.items():
# # if v==True:
# # num_done+=1
# # pct=int(round(100*(num_done/self.num_tabs),0))
# pct_txt=str(-1)+'% Complete'
# return total, pct_txt
# def on_pre_leave(self):
# total,pct_txt=self.update_score()
# self.parent.score_vars_dict[self.page_name]=total
# self.parent.ids['RiskAssesmentPage'].ids[self.name+"_label"].secondary_text=pct_txt
# def arrow_right(self):
# if self.curr_tab_num==self.num_tabs-1:
# self.parent.transition.direction="left"
# self.parent.current=self.next_page
# else:
# self.curr_tab_num+=1
# # self.ids['android_tabs'].switch_tab(self.tab_names[self.curr_tab_num])
# def arrow_left(self):
# if self.curr_tab_num==0:
# self.parent.transition.direction="right"
# self.parent.current=self.prev_page
# else:
# self.curr_tab_num-=1
# # self.ids['android_tabs'].switch_tab(self.tab_names[self.curr_tab_num])
# =====================================================================================
class ScorePageTemplate(SubPageBase):
def __init__(self,**kwargs):
super(ScorePageTemplate,self).__init__(**kwargs)
self.prev_page=None
self.next_page=None
self.score=0
def update_score(self,dt):
try:
self.ids['score_label'].text=str(self.parent.ids[self.prev_page].total_score)
except:
pass
# def on_pre_enter(self):
# # self.ids['score_label'].text=str(self.parent.ids[self.prev_page].total_score)
# release_keyboard_global(self)
# # Clock.schedule_once(self.update_score,0.2)
def on_enter(self):
self.ids['score_label'].text=str(self.parent.ids[self.prev_page].total_score)
def reset_quiz(self):
# try:
# self.parent.ids[self.prev_page].ids.android_tabs.switch_tab('1')
# except:
# pass
self.parent.ids[self.prev_page].reset()
self.parent.transition.direction="right"
self.parent.current=self.landing_page