Beispiel #1
0
    def view_data_file_head(self):
        """
        view first parts of data file
        """
        if self.tw_data_files.selectedIndexes() or self.tw_data_files.rowCount(
        ) == 1:
            if self.tw_data_files.rowCount() == 1:
                data_file_path = project_functions.media_full_path(
                    self.tw_data_files.item(0, 0).text(), self.project_path)
            else:
                data_file_path = project_functions.media_full_path(
                    self.tw_data_files.item(
                        self.tw_data_files.selectedIndexes()[0].row(),
                        0).text(), self.project_path)

            file_parameters = utilities.check_txt_file(data_file_path)
            if "error" in file_parameters:
                QMessageBox.critical(
                    self, programName,
                    f"Error on file {data_file_path}: {file_parameters['error']}"
                )
                return
            header = utilities.return_file_header(data_file_path)

            if header:

                w = dialog.View_data_head()
                w.setWindowTitle(f"Data file: {Path(data_file_path).name}")
                w.setWindowFlags(Qt.WindowStaysOnTopHint)
                w.label.setVisible(False)
                w.le.setVisible(False)

                w.tw.setColumnCount(file_parameters["fields number"])
                w.tw.setRowCount(len(header))

                for row in range(len(header)):
                    for col, v in enumerate(header[row].split(
                            file_parameters["separator"])):
                        w.tw.setItem(row, col, QTableWidgetItem(v))

                w.exec_()

            else:
                QMessageBox.critical(self, programName,
                                     f"Error on file {data_file_path}")

        else:
            QMessageBox.warning(self, programName, "Select a data file")
Beispiel #2
0
    def extract_wav(self):
        """
        extract wav of all media files loaded in player #1
        """

        if self.cbVisualizeSpectrogram.isChecked() or self.cb_visualize_waveform.isChecked():
            flag_wav_produced = False
            # check if player 1 is selected
            flag_player1 = False
            for row in range(self.twVideo1.rowCount()):
                if self.twVideo1.cellWidget(row, 0).currentText() == "1":
                    flag_player1 = True

            if not flag_player1:
                QMessageBox.critical(self, programName, "The player #1 is not selected")
                self.cbVisualizeSpectrogram.setChecked(False)
                self.cb_visualize_waveform.setChecked(False)
                return

            '''
            if dialog.MessageDialog(programName, ("You choose to visualize the spectrogram or waveform for the media in player #1.<br>"
                                                  "The WAV will be extracted from the media files, be patient"), [YES, NO]) == YES:
            '''
            if True:

                w = dialog.Info_widget()
                w.resize(350, 100)
                w.setWindowFlags(Qt.WindowStaysOnTopHint)
                w.setWindowTitle("BORIS")
                w.label.setText("Extracting WAV from media files...")

                for row in range(self.twVideo1.rowCount()):
                    # check if player 1
                    if self.twVideo1.cellWidget(row, 0).currentText() != "1":
                        continue

                    media_file_path = project_functions.media_full_path(self.twVideo1.item(row, MEDIA_FILE_PATH_IDX).text(),
                                                                        self.project_path)
                    if self.twVideo1.item(row, HAS_AUDIO_IDX).text() == "False":
                        QMessageBox.critical(self, programName, f"The media file {media_file_path} do not seem to have audio")
                        flag_wav_produced = False
                        break

                    if os.path.isfile(media_file_path):
                        w.show()
                        QApplication.processEvents()

                        if utilities.extract_wav(self.ffmpeg_bin, media_file_path, self.tmp_dir) == "":
                            QMessageBox.critical(self, programName,
                                                 f"Error during extracting WAV of the media file {media_file_path}")
                            flag_wav_produced = False
                            break

                        w.hide()

                        flag_wav_produced = True
                    else:
                        QMessageBox.warning(self, programName, f"<b>{media_file_path}</b> file not found")

                if not flag_wav_produced:
                    self.cbVisualizeSpectrogram.setChecked(False)
                    self.cb_visualize_waveform.setChecked(False)
            '''
Beispiel #3
0
    def plot_data_file(self):
        """
        show plot
        check if data can be plotted
        """

        if self.pb_plot_data.text() == "Show plot":

            if self.tw_data_files.selectedIndexes() or self.tw_data_files.rowCount() == 1:

                if self.tw_data_files.rowCount() == 1:
                    row_idx = 0
                else:
                    row_idx = self.tw_data_files.selectedIndexes()[0].row()

                filename = self.tw_data_files.item(row_idx, PLOT_DATA_FILEPATH_IDX).text()
                columns_to_plot = self.tw_data_files.item(row_idx, PLOT_DATA_COLUMNS_IDX).text()
                plot_title = self.tw_data_files.item(row_idx, PLOT_DATA_PLOTTITLE_IDX).text()

                # load converters in dictionary
                if self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text():
                    column_converter = eval(self.tw_data_files.item(row_idx, PLOT_DATA_CONVERTERS_IDX).text())
                else:
                    column_converter = {}

                variable_name  = self.tw_data_files.item(row_idx, PLOT_DATA_VARIABLENAME_IDX).text()
                time_interval = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEINTERVAL_IDX).text())
                time_offset = int(self.tw_data_files.item(row_idx, PLOT_DATA_TIMEOFFSET_IDX).text())

                substract_first_value = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_SUBSTRACT1STVALUE_IDX).currentText()

                plot_color = self.tw_data_files.cellWidget(row_idx, PLOT_DATA_PLOTCOLOR_IDX).currentText()

                data_file_path = project_functions.media_full_path(filename, self.project_path)

                if not data_file_path:
                    QMessageBox.critical(self, programName, (f"Data file not found:\n{filename}\n"
                                                             "If the file path is not stored the data file "
                                                             "must be in the same directory than your project"))
                    return

                self.test = plot_data_module.Plot_data(data_file_path,
                                                  time_interval,  # time interval
                                                  time_offset,   # time offset
                                                  plot_color,    # plot style
                                                  plot_title,    # plot title
                                                  variable_name,
                                                  columns_to_plot,
                                                  substract_first_value,
                                                  self.converters,
                                                  column_converter,
                                                  log_level=logging.getLogger().getEffectiveLevel()
                                                  )

                if self.test.error_msg:
                    QMessageBox.critical(self, programName, f"Impossible to plot data:\n{self.test.error_msg}")
                    del self.test
                    return

                self.test.setWindowFlags(Qt.WindowStaysOnTopHint)
                self.test.show()
                self.test.update_plot(0)
                self.pb_plot_data.setText("Close plot")

            else:
                QMessageBox.warning(self, programName, "Select a data file")

        else: # close plot
            self.test.close_plot()
            self.pb_plot_data.setText("Show plot")
Beispiel #4
0
 def test_project_file_not_found(self):
     assert project_functions.media_full_path(
         "geese1.xxx",
         os.getcwd() + "/files/test.xxx.boris") == ""
Beispiel #5
0
 def test_file_and_dir(self):
     assert project_functions.media_full_path(
         "geese1.mp4",
         os.getcwd() +
         "/files/test.boris") == os.getcwd() + "/files/geese1.mp4"