Beispiel #1
0
    def _create_output(self, filters_frame, options_frame):
        if options_frame.validate() and self._validate():
            name = self.name_entry.get_text()
            desc = self.desc_entry.get_text()
            filters = filters_frame.get_filters()
            calc = options_frame.get_output_calc()
            chained = options_frame.get_seg_linkage()

            output = Output(name, desc, filters, calc, chained)

            self.action_callback(output)
            self.window.destroy()

        else:
            UIUtils.show_empty_form_dialog()
Beispiel #2
0
    def _create_filter(self):
        if self._validate():
            filter_type = self.inputs_dict['filter_type'][1]()
            options = DBConstants.COMBO_OPTIONS[
                DBConstants.COMBO_GROUPS.SEG_FILTER_TYPES]
            negate = self.inputs_dict['negate'][1]()

            args = []
            for arg_tuple in self.inputs_dict['type_inputs']:
                args.append(arg_tuple[1]())

            #instantiate the appropriate subclass based on the type of filter being created
            seg_filter = {
                options.SPEAKER:
                lambda: SpeakerCodeSegFilter(*args, negate=negate),
                options.TIME:
                lambda: TimeSegFilter(
                    *args, inclusive=False, negate=negate
                ),  #my fault for breaking the pattern by defining the constructor in this way - unfortunately now it's too late to change it, as ordered args are stored in the database for some apps...
                options.SPEAKER_TYPE:
                lambda: SpeakerTypeSegFilter(*args, negate=negate),
                options.TARGET_LISTENER:
                lambda: TargetListenerSegFilter(*args, negate=negate),
                options.GRAMMATICALITY:
                lambda: GrammaticalitySegFilter(*args, negate=negate),
                options.UTTERANCE_TYPE:
                lambda: UtteranceTypeSegFilter(*args, negate=negate),
                options.OVERLAPPING_VOCALS:
                lambda: OverlappingVocalsSegFilter(*args, negate=negate),
            }[filter_type]()

            self.window.destroy()
            self.callback(seg_filter)

        else:
            UIUtils.show_empty_form_dialog()
    def run(self):
        csv_path = self.csv_entry.get_text()
        wav_path = self.wav_entry.get_text()
        blocks_per_activity = self.blocks_spinner.get_value_as_int()

        activities = []
        if self.acts_treeview and self.acts_treeview.get_selection():
            model, sel_paths = self.acts_treeview.get_selection(
            ).get_selected_rows()

            for path in sel_paths:
                it = model.get_iter(path)
                activities.append(model.get_value(it, 0))

        environments = []
        if self.envs_treeview and self.envs_treeview.get_selection():
            model, sel_paths = self.envs_treeview.get_selection(
            ).get_selected_rows()

            for path in sel_paths:
                it = model.get_iter(path)
                environments.append(model.get_value(it, 0))

        is_valid = csv_path and wav_path and blocks_per_activity and len(
            activities) and len(environments)
        if is_valid:
            check2 = Check2(
                csv_path,
                wav_path,
                activities,
                environments,
                blocks_per_activity,
            )

            sel_test2s = None
            enough_blocks, counts_str = self.parser.have_enough_blocks(
                check2, False)
            if enough_blocks:
                print counts_str
                sel_test2s = self.parser.pick_rows(
                    check2, lambda filename: UIUtils.open_file(
                        'Please locate %s' % (filename),
                        filters=[UIUtils.WAV_FILE_FILTER],
                        save_last_location=True,
                        cur_location=wav_path), False)
            else:
                enough_blocks, counts_str = self.parser.have_enough_blocks(
                    check2, True)
                if enough_blocks:
                    print counts_str
                    if UIUtils.show_confirm_dialog(
                            'There are not enough unused rows left for some activities (see command window for row counts). If you proceed, the same row will be selected twice. Ok to continue?'
                    ):
                        sel_test2s = self.parser.pick_rows(
                            check2, lambda filename: UIUtils.open_file(
                                'Please locate %s' % (filename),
                                filters=[UIUtils.WAV_FILE_FILTER],
                                save_last_location=True,
                                cur_location=wav_path), True)
                else:
                    print counts_str
                    UIUtils.show_message_dialog(
                        'The input file does not contain enough blocks of the specified types. Please refer to the command window for a printout of the activity counts.'
                    )

            if sel_test2s:
                progress_dialog = ProgressDialog(title='Setting up...',
                                                 phases=[''])
                progress_dialog.show()

                db = BLLDatabase()
                check2.db_insert(db)
                check2.test2s = sel_test2s
                for i in range(len(check2.test2s)):
                    test2 = check2.test2s[i]
                    test2.check2_id = check2.db_id
                    test2.db_insert(db)

                    progress_dialog.set_fraction(
                        float(i + 1) / float(len(check2.test2s)))
                db.close()
                progress_dialog.ensure_finish()

                TestWindow(check2)
                if self.parser:
                    self.parser.close()
                self.window.destroy()

        else:
            UIUtils.show_empty_form_dialog()