From fa9b17191ddbb4043a658dae9aa0801e1dc22b84 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 4 Jul 2024 14:19:56 +0200 Subject: [PATCH] feat(waveform_widget): BECWaveformWidget toolbar added import/export config --- .../widgets/waveform/assets/export.svg | 9 +++++ .../widgets/waveform/assets/import.svg | 9 +++++ .../waveform/waveform_dialog/curve_dialog.py | 0 .../waveform_dialog/waveform_toolbar.py | 22 ++++++++++- .../widgets/waveform/waveform_widget.py | 37 +++++++++++++++++-- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 bec_widgets/widgets/waveform/assets/export.svg create mode 100644 bec_widgets/widgets/waveform/assets/import.svg create mode 100644 bec_widgets/widgets/waveform/waveform_dialog/curve_dialog.py diff --git a/bec_widgets/widgets/waveform/assets/export.svg b/bec_widgets/widgets/waveform/assets/export.svg new file mode 100644 index 00000000..acdaf8a2 --- /dev/null +++ b/bec_widgets/widgets/waveform/assets/export.svg @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/bec_widgets/widgets/waveform/assets/import.svg b/bec_widgets/widgets/waveform/assets/import.svg new file mode 100644 index 00000000..bc79c043 --- /dev/null +++ b/bec_widgets/widgets/waveform/assets/import.svg @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/bec_widgets/widgets/waveform/waveform_dialog/curve_dialog.py b/bec_widgets/widgets/waveform/waveform_dialog/curve_dialog.py new file mode 100644 index 00000000..e69de29b diff --git a/bec_widgets/widgets/waveform/waveform_dialog/waveform_toolbar.py b/bec_widgets/widgets/waveform/waveform_dialog/waveform_toolbar.py index f60c3434..d39f6be4 100644 --- a/bec_widgets/widgets/waveform/waveform_dialog/waveform_toolbar.py +++ b/bec_widgets/widgets/waveform/waveform_dialog/waveform_toolbar.py @@ -1,7 +1,7 @@ import os from qtpy.QtCore import QSize -from qtpy.QtGui import QIcon, QAction +from qtpy.QtGui import QAction, QIcon from bec_widgets.widgets.toolbar.toolbar import ToolBarAction @@ -14,3 +14,23 @@ class SettingsAction(ToolBarAction): icon.addFile(os.path.join(parent_path, "assets", "settings.svg"), size=QSize(20, 20)) self.action = QAction(icon, "Open Configuration Dialog", target) toolbar.addAction(self.action) + + +class ImportAction(ToolBarAction): + def add_to_toolbar(self, toolbar, target): + current_path = os.path.dirname(__file__) + parent_path = os.path.dirname(current_path) + icon = QIcon() + icon.addFile(os.path.join(parent_path, "assets", "import.svg"), size=QSize(20, 20)) + self.action = QAction(icon, "Import Configuration from YAML", target) + toolbar.addAction(self.action) + + +class ExportAction(ToolBarAction): + def add_to_toolbar(self, toolbar, target): + current_path = os.path.dirname(__file__) + parent_path = os.path.dirname(current_path) + icon = QIcon() + icon.addFile(os.path.join(parent_path, "assets", "export.svg"), size=QSize(20, 20)) + self.action = QAction(icon, "Export Current Configuration to YAML", target) + toolbar.addAction(self.action) diff --git a/bec_widgets/widgets/waveform/waveform_widget.py b/bec_widgets/widgets/waveform/waveform_widget.py index 4aa18a11..0574f44c 100644 --- a/bec_widgets/widgets/waveform/waveform_widget.py +++ b/bec_widgets/widgets/waveform/waveform_widget.py @@ -4,8 +4,8 @@ import sys from typing import Literal import numpy as np -from PySide6.QtWidgets import QWidget, QVBoxLayout from qtpy import PYSIDE6 +from qtpy.QtWidgets import QVBoxLayout, QWidget from bec_widgets.utils import BECConnector from bec_widgets.widgets.figure import BECFigure @@ -13,7 +13,7 @@ from bec_widgets.widgets.figure.plots.axis_settings import AxisSettingsDialog from bec_widgets.widgets.figure.plots.waveform.waveform import Waveform1DConfig from bec_widgets.widgets.figure.plots.waveform.waveform_curve import BECCurve from bec_widgets.widgets.toolbar import ModularToolBar -from bec_widgets.widgets.waveform.waveform_dialog.waveform_toolbar import SettingsAction +from bec_widgets.widgets.waveform.waveform_dialog.waveform_toolbar import * try: import pandas as pd @@ -71,7 +71,9 @@ class BECWaveformWidget(BECConnector, QWidget): actions={ # "connect": ConnectAction(), # "history": ResetHistoryAction(), - "axis_settings": SettingsAction() + "axis_settings": SettingsAction(), + "import": ImportAction(), + "export": ExportAction(), }, target_widget=self, ) @@ -88,6 +90,12 @@ class BECWaveformWidget(BECConnector, QWidget): def _hook_actions(self): self.toolbar.widgets["axis_settings"].action.triggered.connect(self.show_axis_settings) + self.toolbar.widgets["import"].action.triggered.connect( + lambda: self.load_config(path=None, gui=True) + ) + self.toolbar.widgets["export"].action.triggered.connect( + lambda: self.save_config(path=None, gui=True) + ) def show_axis_settings(self): dialog = AxisSettingsDialog(self, target_widget=self) @@ -377,6 +385,29 @@ class BECWaveformWidget(BECConnector, QWidget): """ self.waveform.lock_aspect_ratio(lock) + ####################################### + # User Access Methods from BECConnector + ###################################### + def load_config(self, path: str | None = None, gui: bool = False): + """ + Load the configuration of the widget from YAML. + + Args: + path(str): Path to the configuration file for non-GUI dialog mode. + gui(bool): If True, use the GUI dialog to load the configuration file. + """ + self.fig.load_config(path=path, gui=gui) + + def save_config(self, path: str | None = None, gui: bool = False): + """ + Save the configuration of the widget to YAML. + + Args: + path(str): Path to save the configuration file for non-GUI dialog mode. + gui(bool): If True, use the GUI dialog to save the configuration file. + """ + self.fig.save_config(path=path, gui=gui) + def cleanup(self): self.fig.cleanup() return super().cleanup()