示例#1
0
    def _create_config(self):
        if self._validate():
            #extract the output objects from the treeview model
            outputs = []
            model = self.outputs_treeview.get_model()
            row = 0
            while row < len(model):
                outputs.append(model[row][4])
                row += 1

            name = self.name_entry.get_text()
            desc = self.desc_entry.get_text()
            overview = self.output_overview.get_active()

            db = BLLDatabase()
            created = None
            #if editing, delete previous config from DB
            if self.edit_config:
                created = self.edit_config.created
                self.edit_config.db_delete(
                    db
                )  #this will also delete any associated outputs and entries in output_configs_to_outputs
                self.edit_config = None

            config = OutputConfig(name, desc, outputs, created, overview)
            config.db_insert(db)
            db.close()

            self.window.destroy()
            self.action_callback(config)

        else:
            UIUtils.show_message_dialog(
                'Please make sure that all of the fields have been filled out.',
                gtk.MessageType.WARNING)
示例#2
0
    def _finish(self):
        if self._validate_cur_test():
            self.save_input(mark_last_run=True, mark_as_completed=True)

            filename, check_results = UIUtils.save_file(
                filters=[UIUtils.CSV_FILE_FILTER],
                open_now_opt=True,
                save_last_location=True)

            if filename:
                exporter = ReliabilityExporter(self.check, filename)
                if exporter.export():
                    if check_results:
                        subprocess.Popen([
                            '%s' % DBConstants.SETTINGS.SPREADSHEET_PATH,
                            filename
                        ])
                    else:
                        UIUtils.show_message_dialog(
                            'Results exported successfully.')

                    self._exit(False)  #we have already saved above

                else:
                    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.'
                    )
示例#3
0
 def _ok(self):
     filters = self._get_filters()
     if self._validate_filters(filters):
         self.window.destroy()
         self.callback(filters)
     else:
         UIUtils.show_message_dialog('Please make sure that all combo boxes are set, with the exception of the last "conjunction" box.')
示例#4
0
 def _remove_output(self):
     model, it = self.outputs_treeview.get_selection().get_selected()
     if it:
         if UIUtils.show_confirm_dialog(
                 'Are you sure you want to delete this output?'):
             model.remove(it)
     else:
         UIUtils.show_message_dialog('Please select a row.',
                                     gtk.MessageType.WARNING)
示例#5
0
    def _edit_output(self):
        model, it = self.outputs_treeview.get_selection().get_selected()
        if it:
            OutputWindow(
                lambda edited_output: self._edit_output_callback(
                    edited_output, it),
                model.get(it, 4)[0])

        else:
            UIUtils.show_message_dialog('Please select a row.',
                                        gtk.MessageType.WARNING)
示例#6
0
    def _edit_config(self, treeview):
        model, it = treeview.get_selection().get_selected()
        if it:
            config = model.get(it, 4)[0]
            ConfigWindow(
                lambda edited_config: self._edit_callback(
                    treeview.get_model(), edited_config, it), config)

        else:
            UIUtils.show_message_dialog('Please select a row.',
                                        gtk.MessageTYpe.WARNING)
