Skip to content

Commit

Permalink
remember the export settings for the Batch Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Feb 1, 2024
1 parent d6b23be commit db45fcc
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 49 deletions.
159 changes: 153 additions & 6 deletions src/asammdf/gui/widgets/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def __init__(
self.lin_database_list.setItemWidget(item, widget)
item.setSizeHint(widget.sizeHint())

self.restore_export_setttings()
self.connect_export_updates()

def set_raster_type(self, event):
if self.raster_type_channel.isChecked():
self.raster_channel.setEnabled(True)
Expand Down Expand Up @@ -1315,7 +1318,7 @@ def apply_processing(self, event):
except ImportError:
MessageBox.critical(
self,
"Export to HDF5 unavailale",
"export_batch to HDF5 unavailale",
"h5py package not found; export to HDF5 is unavailable",
)
return
Expand All @@ -1327,7 +1330,7 @@ def apply_processing(self, event):
except ImportError:
MessageBox.critical(
self,
"Export to mat v7.3 unavailale",
"export_batch to mat v7.3 unavailale",
"hdf5storage package not found; export to mat 7.3 is unavailable",
)
return
Expand All @@ -1337,7 +1340,7 @@ def apply_processing(self, event):
except ImportError:
MessageBox.critical(
self,
"Export to mat v4 and v5 unavailale",
"export_batch to mat v4 and v5 unavailale",
"scipy package not found; export to mat is unavailable",
)
return
Expand All @@ -1348,7 +1351,7 @@ def apply_processing(self, event):
except ImportError:
MessageBox.critical(
self,
"Export to parquet unavailale",
"export_batch to parquet unavailale",
"fastparquet package not found; export to parquet is unavailable",
)
return
Expand Down Expand Up @@ -1610,9 +1613,9 @@ def apply_processing_thread(self, progress):
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/export.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
progress.signals.setWindowIcon.emit(icon)
progress.signals.setWindowTitle.emit(f"Export measurement {mdf_index+1} of {count}")
progress.signals.setWindowTitle.emit(f"export_batch measurement {mdf_index+1} of {count}")
progress.signals.setLabelText.emit(
f"Exporting measurement {mdf_index+1} of {count} to {output_format} (be patient this might take a while)\n{source_file}"
f"export_batching measurement {mdf_index+1} of {count} to {output_format} (be patient this might take a while)\n{source_file}"
)

delimiter = self.delimiter.text() or ","
Expand Down Expand Up @@ -1904,3 +1907,147 @@ def load_filter_list(self, event=None, file_name=None):
else:
items.sort(key=lambda x: x.name)
self.filter_tree.addTopLevelItems(items)

def connect_export_updates(self):
self.output_format.currentTextChanged.connect(self.store_export_setttings)

self.mdf_version.currentTextChanged.connect(self.store_export_setttings)
self.mdf_compression.currentTextChanged.connect(self.store_export_setttings)
self.mdf_split.stateChanged.connect(self.store_export_setttings)
self.mdf_split_size.valueChanged.connect(self.store_export_setttings)

self.single_time_base.stateChanged.connect(self.store_export_setttings)
self.time_from_zero.stateChanged.connect(self.store_export_setttings)
self.time_as_date.stateChanged.connect(self.store_export_setttings)
self.raw.stateChanged.connect(self.store_export_setttings)
self.use_display_names.stateChanged.connect(self.store_export_setttings)
self.reduce_memory_usage.stateChanged.connect(self.store_export_setttings)
self.export_compression.currentTextChanged.connect(self.store_export_setttings)
self.empty_channels.currentTextChanged.connect(self.store_export_setttings)

self.single_time_base_csv.stateChanged.connect(self.store_export_setttings)
self.time_from_zero_csv.stateChanged.connect(self.store_export_setttings)
self.time_as_date_csv.stateChanged.connect(self.store_export_setttings)
self.raw_csv.stateChanged.connect(self.store_export_setttings)
self.add_units.stateChanged.connect(self.store_export_setttings)
self.doublequote.stateChanged.connect(self.store_export_setttings)
self.use_display_names_csv.stateChanged.connect(self.store_export_setttings)
self.empty_channels_csv.currentTextChanged.connect(self.store_export_setttings)
self.delimiter.editingFinished.connect(self.store_export_setttings)
self.escapechar.editingFinished.connect(self.store_export_setttings)
self.lineterminator.editingFinished.connect(self.store_export_setttings)
self.quotechar.editingFinished.connect(self.store_export_setttings)
self.quoting.currentTextChanged.connect(self.store_export_setttings)

self.single_time_base_mat.stateChanged.connect(self.store_export_setttings)
self.time_from_zero_mat.stateChanged.connect(self.store_export_setttings)
self.time_as_date_mat.stateChanged.connect(self.store_export_setttings)
self.raw_mat.stateChanged.connect(self.store_export_setttings)
self.use_display_names_mat.stateChanged.connect(self.store_export_setttings)
self.reduce_memory_usage_mat.stateChanged.connect(self.store_export_setttings)
self.empty_channels_mat.currentTextChanged.connect(self.store_export_setttings)
self.export_compression_mat.currentTextChanged.connect(self.store_export_setttings)
self.mat_format.currentTextChanged.connect(self.store_export_setttings)
self.oned_as.currentTextChanged.connect(self.store_export_setttings)

def restore_export_setttings(self):
self.output_format.setCurrentText(self._settings.value("export_batch", "MDF"))

self.mdf_version.setCurrentText(self._settings.setValue("export_batch/MDF/version", "4.10"))
self.mdf_compression.setCurrentText(self._settings.value("export_batch/MDF/compression", "transposed deflate"))
self.mdf_split.setChecked(self._settings.value("export_batch/MDF/split_data_blocks", True, type=bool))
self.mdf_split_size.setValue(self._settings.value("export_batch/MDF/split_size", 4, type=int))

self.single_time_base.setChecked(self._settings.value("export_batch/HDF5/single_time_base", False, type=bool))
self.time_from_zero.setChecked(self._settings.value("export_batch/HDF5/time_from_zero", False, type=bool))
self.time_as_date.setChecked(self._settings.value("export_batch/HDF5/time_as_date", False, type=bool))
self.raw.setChecked(self._settings.value("export_batch/HDF5/raw", False, type=bool))
self.use_display_names.setChecked(self._settings.value("export_batch/HDF5/use_display_names", False, type=bool))
self.reduce_memory_usage.setChecked(
self._settings.value("export_batch/HDF5/reduce_memory_usage", False, type=bool)
)
self.export_compression.setCurrentText(self._settings.value("export_batch/HDF5/export_compression", "gzip"))
self.empty_channels.setCurrentText(self._settings.value("export_batch/HDF5/empty_channels", "skip"))

self.single_time_base_csv.setChecked(
self._settings.value("export_batch/CSV/single_time_base_csv", False, type=bool)
)
self.time_from_zero_csv.setChecked(
self._settings.value("export_batch/CSV/time_from_zero_csv", False, type=bool)
)
self.time_as_date_csv.setChecked(self._settings.value("export_batch/CSV/time_as_date_csv", False, type=bool))
self.raw_csv.setChecked(self._settings.value("export_batch/CSV/raw_csv", False, type=bool))
self.add_units.setChecked(self._settings.value("export_batch/CSV/add_units", False, type=bool))
self.doublequote.setChecked(self._settings.value("export_batch/CSV/doublequote", False, type=bool))
self.use_display_names_csv.setChecked(
self._settings.value("export_batch/CSV/use_display_names_csv", False, type=bool)
)
self.empty_channels_csv.setCurrentText(self._settings.value("export_batch/CSV/empty_channels_csv", "skip"))
self.delimiter.setText(self._settings.value("export_batch/CSV/delimiter", ","))
self.escapechar.setText(self._settings.value("export_batch/CSV/escapechar", ""))
self.lineterminator.setText(self._settings.value("export_batch/CSV/lineterminator", r"\r\n"))
self.quotechar.setText(self._settings.value("export_batch/CSV/quotechar", '"'))
self.quoting.setCurrentText(self._settings.value("export_batch/CSV/quoting", "MINIMAL"))

self.single_time_base_mat.setChecked(
self._settings.value("export_batch/MAT/single_time_base_mat", False, type=bool)
)
self.time_from_zero_mat.setChecked(
self._settings.value("export_batch/MAT/time_from_zero_mat", False, type=bool)
)
self.time_as_date_mat.setChecked(self._settings.value("export_batch/MAT/time_as_date_mat", False, type=bool))
self.raw_mat.setChecked(self._settings.value("export_batch/MAT/raw_mat", False, type=bool))
self.use_display_names_mat.setChecked(
self._settings.value("export_batch/MAT/use_display_names_mat", False, type=bool)
)
self.reduce_memory_usage_mat.setChecked(
self._settings.value("export_batch/MAT/reduce_memory_usage_mat", False, type=bool)
)
self.empty_channels_mat.setCurrentText(self._settings.value("export_batch/MAT/empty_channels_mat", "skip"))
self.export_compression_mat.setCurrentText(
self._settings.value("export_batch/MAT/export_compression_mat", "enabled")
)
self.mat_format.setCurrentText(self._settings.value("export_batch/MAT/mat_format", "4"))
self.oned_as.setCurrentText(self._settings.value("export_batch/MAT/oned_as", "row"))

def store_export_setttings(self, *args):
self._settings.setValue("export_batch", self.output_format.currentText())

self._settings.setValue("export_batch/MDF/version", self.mdf_version.currentText())
self._settings.setValue("export_batch/MDF/compression", self.mdf_compression.currentText())
self._settings.setValue("export_batch/MDF/split_data_blocks", self.mdf_split.isChecked())
self._settings.setValue("export_batch/MDF/split_size", self.mdf_split_size.value())

self._settings.setValue("export_batch/HDF5/single_time_base", self.single_time_base.isChecked())
self._settings.setValue("export_batch/HDF5/time_from_zero", self.time_from_zero.isChecked())
self._settings.setValue("export_batch/HDF5/time_as_date", self.time_as_date.isChecked())
self._settings.setValue("export_batch/HDF5/raw", self.raw.isChecked())
self._settings.setValue("export_batch/HDF5/use_display_names", self.use_display_names.isChecked())
self._settings.setValue("export_batch/HDF5/reduce_memory_usage", self.reduce_memory_usage.isChecked())
self._settings.setValue("export_batch/HDF5/export_compression", self.export_compression.currentText())
self._settings.setValue("export_batch/HDF5/empty_channels", self.empty_channels.currentText())

self._settings.setValue("export_batch/CSV/single_time_base_csv", self.single_time_base_csv.isChecked())
self._settings.setValue("export_batch/CSV/time_from_zero_csv", self.time_from_zero_csv.isChecked())
self._settings.setValue("export_batch/CSV/time_as_date_csv", self.time_as_date_csv.isChecked())
self._settings.setValue("export_batch/CSV/raw_csv", self.raw_csv.isChecked())
self._settings.setValue("export_batch/CSV/add_units", self.add_units.isChecked())
self._settings.setValue("export_batch/CSV/doublequote", self.doublequote.isChecked())
self._settings.setValue("export_batch/CSV/use_display_names_csv", self.use_display_names_csv.isChecked())
self._settings.setValue("export_batch/CSV/empty_channels_csv", self.empty_channels_csv.currentText())
self._settings.setValue("export_batch/CSV/delimiter", self.delimiter.text())
self._settings.setValue("export_batch/CSV/escapechar", self.escapechar.text())
self._settings.setValue("export_batch/CSV/lineterminator", self.lineterminator.text())
self._settings.setValue("export_batch/CSV/quotechar", self.quotechar.text())
self._settings.setValue("export_batch/CSV/quoting", self.quoting.currentText())

self._settings.setValue("export_batch/MAT/single_time_base_mat", self.single_time_base_mat.isChecked())
self._settings.setValue("export_batch/MAT/time_from_zero_mat", self.time_from_zero_mat.isChecked())
self._settings.setValue("export_batch/MAT/time_as_date_mat", self.time_as_date_mat.isChecked())
self._settings.setValue("export_batch/MAT/raw_mat", self.raw_mat.isChecked())
self._settings.setValue("export_batch/MAT/use_display_names_mat", self.use_display_names_mat.isChecked())
self._settings.setValue("export_batch/MAT/reduce_memory_usage_mat", self.reduce_memory_usage_mat.isChecked())
self._settings.setValue("export_batch/MAT/empty_channels_mat", self.empty_channels_mat.currentText())
self._settings.setValue("export_batch/MAT/export_compression_mat", self.export_compression_mat.currentText())
self._settings.setValue("export_batch/MAT/mat_format", self.mat_format.currentText())
self._settings.setValue("export_batch/MAT/oned_as", self.oned_as.currentText())
Loading

0 comments on commit db45fcc

Please sign in to comment.