1 from gi.repository
import Gtk
as gtk
20 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
21 self.window.set_title(
'Create Check')
22 self.window.connect(
'destroy',
lambda w: self.window.destroy())
23 self.window.set_border_width(10)
27 vbox.pack_start(settings_frame,
True,
True, 0)
33 vbox.pack_end(buttons_box,
True,
True, 0)
37 self.window.show_all()
42 button_box = gtk.HButtonBox()
43 button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
45 cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL, label=
'Cancel')
46 cancel_button.connect(
'clicked',
lambda w: self.window.destroy())
47 button_box.add(cancel_button)
49 create_button = gtk.Button(stock=gtk.STOCK_OK, label=
'Create')
50 create_button.connect(
'clicked',
lambda w: self.
create_check())
51 button_box.add(create_button)
53 vbox.pack_start(gtk.HSeparator(),
True,
True, 0)
54 vbox.pack_start(button_box,
True,
True, 0)
59 settings_frame = gtk.Frame(label=
'Settings')
64 name_label = gtk.Label(
'Name:')
65 name_label.set_justify(gtk.JUSTIFY_RIGHT)
67 grid.attach(name_label, 0, 0, 1, 1)
69 self.form.name_entry = gtk.Entry()
70 self.form.name_entry.set_width_chars(50)
72 grid.attach(self.form.name_entry, 1, 0, 1, 1)
74 input_file_label = gtk.Label(
'TRS / CSV File:')
75 input_file_label.set_justify(gtk.JUSTIFY_RIGHT)
77 grid.attach(input_file_label, 0, 1, 1, 1)
79 self.form.input_file_entry = gtk.Entry()
80 self.form.input_file_entry.set_width_chars(50)
81 self.form.wav_file_entry = gtk.Entry()
82 self.form.wav_file_entry.set_width_chars(50)
84 grid.attach(self.form.input_file_entry, 1, 1, 1, 1)
86 input_file_button = gtk.Button(
'Browse')
87 input_file_button.connect(
'clicked',
lambda w: UIUtils.browse_file(
'Select trs/csv file', self.form.input_file_entry, [UIUtils.TRS_CSV_FILE_FILTER, UIUtils.ALL_FILE_FILTER], self.form.wav_file_entry))
89 grid.attach(input_file_button, 2, 1, 1, 1)
91 wav_file_label = gtk.Label(
'WAV File:')
92 wav_file_label.set_justify(gtk.JUSTIFY_RIGHT)
94 grid.attach(wav_file_label, 0, 2, 1, 1)
97 grid.attach(self.form.wav_file_entry, 1, 2, 1, 1)
99 wav_file_button = gtk.Button(
'Browse')
100 wav_file_button.connect(
'clicked',
lambda w: UIUtils.browse_file(
'Select wav file', self.form.wav_file_entry, [UIUtils.WAV_FILE_FILTER, UIUtils.ALL_FILE_FILTER]))
102 grid.attach(wav_file_button, 2, 2, 1, 1)
104 num_segs_label = gtk.Label(
'Number of Segments:')
105 num_segs_label.set_justify(gtk.JUSTIFY_RIGHT)
107 grid.attach(num_segs_label, 0, 4, 1, 1)
109 num_segs_adj = gtk.Adjustment(value=0, lower=1, upper=2**32, step_incr=1, page_incr=5)
110 self.form.num_segs_spinner = gtk.SpinButton(num_segs_adj)
112 grid.attach(self.form.num_segs_spinner, 1, 4, 1, 1)
114 context_pad_label = gtk.Label(
'Default context padding (sec):')
115 context_pad_label.set_justify(gtk.JUSTIFY_RIGHT)
117 grid.attach(context_pad_label, 0, 5, 1, 1)
119 context_pad_adj = gtk.Adjustment(value=0, lower=1, upper=60, step_incr=1, page_incr=5)
120 self.form.context_pad_spinner = gtk.SpinButton(context_pad_adj)
122 grid.attach(self.form.context_pad_spinner, 1, 5, 1, 1)
124 self.form.rand_checkbox = gtk.CheckButton(
'Pick segs randomly')
126 grid.attach(self.form.rand_checkbox, 0, 6, 1, 1)
128 settings_frame.add(grid)
130 return settings_frame
135 if (self.form.name_entry.get_text() ==
'' or
136 self.form.input_file_entry.get_text() ==
'' or
137 self.form.wav_file_entry.get_text() ==
''):
138 error_msgs.append(
' -Please ensure that all fields are filled.')
140 if self.form.input_file_entry.get_text() !=
'' and not os.path.exists(self.form.input_file_entry.get_text()):
141 error_msgs.append(
' -Unable to locate TRS/CSV file. Please double-check the file path.')
143 if self.form.wav_file_entry.get_text() !=
'' and not os.path.exists(self.form.wav_file_entry.get_text()):
144 error_msgs.append(
' -Unable to locate WAV file. Please double-check the file path.')
148 composite_msg =
'The following issues were detected:\n%s' % (
'\n'.join(error_msgs))
156 UIUtils.show_message_dialog(error_msg)
159 filters = self.filters_frame.get_filters()
161 check =
Check(self.form.name_entry.get_text(),
162 self.form.input_file_entry.get_text(),
163 self.form.wav_file_entry.get_text(),
164 self.form.num_segs_spinner.get_value_as_int(),
165 self.form.context_pad_spinner.get_value_as_int(),
169 pick_randomly=self.form.rand_checkbox.get_active(),
174 phases=[
'Parsing file...',
'Setting up...'])
178 if check.input_filename.lower().endswith(
'.trs'):
180 progress_dialog.show()
181 segs = parser.parse(progress_update_fcn=progress_dialog.set_fraction,
182 progress_next_phase_fcn=progress_dialog.next_phase,
184 seg_filters=check.filters)
189 progress_dialog.show()
190 segs = parser.parse(progress_update_fcn=progress_dialog.set_fraction,
191 seg_filters=check.filters)
193 progress_dialog.next_phase()
195 if check.pick_randomly:
197 segs = ParserTools.hacked_pick_rand_segs(check.num_segs, segs, os.path.basename(check.input_filename))
199 segs = ParserTools.pick_contiguous_segs(check.num_segs, segs)
200 progress_dialog.set_fraction(1.0)
202 if len(segs) < check.num_segs:
203 progress_dialog.ensure_finish()
204 UIUtils.show_message_dialog(
'The input file does not contain enough segments of the specified types.', dialog_type=gtk.MessageType.ERROR)
210 for i
in range(len(segs)):
211 if segs[i].db_id ==
None:
212 segs[i].db_insert(db)
221 check.default_context_padding,
224 check.tests.append(test)
226 progress_dialog.set_fraction( float(i + 1) / float(check.num_segs) )
229 progress_dialog.ensure_finish()
231 self.window.destroy()