示例#7
0
    def save_and_export(self):
        if self._check_completion():
            checkbuttons = []
            include_trans_check = gtk.CheckButton('Include Transcription')
            checkbuttons.append(include_trans_check)
            open_now_check = gtk.CheckButton('Open Immediately')
            open_now_check.set_active(True)
            checkbuttons.append(open_now_check)

            filename, results = UIUtils.show_file_dialog_with_checks(
                'Save File',
                [UIUtils.CSV_FILE_FILTER, UIUtils.ALL_FILE_FILTER],
                gtk.FileChooserAction.SAVE,
                gtk.STOCK_SAVE,
                checkbuttons,
                save_last_location=True)

            if filename:
                progress_dialog = ProgressDialog(
                    title='Saving...',
                    phases=[
                        'Saving records to DB', 'Matching DB records to rows',
                        'Writing rows to file'
                    ])
                progress_dialog.show()

                self.save(True, progress_dialog)
                progress_dialog.next_phase()

                if not filename.lower().endswith('.csv'):
                    filename += '.csv'

                exporter = Reliability2Exporter(filename, self.check2)
                exporter.export(
                    results[0],
                    progress_update_fcn=progress_dialog.set_fraction,
                    progress_next_fcn=progress_dialog.next_phase)
                exporter.close()
                progress_dialog.ensure_finish()

                self.handler_man.block_handler(self.window, 'destroy')
                self.window.destroy()
                #note: there is no need for a corresponding self.handler_man.unblock_handler() call, since the object the handler is operating upon (the window) is destroyed)

                #show immediately, if requested
                if results[1]:
                    subprocess.Popen([
                        '%s' % DBConstants.SETTINGS.SPREADSHEET_PATH, filename
                    ])
                else:
                    UIUtils.show_message_dialog(
                        'Results exported successfully!')
示例#8
0
    def _export(self, treeview, col_headers, db):
        write_filename, open_now = UIUtils.save_file(filters=[UIUtils.CSV_FILE_FILTER, UIUtils.ALL_FILE_FILTER], open_now_opt=True)
        if write_filename: #if they didn't click cancel
            #lag_time_cutoff = float( UIUtils.show_entry_dialog(None, 'Lag time cutoff for counts: ', default_text='2', validate_regex=r'^-?\d+(\.\d+)?$', invalid_msg='Please enter a number.') )
            lag_time_cutoff = 2.0

	if write_filename and lag_time_cutoff != None: #if user did not click cancel (note: lag time cutoff could be 0)
            if not write_filename.lower().endswith('.csv'):
                write_filename += '.csv'

            try:
                csv_file = open(write_filename, 'wb')
                writer = csv.writer(csv_file, quoting=csv.QUOTE_ALL)

                cols = treeview.get_columns()
                visible_col_indices = filter(lambda i: cols[i].get_visible(), range(len(cols)))

                filtered_headers = [col_headers[i] for i in visible_col_indices]
                writer.writerow(filtered_headers)

                progress_dialog = ProgressDialog(title='Exporting to file', phases=['Exporting...'])
                progress_dialog.show()

                num_rows = len(treeview.get_model())
                row_index = 1 #this is awkward, but there is no way to pull all the rows out of the model in one shot, so we have to use a non-indexed for loop and manually track the index
                for row in treeview.get_model():
                    filtered_row = [row[i] for i in visible_col_indices]
                    writer.writerow(filtered_row)

                    progress_dialog.set_fraction(float(row_index) / float(num_rows))
                    row_index += 1

                # export_stats = self._get_export_stats(lag_time_cutoff, db, col_headers)
                # if export_stats:
                #     for row in export_stats:
                #         writer.writerow(row)

                progress_dialog.ensure_finish()
                csv_file.close()

                if open_now:
                    subprocess.Popen(['%s' % DBConstants.SETTINGS.SPREADSHEET_PATH, write_filename])
                else:
                    UIUtils.show_message_dialog('Data exported successfully.')
                    

                #UIUtils.show_message_dialog('Data export completed.')
            except Exception as err:
                UIUtils.show_message_dialog('Unable to export data - please make sure the destination file is not already open in another program.')
                raise err
