def _build(self): #table = gtk.Table(3, 2) #table.set_row_spacings(5) #table.set_col_spacings(2) grid = gtk.Grid() grid.set_row_spacing(5) grid.set_column_spacing(2) type_label = gtk.Label('Filter Type:') #table.attach(type_label, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND) grid.attach(type_label, 0, 0, 1, 1) filter_type_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.SEG_FILTER_TYPES) #table.attach(filter_type_combo, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND) grid.attach(filter_type_combo, 1, 0, 1, 1) self.inputs_dict['filter_type'] = ( lambda: filter_type_combo.get_active() > 0, lambda: filter_type_combo.get_model()[filter_type_combo.get_active()][1]) negate_label = gtk.Label('Negate:') #table.attach(negate_label, 0, 1, 1, 2, gtk.EXPAND, gtk.EXPAND) grid.attach(negate_label, 0, 1, 1, 1) negate_checkbox = gtk.CheckButton() negate_hbox = gtk.HBox() negate_hbox.pack_start(negate_checkbox, True, True, 0) negate_hbox.pack_start(gtk.Alignment(xalign=0, yalign=0), True, True, 0) #table.attach(negate_hbox, 1, 2, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL) grid.attach(negate_hbox, 1, 1, 1, 1) self.inputs_dict['negate'] = (lambda: True, lambda: negate_checkbox.get_active()) opts_vbox = gtk.VBox() #table.attach(opts_vbox, 0, 2, 2, 3) grid.attach(opts_vbox, 0, 2, 2, 1) filter_type_combo.connect('changed', lambda w: self._update_add_inputs(opts_vbox)) button_box = gtk.HButtonBox() button_box.set_layout(gtk.ButtonBoxStyle.EDGE) cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL) cancel_button.connect('clicked', lambda w: self.window.destroy()) button_box.pack_start(cancel_button, False, False, 0) ok_button = gtk.Button(stock=gtk.STOCK_OK) ok_button.connect('clicked', lambda w: self._create_filter()) button_box.pack_start(ok_button, False, False, 0) vbox = gtk.VBox() vbox.pack_start(grid, False, False, 0) vbox.pack_end(button_box, False, False, 0) self.window.add(vbox) self.window.show_all()
def _build_w_context_frame(self): cur_test = self.check.tests[self.check.test_index] frame = gtk.Frame(label='With Context') #table = gtk.Table(6, 4, False) grid = gtk.Grid() play_button = UIUtils.create_button('', UIUtils.BUTTON_ICONS.PLAY, UIUtils.BUTTON_ICON_SIZES.PX32) #table.attach(play_button, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND) grid.attach(play_button, 0, 0, 1, 1) type_label = gtk.Label('Seg Category:') #table.attach(type_label, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND) grid.attach(type_label, 1, 0, 1, 1) self.w_form.type_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.RELIABILITY_CATEGORIES) #table.attach(self.w_form.type_combo, 2, 3, 0, 1, gtk.EXPAND, gtk.EXPAND) grid.attach(self.w_form.type_combo, 2, 0, 1, 1) uncertain_label = gtk.Label('Other/Uncertain:') self.w_form.uncertain_checkbox = gtk.CheckButton() #table.attach(uncertain_label, 1, 2, 1, 2, gtk.EXPAND, gtk.EXPAND) grid.attach(uncertain_label, 1, 1, 1, 1) #table.attach(self.w_form.uncertain_checkbox, 2, 3, 1, 2, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL) grid.attach(self.w_form.uncertain_checkbox, 2, 1, 1, 1) padding_label = gtk.Label('Padding:') context_pad_adj = gtk.Adjustment(value=0, lower=1, upper=1000, step_incr=1, page_incr=5) self.w_form.context_pad_spinner = gtk.SpinButton(context_pad_adj) #table.attach(padding_label, 1, 2, 2, 3, gtk.EXPAND, gtk.EXPAND) grid.attach(padding_label, 1, 2, 1, 1) #table.attach(self.w_form.context_pad_spinner, 2, 3, 2, 3, gtk.EXPAND, gtk.EXPAND) grid.attach(self.w_form.context_pad_spinner, 2, 2, 1, 1) self.w_form.handler_man.add_handler( play_button, 'clicked', lambda w: self.play_seg( int(self.w_form.context_pad_spinner.get_value()))) syllables_label = gtk.Label('Syllables:') syllables_adj = gtk.Adjustment(value=0, lower=0, upper=1000, step_incr=1, page_incr=5) self.w_form.syllables_spinner = gtk.SpinButton(syllables_adj) #table.attach(syllables_label, 1, 2, 3, 4, gtk.EXPAND, gtk.EXPAND) grid.attach(syllables_label, 1, 3, 1, 1) #table.attach(self.w_form.syllables_spinner, 2, 3, 3, 4, gtk.EXPAND, gtk.EXPAND) grid.attach(self.w_form.syllables_spinner, 2, 3, 1, 1) user_start_label = gtk.Label('User Start:') self.w_form.user_start_entry = gtk.Entry() self.w_form.user_start_entry.set_width_chars(10) #table.attach(user_start_label, 1, 2, 4, 5, gtk.EXPAND, gtk.EXPAND) grid.attach(user_start_label, 1, 4, 1, 1) #table.attach(self.w_form.user_start_entry, 2, 3, 4, 5, gtk.EXPAND, gtk.EXPAND) grid.attach(self.w_form.user_start_entry, 2, 5, 1, 1) user_end_label = gtk.Label('User End:') self.w_form.user_end_entry = gtk.Entry() self.w_form.user_end_entry.set_width_chars(10) #table.attach(user_end_label, 1, 2, 5, 6, gtk.EXPAND, gtk.EXPAND) grid.attach(user_end_label, 1, 5, 1, 1) #table.attach(self.w_form.user_end_entry, 2, 3, 5, 6, gtk.EXPAND, gtk.EXPAND) grid.attach(self.w_form.user_end_entry, 2, 5, 1, 1) open_praat_button = gtk.Button('Open Praat') #table.attach(open_praat_button, 3, 4, 4, 5, gtk.EXPAND, gtk.EXPAND) grid.attach(open_praat_button, 3, 4, 1, 1) self.w_form.handler_man.add_handler(open_praat_button, 'clicked', lambda w: self._open_praat()) close_praat_button = gtk.Button('Close Praat') #table.attach(close_praat_button, 3, 4, 5, 6, gtk.EXPAND, gtk.EXPAND) grid.attach(close_praat_button, 3, 5, 1, 1) self.w_form.handler_man.add_handler(close_praat_button, 'clicked', lambda w: self._close_praat()) frame.add(grid) return frame
def _update_options_frame(self, cell_matrix, n_rows, n_cols, sel_option_id): for row in range(n_rows): for col in range(n_cols): children = cell_matrix[row][col].get_children() for child in children: cell_matrix[row][col].remove(child) self.inputs_dict['calc_inputs'] = [] #clear any previous inputs options = DBConstants.COMBO_OPTIONS[ DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES] if sel_option_id == options.COUNT: regex_label = gtk.Label('Search:') regex_entry = gtk.Entry() regex_entry.set_width_chars(30) if self.edit_output: regex_entry.set_text(self.edit_output.output_calc.search_term) regex_helper = UIUtils.build_regex_helper_combo(regex_entry) hbox = gtk.HBox() hbox.pack_start(regex_entry, False, False, 0) hbox.pack_start(regex_helper, False, False, 0) cell_matrix[0][0].pack_start(regex_label, False, False, 0) cell_matrix[0][1].pack_start(hbox, False, False, 0) cell_matrix[0][0].show_all() cell_matrix[0][1].show_all() combo_label = gtk.Label('Calc Type:') active_index = 0 if self.edit_output: active_index = self._get_combo_index( DBConstants.COMBO_GROUPS.COUNT_OUTPUT_CALC_TYPES, self.edit_output.output_calc.count_type) combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.COUNT_OUTPUT_CALC_TYPES, active_index) cell_matrix[1][0].pack_start(combo_label, False, False, 0) cell_matrix[1][1].pack_start(combo, False, False, 0) cell_matrix[1][0].show_all() cell_matrix[1][1].show_all() self.inputs_dict['calc_inputs'].append(( lambda: True, #if no text, assume user is searching for '*' lambda: regex_entry.get_text())) self.inputs_dict['calc_inputs'].append( (lambda: combo.get_active() > 0, lambda: combo.get_model()[combo.get_active()][1])) elif sel_option_id == options.RATE: regex_label = gtk.Label('Search:') regex_entry = gtk.Entry() regex_entry.set_width_chars(30) if self.edit_output: regex_entry.set_text(self.edit_output.output_calc.search_term) regex_helper = UIUtils.build_regex_helper_combo(regex_entry) hbox = gtk.HBox() hbox.pack_start(regex_entry, False, False, 0) hbox.pack_start(regex_helper, False, False, 0) cell_matrix[0][0].pack_start(regex_label, False, False, 0) cell_matrix[0][1].pack_start(hbox, False, False, 0) cell_matrix[0][0].show_all() cell_matrix[0][1].show_all() combo_label = gtk.Label('Calc Type:') active_index = 0 if self.edit_output: active_index = self._get_combo_index( DBConstants.COMBO_GROUPS.RATE_OUTPUT_CALC_TYPES, self.edit_output.output_calc.rate_type) combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.RATE_OUTPUT_CALC_TYPES, active_index) cell_matrix[1][0].pack_start(combo_label, False, False, 0) cell_matrix[1][1].pack_start(combo, False, False, 0) cell_matrix[1][0].show_all() cell_matrix[1][1].show_all() self.inputs_dict['calc_inputs'].append( (lambda: True, lambda: regex_entry.get_text())) self.inputs_dict['calc_inputs'].append( (lambda: combo.get_active() > 0, lambda: combo.get_model()[combo.get_active()][1])) elif sel_option_id == options.TIME_PERIOD: regex_label = gtk.Label('Search:') regex_entry = gtk.Entry() regex_entry.set_width_chars(30) if self.edit_output: regex_entry.set_text(self.edit_output.output_calc.search_term) regex_helper = UIUtils.build_regex_helper_combo(regex_entry) hbox = gtk.HBox() hbox.pack_start(regex_entry, False, False, 0) hbox.pack_start(regex_helper, False, False, 0) cell_matrix[0][0].pack_start(regex_label, False, False, 0) cell_matrix[0][1].pack_start(hbox, False, False, 0) cell_matrix[0][0].show_all() cell_matrix[0][1].show_all() self.inputs_dict['calc_inputs'].append( (lambda: True, lambda: regex_entry.get_text())) elif sel_option_id == options.BREAKDOWN: row_combo_label = gtk.Label('Row Criteria:') active_row_index = 0 if self.edit_output: active_row_index = self._get_combo_index( DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, self.edit_output.output_calc.row_criteria) row_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, active_row_index) cell_matrix[0][0].pack_start(row_combo_label, False, False, 0) cell_matrix[0][1].pack_start(row_combo, False, False, 0) cell_matrix[0][0].show_all() cell_matrix[0][1].show_all() col_combo_label = gtk.Label('Column Criteria:') active_col_index = 0 if self.edit_output: active_col_index = self._get_combo_index( DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, self.edit_output.output_calc.col_criteria) col_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, active_col_index) cell_matrix[1][0].pack_start(col_combo_label, False, False, 0) cell_matrix[1][1].pack_start(col_combo, False, False, 0) cell_matrix[1][0].show_all() cell_matrix[1][1].show_all() self.inputs_dict['calc_inputs'].append( (lambda: row_combo.get_active() > 0, lambda: row_combo.get_model()[row_combo.get_active()][1])) self.inputs_dict['calc_inputs'].append( (lambda: col_combo.get_active() > 0, lambda: col_combo.get_model()[col_combo.get_active()][1])) elif sel_option_id == options.LIST: regex_label = gtk.Label('Search:') regex_entry = gtk.Entry() regex_entry.set_width_chars(30) if self.edit_output: regex_entry.set_text(self.edit_output.output_calc.search_term) regex_helper = UIUtils.build_regex_helper_combo(regex_entry) hbox = gtk.HBox() hbox.pack_start(regex_entry, False, False, 0) hbox.pack_start(regex_helper, False, False, 0) cell_matrix[0][0].pack_start(regex_label, False, False, 0) cell_matrix[0][1].pack_start(hbox, False, False, 0) cell_matrix[0][0].show_all() cell_matrix[0][1].show_all() grouping_cat_label = gtk.Label("Grouping Category:") active_index = 0 if self.edit_output: active_index = self._get_combo_index( DBConstants.COMBO_GROUPS.LIST_OUTPUT_CALC_CATS, self.edit_output.output_calc.cat) grouping_cat_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.LIST_OUTPUT_CALC_CATS, active_index) cell_matrix[1][0].pack_start(grouping_cat_label, False, False, 0) cell_matrix[1][1].pack_start(grouping_cat_combo, False, False, 0) cell_matrix[1][0].show_all() cell_matrix[1][1].show_all() self.inputs_dict['calc_inputs'].append( (lambda: True, lambda: regex_entry.get_text())) self.inputs_dict['calc_inputs'].append( (lambda: grouping_cat_combo.get_active() > 0, lambda: grouping_cat_combo.get_model()[grouping_cat_combo. get_active()][1])) #Make sure we don't try to restore state on subsequent calls to this method #Note: outdated outputs will be removed from the database by create_config_window.py self.edit_output = None
def _build(self): vbox = gtk.VBox(spacing=5) linkage_label = gtk.Label('Segment Linkage:') linkage_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.FILTER_LINKAGE_OPTIONS, include_empty_option=False, active_index=(0 if self.edit_output and self.edit_output.chained else 1)) self.inputs_dict['seg_linkage'] = ( lambda: linkage_combo.get_active( ) >= 0, #Note: there is no "empty" option in this combo (hence >=) lambda: linkage_combo.get_model()[linkage_combo.get_active()][1] == DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS. FILTER_LINKAGE_OPTIONS].LINKED) linkage_hbox = gtk.HBox() linkage_hbox.pack_start(linkage_label, True, True, 0) linkage_hbox.pack_start(linkage_combo, True, True, 0) vbox.pack_start(linkage_hbox, False, False, 0) #table = gtk.Table(2, 2) grid = gtk.Grid() grid.set_row_spacing(5) cell_matrix = [] n_rows = 2 #table.get_property('n-rows') n_cols = 2 #table.get_property('n-columns') for row in range(n_rows): for col in range(n_cols): cell_hbox = gtk.HBox() if col == 0: cell_matrix.append([cell_hbox]) else: cell_matrix[row].append(cell_hbox) #table.attach(cell_matrix[row][col], col, col + 1, row, row + 1, gtk.EXPAND, gtk.EXPAND) grid.attach(cell_matrix[row][col], col, row, 1, 1) output_type_label = gtk.Label('Output Type:') active_index = 0 if self.edit_output: active_index = self._get_output_type_combo_index() output_type_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES, active_index) output_type_combo.connect( 'changed', lambda w: self._update_options_frame( cell_matrix, n_rows, n_cols, w.get_model().get(w.get_active_iter(), 1)[0])) if self.edit_output: self._update_options_frame( cell_matrix, n_rows, n_cols, output_type_combo.get_model().get( output_type_combo.get_active_iter(), 1)[0]) self.inputs_dict['calc_type'] = ( lambda: output_type_combo.get_active() > 0, lambda: output_type_combo.get_model()[output_type_combo.get_active()][1]) output_type_hbox = gtk.HBox() output_type_hbox.pack_start(output_type_label, True, True, 0) output_type_hbox.pack_start(output_type_combo, True, True, 0) vbox.pack_start(output_type_hbox, False, False, 0) vbox.pack_start(gtk.HSeparator(), False, False, 0) vbox.pack_start(grid, True, True, 0) self.add(vbox)
def _update_add_inputs(self, vbox): #remove previous children map(lambda child: vbox.remove(child), vbox.get_children()) self.inputs_dict['type_inputs'] = [] #get new combo value sel_opt = self.inputs_dict['filter_type'][1]() options = DBConstants.COMBO_OPTIONS[ DBConstants.COMBO_GROUPS.SEG_FILTER_TYPES] #add new children, based on new filter type if sel_opt == options.SPEAKER: treeview = self._build_codes_treeview( DBConstants.COMBO_GROUPS.SPEAKER_CODES, 'Select Speaker Codes:') vbox.pack_start(treeview, True, True, 0) self.inputs_dict['type_inputs'].append( (lambda: len( self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.SPEAKER_CODES)) > 0, lambda: self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.SPEAKER_CODES))) elif sel_opt == options.TIME: #table = gtk.Table(2, 2) grid = gtk.Grid() criteria_label = gtk.Label('Criteria:') #criteria_label.set_alignment(xalign=1.0, yalign=0.5) #table.attach(criteria_label, 0, 1, 0, 1) grid.attach(criteria_label, 0, 0, 1, 1) criteria_combo = UIUtils.build_options_combo( DBConstants.COMBO_GROUPS.SEG_FILTER_TIME) #table.attach(criteria_combo, 1, 2, 0, 1) grid.attach(criteria_combo, 1, 0, 1, 1) self.inputs_dict['type_inputs'].append( (lambda: criteria_combo.get_active() > 0, lambda: criteria_combo.get_model()[criteria_combo.get_active()][1])) time_label = gtk.Label('Time (h:m:s):') #time_label.set_alignment(xalign=1.0, yalign=0.5) #table.attach(time_label, 0, 1, 1, 2) grid.attach(time_label, 0, 1, 1, 1) time_inputs_box, hours_spinner, mins_spinner, secs_spinner = UIUtils.get_time_spinners( ) self.inputs_dict['type_inputs'].append( (lambda: hours_spinner.get_value_as_int() > 0 or mins_spinner. get_value_as_int() > 0 or secs_spinner.get_value_as_int() > 0, lambda: hours_spinner.get_value_as_int( ) * 60 * 60 + mins_spinner.get_value_as_int( ) * 60 + secs_spinner.get_value_as_int())) #table.attach(time_inputs_box, 1, 2, 1, 2) grid.attach(time_inputs_box, 1, 1, 1, 1) vbox.pack_start(grid, True, True, 0) elif sel_opt == options.SPEAKER_TYPE: treeview = self._build_codes_treeview( DBConstants.COMBO_GROUPS.SPEAKER_TYPES, 'Select Speaker Types:') vbox.pack_start(treeview, True, True, 0) self.inputs_dict['type_inputs'].append( (lambda: len( self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.SPEAKER_TYPES)) > 0, lambda: self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.SPEAKER_TYPES))) elif sel_opt == options.TARGET_LISTENER: treeview = self._build_codes_treeview( DBConstants.COMBO_GROUPS.TARGET_LISTENERS, 'Select Target Listeners:') vbox.pack_start(treeview, True, True, 0) self.inputs_dict['type_inputs'].append((lambda: len( self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.TARGET_LISTENERS) ) > 0, lambda: self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.TARGET_LISTENERS))) elif sel_opt == options.GRAMMATICALITY: treeview = self._build_codes_treeview( DBConstants.COMBO_GROUPS.GRAMMATICALITY, 'Select Grammaticality/Completeness options:') vbox.pack_start(treeview, True, True, 0) self.inputs_dict['type_inputs'].append((lambda: len( self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.GRAMMATICALITY) ) > 0, lambda: self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.GRAMMATICALITY))) elif sel_opt == options.UTTERANCE_TYPE: treeview = self._build_codes_treeview( DBConstants.COMBO_GROUPS.UTTERANCE_TYPES, 'Select Utterance Types:') vbox.pack_start(treeview, True, True, 0) self.inputs_dict['type_inputs'].append((lambda: len( self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.UTTERANCE_TYPES) ) > 0, lambda: self._get_treeview_combo_opts( treeview, DBConstants.COMBO_GROUPS.UTTERANCE_TYPES))) vbox.show_all()