diff --git a/plottr/apps/inspectr.py b/plottr/apps/inspectr.py index 4a710ce4..ac2b0f7d 100644 --- a/plottr/apps/inspectr.py +++ b/plottr/apps/inspectr.py @@ -166,6 +166,10 @@ def showContextMenu(self, position: QtCore.QPoint) -> None: crossAction: QtWidgets.QAction = window.crossAction # type: ignore[has-type] crossAction.setText('Cross' if current_tag_char != self.tag_dict['cross'] else 'Uncross') menu.addAction(crossAction) + + expAction: QtWidgets.QAction = window.expAction # type: ignore[has-type] + expAction.setText('Export') + menu.addAction(expAction) action = menu.exec_(self.mapToGlobal(position)) if action == copy_action: @@ -405,6 +409,12 @@ def __init__(self, parent: Optional[QtWidgets.QWidget] = None, self.crossAction.triggered.connect(self.crossSelectedRun) self.addAction(self.crossAction) + # action: export data + self.expAction = QtWidgets.QAction() + self.expAction.setShortcut('Ctrl+Alt+E') + self.expAction.triggered.connect(self.exportSelectedRun) + self.addAction(self.expAction) + # sizing scaledSize = int(640 * rint(self.logicalDpiX() / 96.0)) self.resize(scaledSize, scaledSize) @@ -638,6 +648,27 @@ def starSelectedRun(self) -> None: def crossSelectedRun(self) -> None: self.tagSelectedRun('cross') + @Slot() + def exportSelectedRun(self) -> None: + """ + Open a file dialog that allows selecting a folder and file name. + """ + curdir = os.getcwd() + runId = int(self.runList.selectedItems()[0].text(0)) + default_name = curdir+"/dataID_"+str(runId)+".csv" + + path, _fltr = QtWidgets.QFileDialog.getSaveFileName( + self, + 'Export to .csv file', + default_name, + 'comma separated files (*.csv);;all files (*.*)', + ) + + if path: + LOGGER.info(f"Opening: {path}") + ds = load_dataset_from(self.filepath, runId) + df = ds.to_pandas_dataframe() + df.to_csv(path) class WindowDict(TypedDict): flowchart: Flowchart