Skip to content

Commit 8e6eeaf

Browse files
ENH: add batch learn
1 parent fa524d9 commit 8e6eeaf

File tree

4 files changed

+217
-443
lines changed

4 files changed

+217
-443
lines changed

common.py

Lines changed: 10 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -143,107 +143,6 @@ def __init__(self, title, from_string_methods=None, to_string_methods=None, **kw
143143

144144
def delete(self):
145145
pass
146-
#
147-
#
148-
# class NewElementPopup(Popup):
149-
#
150-
# id_map = {}
151-
#
152-
# def __init__(self, title, default_vals=None, conversion=None, **kwargs):
153-
# super().__init__(**kwargs)
154-
# self.default_vals = default_vals or {}
155-
# self.title = title
156-
# self.conversion = conversion or {}
157-
# self.populate_content()
158-
#
159-
# def populate_content(self):
160-
# for cell_id, db_field in self.id_map.items():
161-
# self.ids[cell_id].text = str(self.default_vals.get(db_field, ''))
162-
#
163-
# def alert(self, msg):
164-
# try:
165-
# self.ids['alert'].text = msg
166-
# except KeyError:
167-
# pass
168-
#
169-
# def save(self):
170-
# value_dict = {}
171-
# for cell_id, db_field in self.id_map.items():
172-
# new_val = self.ids[cell_id].text.strip()
173-
# if db_field in self.conversion:
174-
# try:
175-
# new_val = self.conversion[db_field](new_val)
176-
# except ValueError:
177-
# self.alert('invalid value for %s!' % db_field)
178-
# return
179-
# value_dict[db_field] = new_val
180-
# if self.validate_input(value_dict):
181-
# self.act_on_save(value_dict)
182-
# self.dismiss()
183-
#
184-
# def validate_input(self, value_dict):
185-
# return True
186-
#
187-
# def act_on_save(self, value_dict):
188-
# pass
189-
#
190-
# def cancel(self):
191-
# self.dismiss()
192-
#
193-
#
194-
# class EditPopup(Popup):
195-
#
196-
# id_map = {}
197-
#
198-
# def __init__(self, db_object, title, conversion=None, **kwargs):
199-
# super().__init__(**kwargs)
200-
# self.db_object = db_object
201-
# self.title = title
202-
# self.conversion = conversion or {}
203-
# self.populate_content()
204-
#
205-
# def populate_content(self):
206-
# val_dict = self.db_object.to_dict()
207-
# for cell_id, db_field in self.id_map.items():
208-
# self.ids[cell_id].text = str(val_dict[db_field])
209-
#
210-
# def alert(self, msg):
211-
# try:
212-
# self.ids['alert'].text = msg
213-
# except KeyError:
214-
# pass
215-
#
216-
# def save(self):
217-
# val_dict = self.db_object.to_dict()
218-
# changed = False
219-
# for cell_id, db_field in self.id_map.items():
220-
# new_val = self.ids[cell_id].text.strip()
221-
# if db_field in self.conversion:
222-
# try:
223-
# new_val = self.conversion[db_field](new_val)
224-
# except ValueError:
225-
# self.alert('invalid value for %s!' % db_field)
226-
# return
227-
# if new_val != val_dict[db_field]:
228-
# changed = True
229-
# setattr(self.db_object, db_field, new_val)
230-
# if changed:
231-
# if self.validate_input(value_dict):
232-
# self.act_on_edit()
233-
# self.dismiss()
234-
# else:
235-
# return
236-
# else:
237-
# self.alert('nothing changed!')
238-
#
239-
# def act_on_edit(self):
240-
# pass
241-
#
242-
# def validate_input(self, value_dict):
243-
# return True
244-
#
245-
# def cancel(self):
246-
# self.dismiss()
247146

248147

249148
class PopupLabelCell(Label):
@@ -260,3 +159,13 @@ def get_screen(name):
260159

261160
def set_screen_active(name):
262161
get_screen_manager().current = name
162+
163+
164+
def hide_widget(wid, dohide=True):
165+
if hasattr(wid, 'saved_attrs'):
166+
if not dohide:
167+
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = wid.saved_attrs
168+
del wid.saved_attrs
169+
elif dohide:
170+
wid.saved_attrs = wid.height, wid.size_hint_y, wid.opacity, wid.disabled
171+
wid.height, wid.size_hint_y, wid.opacity, wid.disabled = 0, None, 0, True

learn.kv

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,42 @@
6666
on_release:
6767
root.cancel()
6868

69+
<LearnBatchLabel>:
70+
orientation: 'horizontal'
71+
padding: 0
72+
spacing: 1
73+
HiddenButton:
74+
id: btn_left
75+
halign: 'left'
76+
valign: 'top'
77+
on_press: root.set_correct()
78+
size_hint: 1, 1
79+
text_size: self.size[0] * .9, self.size[1] * .9
80+
HiddenButton:
81+
id: btn_right
82+
halign: 'left'
83+
valign: 'top'
84+
on_press: root.reveal()
85+
size_hint: 1, 1
86+
text_size: self.size[0] * .9, self.size[1] * .9
87+
88+
<LearnBatchRV>:
89+
viewclass: 'LearnBatchLabel'
90+
RecycleBoxLayout:
91+
id: rv_layout
92+
orientation: 'vertical'
93+
default_size: None, dp(42)
94+
default_size_hint: 1, None
95+
size_hint_y: None
96+
height: self.minimum_height
97+
6998
<LearnScreen>:
7099

71100
set_info_label: set_info_label
101+
learn_layout: learn_layout
102+
layout_single: layout_single
103+
layout_batch: layout_batch
104+
box_batch_table: box_batch_table
72105

73106
BoxLayout:
74107
orientation: 'vertical'
@@ -98,38 +131,66 @@
98131
color: .6, .6, .6, 1.
99132

100133
BoxLayout:
101-
id: questions
134+
id: learn_layout
102135
orientation: 'vertical'
103-
size_hint_y: 7
104-
HiddenButton:
105-
id: q_next
106-
text: 'foo'
107-
color: .6, .6, .6, 1.
108-
font_size: 14
109-
on_press: root.reveal()
110-
HiddenButton:
111-
id: q_this
112-
text: 'bar'
113-
font_size: 20
114-
on_press: root.reveal()
115-
HiddenButton:
116-
id: answer
117-
text: 'hidden answer'
118-
font_size: 20
119-
on_press: root.reveal()
136+
size_hint_y: 10
137+
138+
BoxLayout:
139+
id: layout_single
140+
orientation: 'vertical'
141+
142+
BoxLayout:
143+
id: questions
144+
orientation: 'vertical'
145+
size_hint_y: 7
146+
HiddenButton:
147+
id: q_next
148+
text: 'foo'
149+
color: .6, .6, .6, 1.
150+
font_size: 14
151+
on_press: root.reveal()
152+
HiddenButton:
153+
id: q_this
154+
text: 'bar'
155+
font_size: 20
156+
on_press: root.reveal()
157+
HiddenButton:
158+
id: answer
159+
text: 'hidden answer'
160+
font_size: 20
161+
on_press: root.reveal()
162+
163+
BoxLayout:
164+
orientation: 'vertical'
165+
size_hint_y: 3
166+
BoxLayout:
167+
orientation: 'horizontal'
168+
spacing: 1
169+
padding: 1
170+
NavbarButton:
171+
background_color: 0.173, 0.278, 0.439, 1.
172+
text: 'wrong'
173+
on_press: root.wrong_answer()
174+
NavbarButton:
175+
background_color: 0.29, 0.569, 0.188, 1.
176+
text: 'correct'
177+
on_press: root.right_answer()
120178

121-
BoxLayout:
122-
orientation: 'vertical'
123-
size_hint_y: 3
124179
BoxLayout:
125-
orientation: 'horizontal'
126-
spacing: 1
127-
padding: 1
128-
NavbarButton:
129-
background_color: 0.173, 0.278, 0.439, 1.
130-
text: 'wrong'
131-
on_press: root.wrong_answer()
132-
NavbarButton:
133-
background_color: 0.29, 0.569, 0.188, 1.
134-
text: 'correct'
135-
on_press: root.right_answer()
180+
id: layout_batch
181+
orientation: 'vertical'
182+
size_hint_y: 10
183+
184+
BoxLayout:
185+
orientation: 'vertical'
186+
size_hint_y: 0.5
187+
padding: 3
188+
NavbarButton:
189+
text: 'Submit'
190+
on_press: root.submit_batch()
191+
192+
193+
BoxLayout:
194+
id: box_batch_table
195+
orientation: 'vertical'
196+
size_hint_y: 9.5

0 commit comments

Comments
 (0)