示例#9
0
    def _get_sel_row_clip_info(self, col_headers, treeview):
        start = None
        end = None
        
        model, it = treeview.get_selection().get_selected()
        if it:
            #find start and end column indices (if not already found)
            if self.sound_col_fcns == None:
                start_index, end_index, dur_index, el_time_index = self._get_sound_col_indices(col_headers)

                if start_index > -1 and end_index > -1:
                    self.sound_col_fcns = (
                        lambda model, it: self._get_abs_time(model.get_value(it, start_index)),
                        lambda model, it: self._get_abs_time(model.get_value(it, end_index)),
                        )
                    
                elif dur_index > -1 and el_time_index > -1:
                    self.sound_col_fcns = (
                        lambda model, it: self._get_abs_time(float(model.get_value(it, el_time_index))),
                        lambda model, it: self._get_abs_time(float(model.get_value(it, el_time_index)) + float(model.get_value(it, dur_index))),
                        )

                else:
                    error_msg = 'The program was unable to derive the sound clip start and end times from the columns.\n'
                    error_msg += '\nColumn headers must include:\n'
                    error_msg += '-One start name: %s\n' % (' or '.join(['"%s"' % (name) for name in MainWindow.START_COL_NAMES]))
                    error_msg += '-One end name: %s\n' % (' or '.join(['"%s"' % (name) for name in MainWindow.END_COL_NAMES]))
                    error_msg += '\nOr alternatively:\n'
                    error_msg += '-One duration name: %s\n' % (' or '.join(['"%s"' % (name) for name in MainWindow.DUR_COL_NAMES]))
                    error_msg += '-One elapsed time name: %s\n' % (' or '.join(['"%s"' % (name) for name in MainWindow.EL_TIME_COL_NAMES]))

                    error_msg += '\nPlease make sure your input spreadsheet contains one of these pairs.'

                    UIUtils.show_message_dialog(error_msg)

            if self.sound_col_fcns != None and self.wav_filename:
                try:
                    start = float( self.sound_col_fcns[0](treeview.get_model(), it) )
                    end = float( self.sound_col_fcns[1](treeview.get_model(), it) )
                except ValueError as err:
                    UIUtils.show_message_dialog('The program was unable to determine start and end times for this row.')
                    start = None
                    end = None
                    print err

        else:
            UIUtils.show_no_sel_dialog()

        return start, end
示例#10
0
    def _process(self, src, dest):
        in_files = None
        out_files = None

        if src and os.path.exists(src):
            src = src.replace('\\', '/')

            if self.filter_type == FilterWindow.FILTER_TYPES.FILE:
                if not src.endswith('.csv'):
                    src += '.csv'
            elif self.filter_type == FilterWindow.FILTER_TYPES.FOLDER:
                if src.endswith('/'):
                    src = src[:-1]
            
            if os.path.isdir(src):
                in_files = map(lambda name: name.replace('\\', '/'), glob.glob('%s/*.csv' % (src)))
            else:
                in_files = [src]

        else:
            UIUtils.show_message_dialog('Source path does not exist!')
            return

        if dest and os.path.exists(dest):
            dest = dest.replace('\\', '/')
            if dest.endswith('/'):
                dest = dest[:-1]
            out_files = map(lambda name: '%s/%s-noNaps.csv' % (dest, os.path.basename(name)[:-4]), in_files)

        else:
            UIUtils.show_message_dialog('Destination path does not exist!')
            return

        self.window.destroy()
        prog_diag = ProgressDialog(
            title='Processing...',
            phases=['Please Wait']
        )
        prog_diag.show()

        db = BLLDatabase()
        
        for i in range(len(in_files)):
            Naptime.filter_file(db, in_files[i], out_files[i])
            prog_diag.set_fraction(float(i + 1) / float(len(in_files)))
            
        db.close()
        prog_diag.ensure_finish()        
示例#11
0
    def _check_input(self, file1_path, file2_path, file1_name, file2_name):
        if file1_path and file2_path:
            bad_paths = []
            for path in [file1_path, file2_path]:
                if not os.path.exists(path):
                    bad_paths.append(path)

            if bad_paths:
                message = 'The following files could not be located.\n'
                for path in bad_paths:
                    message += '\n- %s' % (path)
                message += '\n\nPlease double-check the paths and try again.'
                UIUtils.show_message_dialog(message)

            else:
                self._compare(file1_path, file2_path, file1_name, file2_name)

        else:
            UIUtils.show_message_dialog('Please select two files.')
