0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

feat(waveform_widget): BECWaveformWidget toolbar added import/export config

This commit is contained in:
2024-07-04 14:19:56 +02:00
parent 755b394c1c
commit fa9b17191d
5 changed files with 73 additions and 4 deletions

View File

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="48px" viewBox="0 0 24 24" width="48px"
fill="#FFFFFF">
<g>
<rect fill="none" height="24" width="24"/>
</g>
<g>
<path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M7,9l1.41,1.41L11,7.83V16h2V7.83l2.59,2.58L17,9l-5-5L7,9z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 371 B

View File

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="48px" viewBox="0 0 24 24" width="48px"
fill="#FFFFFF">
<g>
<rect fill="none" height="24" width="24"/>
</g>
<g>
<path d="M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 377 B

View File

@ -1,7 +1,7 @@
import os import os
from qtpy.QtCore import QSize 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 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)) icon.addFile(os.path.join(parent_path, "assets", "settings.svg"), size=QSize(20, 20))
self.action = QAction(icon, "Open Configuration Dialog", target) self.action = QAction(icon, "Open Configuration Dialog", target)
toolbar.addAction(self.action) 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)

View File

@ -4,8 +4,8 @@ import sys
from typing import Literal from typing import Literal
import numpy as np import numpy as np
from PySide6.QtWidgets import QWidget, QVBoxLayout
from qtpy import PYSIDE6 from qtpy import PYSIDE6
from qtpy.QtWidgets import QVBoxLayout, QWidget
from bec_widgets.utils import BECConnector from bec_widgets.utils import BECConnector
from bec_widgets.widgets.figure import BECFigure 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 import Waveform1DConfig
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import BECCurve from bec_widgets.widgets.figure.plots.waveform.waveform_curve import BECCurve
from bec_widgets.widgets.toolbar import ModularToolBar 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: try:
import pandas as pd import pandas as pd
@ -71,7 +71,9 @@ class BECWaveformWidget(BECConnector, QWidget):
actions={ actions={
# "connect": ConnectAction(), # "connect": ConnectAction(),
# "history": ResetHistoryAction(), # "history": ResetHistoryAction(),
"axis_settings": SettingsAction() "axis_settings": SettingsAction(),
"import": ImportAction(),
"export": ExportAction(),
}, },
target_widget=self, target_widget=self,
) )
@ -88,6 +90,12 @@ class BECWaveformWidget(BECConnector, QWidget):
def _hook_actions(self): def _hook_actions(self):
self.toolbar.widgets["axis_settings"].action.triggered.connect(self.show_axis_settings) 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): def show_axis_settings(self):
dialog = AxisSettingsDialog(self, target_widget=self) dialog = AxisSettingsDialog(self, target_widget=self)
@ -377,6 +385,29 @@ class BECWaveformWidget(BECConnector, QWidget):
""" """
self.waveform.lock_aspect_ratio(lock) 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): def cleanup(self):
self.fig.cleanup() self.fig.cleanup()
return super().cleanup() return super().cleanup()