diff --git a/docs/changes/newsfragments/7772.improved b/docs/changes/newsfragments/7772.improved new file mode 100644 index 000000000000..f490e3e058a4 --- /dev/null +++ b/docs/changes/newsfragments/7772.improved @@ -0,0 +1,5 @@ +The table created by experiments_widget() now has a column of buttons by which individual datasets can be exported as ASCII files. This is a user-friendly way to use the qcode.dataset.export() method. + +To demo this feature, run +> experiments_widget(sort_by="timestamp") +in Jupyter, and click on one of the cells in the "Export" column. diff --git a/src/qcodes/interactive_widget.py b/src/qcodes/interactive_widget.py index 503dd5e152e2..f12c30a294f0 100644 --- a/src/qcodes/interactive_widget.py +++ b/src/qcodes/interactive_widget.py @@ -8,6 +8,7 @@ import traceback from datetime import datetime from functools import partial, reduce +from pathlib import Path from typing import TYPE_CHECKING, Any, Literal from ipywidgets import ( # type: ignore[import-untyped] @@ -442,6 +443,21 @@ def _get_plot_button(ds: DataSetProtocol, tab: Tab) -> Button: ) +def _get_export_button( + ds: DataSetProtocol, tab: Tab +) -> Button: # New button in the table to export each dataset + return button( + "", + "warning", + tooltip="Click to export this DataSet as ASCII.", + on_click=lambda _: ds.export( + "csv", + path=Path.cwd() / "export", + ), + button_kwargs=dict(icon="file-export"), + ) + + def _experiment_widget( data_sets: Iterable[DataSetProtocol], tab: Tab ) -> GridspecLayout: @@ -457,6 +473,7 @@ def _experiment_widget( "Notes", "Snapshot", "Plot", + "Export", ] header = {n: button(n, "info") for n in header_names} @@ -471,6 +488,7 @@ def _experiment_widget( row["MSMT Time"] = _get_timestamp_button(ds) row["Snapshot"] = _get_snapshot_button(ds, tab) row["Plot"] = _get_plot_button(ds, tab) + row["Export"] = _get_export_button(ds, tab) rows.append(row) grid = GridspecLayout(n_rows=len(rows), n_columns=len(header_names)) diff --git a/tests/test_interactive_widget.py b/tests/test_interactive_widget.py index e582bddf35bb..f57116b75287 100644 --- a/tests/test_interactive_widget.py +++ b/tests/test_interactive_widget.py @@ -75,6 +75,13 @@ def test_snapshot_button(tab, standalone_parameters_dataset) -> None: assert "snapshot" in tab.get_title(1) +def test_export_button(tab, standalone_parameters_dataset) -> None: + ds = standalone_parameters_dataset + export_button = interactive_widget._get_export_button(ds, tab) + export_button.click() + time.sleep(0.5) # after click + + @patch("matplotlib.pyplot.show") def test_plot_button(tab, standalone_parameters_dataset) -> None: ds = standalone_parameters_dataset