示例#12
0
    def _run_config(self, treeview):
        model, it = treeview.get_selection().get_selected()
        if it:
            config = model.get(it, 4)[0]
            trs_folder = UIUtils.open_folder(title='Select TRS Folder...')

            if trs_folder:  #will be None if user clicked 'cancel' or closed the dialog window
                export_folder = UIUtils.open_folder(
                    title='Select Output Folder...')
                if export_folder:
                    #trs_filenames = glob.glob(trs_folder + '\\*.trs')
                    trs_filenames = self._get_trs_filenames(trs_folder)
                    export_filenames = map(
                        lambda name: '%s/%s-stats.csv' %
                        (export_folder, os.path.basename(name)[:-4]),
                        trs_filenames)

                    phases = [
                        'File %d of %d' % (i + 1, len(trs_filenames))
                        for i in range(len(trs_filenames))
                    ]
                    dialog = ProgressDialog('Working...', phases)
                    dialog.show()

                    for j in range(len(trs_filenames)):
                        exporter = StatsExporter(
                            config,
                            trs_filenames[j],
                            export_filenames[j],
                            summary_filename=export_folder + "/summary.csv")
                        exporter.export()
                        dialog.set_fraction(1.0)
                        if j < len(trs_filenames) - 1:
                            dialog.next_phase()

                    dialog.ensure_finish()

                    UIUtils.show_message_dialog('Export successful.')

        else:
            UIUtils.show_no_sel_dialog()
示例#13
0
    def delete_check(self, treeview):
        model, sel_paths = treeview.get_selection().get_selected_rows()
        if sel_paths:
            if UIUtils.show_confirm_dialog(
                    'Are you sure you want to delete this row?'):
                it = model.get_iter(sel_paths[0])
                check2_id = model.get_value(it, 0)

                db = BLLDatabase()
                #this is a little awkward, but it works for now...
                check2 = Check2.db_select(db, ids=[check2_id])[0]
                if check2.db_delete(db) > 0:
                    model.remove(it)
                else:
                    UIUtils.show_message_dialog(
                        'An error has prevented this row from being deleted. Please check the log files for details.',
                        gtk.MESSAGE_ERROR)
                db.close()

        else:
            UIUtils.show_no_sel_dialog()
示例#14
0
    def update_db(self, path):
        prog_diag = ProgressDialog(title='Processing...',
                                   phases=['Please Wait'])
        prog_diag.show()

        db = BLLDatabase()
        error_filenames = Naptime.update_naptime_data(db,
                                                      path,
                                                      prog_diag=prog_diag)
        db.close()
        prog_diag.ensure_finish()

        if error_filenames:
            UIUtils.show_message_dialog(
                'Unable to process the following files - see the log file for details:\n'
                + '\n'.join(map(os.path.basename, error_filenames)),
                dialog_type=gtk.MessageType.ERROR)

        else:
            UIUtils.show_message_dialog(
                'Naptime database table updated successfully.')
            self.window.destroy()
示例#15
0
    def _confirm_delete(self, treeview):
        (model, it) = treeview.get_selection().get_selected()
        db_id = model.get_value(it, 0) if it else None

        if db_id != None:
            response = UIUtils.show_confirm_dialog(
                'Are you sure you want to delete the selected check?')

            if response:
                db = BLLDatabase()
                rows_deleted = Check.db_select(db, [db_id])[0].db_delete(db)
                db.close()

                if rows_deleted > 0:
                    model.remove(it)

                else:
                    UIUtils.show_message_dialog(
                        'An error occurred and the check could not be deleted.'
                    )

        else:
            UIUtils.show_no_sel_dialog()
