From bdec5e9b62a0f3cda90f89fcf4dec613860de8c4 Mon Sep 17 00:00:00 2001 From: Edward Laird <52163138+EdwardLaird1@users.noreply.github.com> Date: Sun, 11 Jan 2026 22:12:42 +0000 Subject: [PATCH 1/3] Add export button to experiments_widget() 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. --- docs/changes/newsfragments/nnnn.improved | 5 +++++ src/qcodes/interactive_widget.py | 11 +++++++++++ tests/test_interactive_widget.py | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 docs/changes/newsfragments/nnnn.improved diff --git a/docs/changes/newsfragments/nnnn.improved b/docs/changes/newsfragments/nnnn.improved new file mode 100644 index 000000000000..ee2ca431c7e6 --- /dev/null +++ b/docs/changes/newsfragments/nnnn.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. \ No newline at end of file diff --git a/src/qcodes/interactive_widget.py b/src/qcodes/interactive_widget.py index 503dd5e152e2..b61b0b5d4216 100644 --- a/src/qcodes/interactive_widget.py +++ b/src/qcodes/interactive_widget.py @@ -9,6 +9,7 @@ from datetime import datetime from functools import partial, reduce from typing import TYPE_CHECKING, Any, Literal +from pathlib import Path from ipywidgets import ( # type: ignore[import-untyped] HTML, @@ -441,6 +442,14 @@ def _get_plot_button(ds: DataSetProtocol, tab: Tab) -> Button: button_kwargs=dict(icon="line-chart"), ) +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 @@ -457,6 +466,7 @@ def _experiment_widget( "Notes", "Snapshot", "Plot", + "Export" ] header = {n: button(n, "info") for n in header_names} @@ -471,6 +481,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 From 53f49bbecbee337400d6c7ae23a6eeed805fc0f9 Mon Sep 17 00:00:00 2001 From: Edward Laird <52163138+EdwardLaird1@users.noreply.github.com> Date: Sun, 11 Jan 2026 22:18:53 +0000 Subject: [PATCH 2/3] Rename nnnn.improved to 7772.improved --- docs/changes/newsfragments/{nnnn.improved => 7772.improved} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/changes/newsfragments/{nnnn.improved => 7772.improved} (99%) diff --git a/docs/changes/newsfragments/nnnn.improved b/docs/changes/newsfragments/7772.improved similarity index 99% rename from docs/changes/newsfragments/nnnn.improved rename to docs/changes/newsfragments/7772.improved index ee2ca431c7e6..5d9a1ce9da9f 100644 --- a/docs/changes/newsfragments/nnnn.improved +++ b/docs/changes/newsfragments/7772.improved @@ -2,4 +2,4 @@ The table created by experiments_widget() now has a column of buttons by which i To demo this feature, run > experiments_widget(sort_by="timestamp") -in Jupyter, and click on one of the cells in the "Export" column. \ No newline at end of file +in Jupyter, and click on one of the cells in the "Export" column. From e90179410a5cc162b45d54e291a19aed9111be3b Mon Sep 17 00:00:00 2001 From: Edward Laird Date: Tue, 13 Jan 2026 16:44:45 +0000 Subject: [PATCH 3/3] Apply pre-commit fixes --- docs/changes/newsfragments/7772.improved | 2 +- src/qcodes/interactive_widget.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/changes/newsfragments/7772.improved b/docs/changes/newsfragments/7772.improved index 5d9a1ce9da9f..f490e3e058a4 100644 --- a/docs/changes/newsfragments/7772.improved +++ b/docs/changes/newsfragments/7772.improved @@ -1,5 +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") +> 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 b61b0b5d4216..f12c30a294f0 100644 --- a/src/qcodes/interactive_widget.py +++ b/src/qcodes/interactive_widget.py @@ -8,8 +8,8 @@ import traceback from datetime import datetime from functools import partial, reduce -from typing import TYPE_CHECKING, Any, Literal from pathlib import Path +from typing import TYPE_CHECKING, Any, Literal from ipywidgets import ( # type: ignore[import-untyped] HTML, @@ -442,15 +442,22 @@ def _get_plot_button(ds: DataSetProtocol, tab: Tab) -> Button: button_kwargs=dict(icon="line-chart"), ) -def _get_export_button(ds: DataSetProtocol, tab: Tab) -> Button: # New button in the table to export each dataset + +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",), + 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: @@ -466,7 +473,7 @@ def _experiment_widget( "Notes", "Snapshot", "Plot", - "Export" + "Export", ] header = {n: button(n, "info") for n in header_names}