1 from gi.repository
import Gtk
as gtk
20 self.
logger = logging.getLogger(__name__)
26 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
27 self.window.set_title(
'Testing')
28 self.window.connect(
'destroy',
lambda w: self.
_exit())
29 self.window.set_border_width(10)
30 self.window.set_default_size(350, 200)
52 vbox.pack_end(button_box,
True,
True, 0)
55 self.window.show_all()
62 progress_bar = gtk.ProgressBar()
63 progress_bar.set_orientation(gtk.Orientation.HORIZONTAL)
68 cur_test = self.check.tests[self.check.test_index]
71 if cur_test.category_input !=
None:
72 cat_index = cur_test.category_input - DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS.RELIABILITY_CATEGORIES].EMPTY
73 self.w_form.type_combo.set_active(cat_index)
75 self.w_form.uncertain_checkbox.set_active(cur_test.is_uncertain
or False)
77 self.w_form.context_pad_spinner.set_value(cur_test.context_padding)
79 self.w_form.syllables_spinner.set_value(cur_test.syllables_w_context
if cur_test.syllables_w_context !=
None else 0)
83 self.w_form.user_start_entry.set_text(str(cur_test.seg.user_adj_start)
if cur_test.seg.user_adj_start !=
None else str(seg_start))
84 self.w_form.user_end_entry.set_text(str(cur_test.seg.user_adj_end)
if cur_test.seg.user_adj_end !=
None else str(seg_end))
86 self.wo_form.syllables_spinner.set_value(cur_test.syllables_wo_context
if cur_test.syllables_wo_context !=
None else 0)
87 self.wo_context_checkbox.set_active(cur_test.syllables_wo_context !=
None)
90 cur_test = self.check.tests[self.check.test_index]
91 frame = gtk.Frame(label=
'With Context')
96 play_button = UIUtils.create_button(
'', UIUtils.BUTTON_ICONS.PLAY, UIUtils.BUTTON_ICON_SIZES.PX32)
98 grid.attach(play_button, 0, 0, 1, 1)
100 type_label = gtk.Label(
'Seg Category:')
102 grid.attach(type_label, 1, 0, 1, 1)
104 self.w_form.type_combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.RELIABILITY_CATEGORIES)
106 grid.attach(self.w_form.type_combo, 2, 0, 1, 1)
108 uncertain_label = gtk.Label(
'Other/Uncertain:')
109 self.w_form.uncertain_checkbox = gtk.CheckButton()
111 grid.attach(uncertain_label, 1, 1, 1, 1)
113 grid.attach(self.w_form.uncertain_checkbox, 2, 1, 1, 1)
115 padding_label = gtk.Label(
'Padding:')
116 context_pad_adj = gtk.Adjustment(value=0, lower=1, upper=1000, step_incr=1, page_incr=5)
117 self.w_form.context_pad_spinner = gtk.SpinButton(context_pad_adj)
119 grid.attach(padding_label, 1, 2, 1, 1)
121 grid.attach(self.w_form.context_pad_spinner, 2, 2, 1, 1)
123 self.w_form.handler_man.add_handler(play_button,
'clicked',
lambda w: self.
play_seg(int(self.w_form.context_pad_spinner.get_value())))
125 syllables_label = gtk.Label(
'Syllables:')
126 syllables_adj = gtk.Adjustment(value=0, lower=0, upper=1000, step_incr=1, page_incr=5)
127 self.w_form.syllables_spinner = gtk.SpinButton(syllables_adj)
129 grid.attach(syllables_label, 1, 3, 1, 1)
131 grid.attach(self.w_form.syllables_spinner, 2, 3, 1, 1)
133 user_start_label = gtk.Label(
'User Start:')
134 self.w_form.user_start_entry = gtk.Entry()
135 self.w_form.user_start_entry.set_width_chars(10)
137 grid.attach(user_start_label, 1, 4, 1, 1)
139 grid.attach(self.w_form.user_start_entry, 2, 5, 1, 1)
141 user_end_label = gtk.Label(
'User End:')
142 self.w_form.user_end_entry = gtk.Entry()
143 self.w_form.user_end_entry.set_width_chars(10)
145 grid.attach(user_end_label, 1, 5, 1, 1)
147 grid.attach(self.w_form.user_end_entry, 2, 5, 1, 1)
149 open_praat_button = gtk.Button(
'Open Praat')
151 grid.attach(open_praat_button, 3, 4, 1, 1)
152 self.w_form.handler_man.add_handler(open_praat_button,
'clicked',
lambda w: self.
_open_praat())
154 close_praat_button = gtk.Button(
'Close Praat')
156 grid.attach(close_praat_button, 3, 5, 1, 1)
157 self.w_form.handler_man.add_handler(close_praat_button,
'clicked',
lambda w: self.
_close_praat())
164 cur_test = self.check.tests[self.check.test_index]
165 frame = gtk.Frame(label=
'Without Context')
170 self.wo_form.play_button = UIUtils.create_button(
'', UIUtils.BUTTON_ICONS.PLAY, UIUtils.BUTTON_ICON_SIZES.PX32)
171 self.wo_form.handler_man.add_handler(self.wo_form.play_button,
'clicked',
lambda w: self.
play_seg(0))
173 grid.attach(self.wo_form.play_button, 0, 0, 1, 1)
175 syllables_label = gtk.Label(
'Syllables:')
176 syllables_adj = gtk.Adjustment(value=0, lower=0, upper=1000, step_incr=1, page_incr=5)
177 self.wo_form.syllables_spinner = gtk.SpinButton(syllables_adj)
179 grid.attach(syllables_label, 1, 0, 1, 1)
181 grid.attach(self.wo_form.syllables_spinner, 2, 0, 1, 1)
189 self.wo_context_frame.show()
191 self.wo_context_frame.hide()
192 self.check.tests[self.check.test_index].syllables_wo_context =
None
193 self.wo_form.syllables_spinner.get_adjustment().set_value(1)
197 cur_test = self.check.tests[self.check.test_index]
198 checkbox = gtk.CheckButton(label=
'Test Without Context')
201 checkbox.set_active(cur_test.syllables_wo_context !=
None)
206 box = gtk.HButtonBox()
207 box.set_layout(gtk.ButtonBoxStyle.EDGE)
209 self.button_form.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
210 self.button_form.handler_man.add_handler(self.button_form.back_button,
'clicked',
lambda w: self.
_back())
212 self.button_form.save_button = UIUtils.create_button(
'Save & Exit', UIUtils.BUTTON_ICONS.SAVE, UIUtils.BUTTON_ICON_SIZES.PX32)
213 self.button_form.handler_man.add_handler(self.button_form.save_button,
'clicked',
lambda w: self.
_exit())
215 self.button_form.forward_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
216 self.button_form.handler_man.add_handler(self.button_form.forward_button,
'clicked',
lambda w: self.
_forward())
220 box.pack_start(self.button_form.back_button,
False,
False, 0)
221 box.pack_start(self.button_form.save_button,
False,
False, 0)
222 box.pack_end(self.button_form.forward_button,
False,
False, 0)
227 if self.check.num_segs == 1:
228 self.progress_bar.set_fraction(1.0)
231 self.progress_bar.set_fraction( float(self.check.test_index) / float(self.check.num_segs - 1) )
233 self.progress_bar.set_text(
'Segment %d of %d' % (self.check.test_index + 1, self.check.num_segs))
237 img.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
238 button.set_label(label_text)
239 button.set_image(img)
241 self.button_form.handler_man.remove_handlers(button, [
'clicked'])
242 self.button_form.handler_man.add_handler(button,
'clicked', clicked_handler)
245 finish_text =
'Finish'
246 forward_text =
'Forward'
248 if self.check.test_index == self.check.num_segs - 1:
251 elif self.button_form.forward_button.get_label() == finish_text:
252 self.
_set_step_button(self.button_form.forward_button, gtk.STOCK_GO_FORWARD, forward_text,
lambda w: self.
_forward())
254 self.button_form.back_button.set_sensitive(self.check.test_index > 0)
260 self.wav_parser.close()
261 self.window.destroy()
265 self.
save_input(mark_last_run=
True, mark_as_completed=
True)
267 filename, check_results = UIUtils.save_file(filters=[UIUtils.CSV_FILE_FILTER], open_now_opt=
True, save_last_location=
True)
271 if exporter.export():
273 subprocess.Popen([
'%s' % DBConstants.SETTINGS.SPREADSHEET_PATH, filename])
275 UIUtils.show_message_dialog(
'Results exported successfully.')
280 UIUtils.show_message_dialog(
'An error occurred while exporting the results. These results are still saved in the database, and can be exported at a later time, pending the correction of this problem. Please bother the programmer until this happens.')
284 w_context_valid = (self.w_form.type_combo.get_active() != 0
and
285 int(self.w_form.syllables_spinner.get_adjustment().get_value()) > 0
and
286 BackendUtils.is_float(self.w_form.user_start_entry.get_text())
and
287 BackendUtils.is_float(self.w_form.user_end_entry.get_text()))
291 wo_context_valid = (
not self.wo_context_checkbox.get_active()
or int(self.wo_form.syllables_spinner.get_adjustment().get_value()) > 0)
295 is_valid = w_context_valid
and wo_context_valid
300 user_start = float(self.w_form.user_start_entry.get_text())
301 user_end = float(self.w_form.user_end_entry.get_text())
302 cur_test = self.check.tests[self.check.test_index]
304 is_valid = (cur_test.seg.start != user_start
or cur_test.seg.end != user_end)
306 is_valid = UIUtils.show_confirm_dialog(
'Segment boundaries have not been adjusted. Continue anyway?')
309 UIUtils.show_message_dialog(
'Please ensure that all of the inputs have a correct value.')
315 self.check.test_index += incr
328 start_time = self.check.tests[self.check.test_index].seg.start
329 end_time = self.check.tests[self.check.test_index].seg.end
332 context_len = self.w_form.context_pad_spinner.get_value_as_int()
if include_context
else 0
333 start_time = max(start_time - context_len, 0)
334 end_time = min(end_time + context_len, self.wav_parser.get_sound_len())
336 return start_time, end_time
339 start_time, end_time = self.
_get_bounds(include_context=
True)
340 PraatInterop.open_praat()
341 PraatInterop.send_commands( PraatInterop.get_open_clip_script(start_time, end_time, self.check.wav_filename) )
344 socket = PraatInterop.create_serversocket()
345 PraatInterop.send_commands( PraatInterop.get_sel_bounds_script(self.check.wav_filename) )
346 start_time, end_time = PraatInterop.socket_receive(socket)
348 PraatInterop.close_praat()
350 if start_time != end_time:
352 start_time = str( round(float(start_time), 3) )
353 end_time = str( round(float(end_time), 3) )
355 self.w_form.user_start_entry.set_text(start_time)
356 self.w_form.user_end_entry.set_text(end_time)
359 self.wav_parser.play_seg(self.check.tests[self.check.test_index].seg, context_len)
361 def save_input(self, mark_last_run=False, mark_as_completed=False):
362 cur_test = self.check.tests[self.check.test_index]
364 cur_test.category_input = self.w_form.type_combo.get_model()[self.w_form.type_combo.get_active()][1]
365 cur_test.is_uncertain = self.w_form.uncertain_checkbox.get_active()
366 cur_test.context_padding = int(self.w_form.context_pad_spinner.get_adjustment().get_value())
367 cur_test.syllables_w_context = int(self.w_form.syllables_spinner.get_adjustment().get_value())
368 cur_test.seg.user_adj_start = float(self.w_form.user_start_entry.get_text())
369 cur_test.seg.user_adj_end = float(self.w_form.user_end_entry.get_text())
371 cur_test.syllables_wo_context =
None
372 if self.wo_context_checkbox.get_active():
373 cur_test.syllables_wo_context = int(self.wo_form.syllables_spinner.get_adjustment().get_value())
376 cur_test.db_update_user_inputs(db)
377 self.check.db_update_test_index(db)
380 self.check.mark_last_run(db)
382 if mark_as_completed:
383 self.check.mark_as_completed(db)