Skip to content

Added data export functionality #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions plottr/apps/inspectr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd highly recommend to use dataset's GUID in the file name. For an example you can see how qcodes' dataset export feature is implemented see here https://microsoft.github.io/Qcodes/examples/DataSet/Exporting-data-to-other-file-formats.html


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
Expand Down