示例#16
0
    def _validate_cur_test(self):
        #validate w_context form
        w_context_valid = (
            self.w_form.type_combo.get_active() != 0 and
            int(self.w_form.syllables_spinner.get_adjustment().get_value()) > 0
            and BackendUtils.is_float(self.w_form.user_start_entry.get_text())
            and BackendUtils.is_float(self.w_form.user_end_entry.get_text()))

        #print 'w_context_valid: %s' % str(w_context_valid)

        wo_context_valid = (not self.wo_context_checkbox.get_active() or int(
            self.wo_form.syllables_spinner.get_adjustment().get_value()) > 0)

        #print 'wo_context_valid: %s' % str(wo_context_valid)

        is_valid = w_context_valid and wo_context_valid

        if is_valid:
            #make sure user-boundaries have been updated
            #note: they are guarenteed to contain floats at this point because of the w_context_valid condition
            user_start = float(self.w_form.user_start_entry.get_text())
            user_end = float(self.w_form.user_end_entry.get_text())
            cur_test = self.check.tests[self.check.test_index]

            is_valid = (cur_test.seg.start != user_start
                        or cur_test.seg.end != user_end)
            if not is_valid:
                is_valid = UIUtils.show_confirm_dialog(
                    'Segment boundaries have not been adjusted. Continue anyway?'
                )

        else:
            UIUtils.show_message_dialog(
                'Please ensure that all of the inputs have a correct value.')

        return is_valid
示例#17
0
    def create_check(self):
        error_msg = self.validate_form()

        if error_msg:
            UIUtils.show_message_dialog(error_msg)

        else:
            filters = self.filters_frame.get_filters()

            check = Check(
                self.form.name_entry.get_text(),
                self.form.input_file_entry.get_text(),
                self.form.wav_file_entry.get_text(),
                self.form.num_segs_spinner.get_value_as_int(),
                self.form.context_pad_spinner.get_value_as_int(),
                [],
                0,
                filters=filters,
                pick_randomly=self.form.rand_checkbox.get_active(),
            )

            parser = None
            progress_dialog = ProgressDialog(
                title='Loading File',
                phases=['Parsing file...', 'Setting up...'])
            segs = []

            #TRS files
            if check.input_filename.lower().endswith('.trs'):
                parser = TRSParser(check.input_filename)
                progress_dialog.show()
                segs = parser.parse(
                    progress_update_fcn=progress_dialog.set_fraction,
                    progress_next_phase_fcn=progress_dialog.next_phase,
                    validate=False,
                    seg_filters=check.filters)

            #CSV files
            else:
                parser = CSVParser(check.input_filename)
                progress_dialog.show()
                segs = parser.parse(
                    progress_update_fcn=progress_dialog.set_fraction,
                    seg_filters=check.filters)

            progress_dialog.next_phase()

            if check.pick_randomly:
                #segs = ParserTools.pick_rand_segs(check.num_segs, segs)
                segs = ParserTools.hacked_pick_rand_segs(
                    check.num_segs, segs,
                    os.path.basename(check.input_filename))
            else:
                segs = ParserTools.pick_contiguous_segs(check.num_segs, segs)
            progress_dialog.set_fraction(1.0)

            if len(segs) < check.num_segs:
                progress_dialog.ensure_finish(
                )  #close the progress bar (even though there's still one phase left)
                UIUtils.show_message_dialog(
                    'The input file does not contain enough segments of the specified types.',
                    dialog_type=gtk.MessageType.ERROR)

            else:
                db = BLLDatabase()
                check.db_insert(db)

                for i in range(len(segs)):
                    if segs[i].db_id == None:
                        segs[i].db_insert(db)

                    test = Test(
                        check.db_id,
                        None,
                        None,
                        None,
                        segs[i],
                        None,
                        check.default_context_padding,
                    )
                    test.db_insert(db)
                    check.tests.append(test)

                    progress_dialog.set_fraction(
                        float(i + 1) / float(check.num_segs))

                db.close()
                progress_dialog.ensure_finish()

                self.window.destroy()
                TestWindow(check)
示例#18
0
 def _finish(self):
     self.window.destroy()
     UIUtils.show_message_dialog('Testing complete! Thanks for your help.')
示例#19
0
    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()