From a8ff1d4cd09cae5eaeb4bd0ea90fdd102e32f3a3 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 16 Jul 2024 13:24:57 +0200 Subject: [PATCH] feat(waveform_widget): added error handle utility --- bec_widgets/cli/client.py | 52 +++++-------------- .../curve_dialog/curve_dialog.py | 16 ++++-- .../widgets/waveform/waveform_widget.py | 4 ++ 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 773d5b44..75f147fd 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -1564,8 +1564,6 @@ class BECWaveform(RPCBase): y_name(str): Name of the y signal. y_entry(str): Entry of the y signal. color(str, optional): Color of the curve. Defaults to None. - color_map_z(str): The color map to use for the z-axis. - label(str, optional): Label of the curve. Defaults to None. dap(str): The dap model to use for the curve. validate_bec(bool, optional): If True, validate the signal with BEC. Defaults to True. **kwargs: Additional keyword arguments for the curve configuration. @@ -1757,6 +1755,15 @@ class BECWaveform(RPCBase): y(bool): Show grid on the y-axis. """ + @rpc_call + def set_colormap(self, colormap: "str | None" = None): + """ + Set the colormap of the plot widget. + + Args: + colormap(str, optional): Scale the colors of curves to colormap. If None, use the default color palette. + """ + @rpc_call def lock_aspect_ratio(self, lock): """ @@ -1799,42 +1806,9 @@ class BECWaveformWidget(RPCBase): """ @rpc_call - def plot( - self, - x: "list | np.ndarray | None" = None, - y: "list | np.ndarray | None" = None, - x_name: "str | None" = None, - y_name: "str | None" = None, - z_name: "str | None" = None, - x_entry: "str | None" = None, - y_entry: "str | None" = None, - z_entry: "str | None" = None, - color: "str | None" = None, - color_map_z: "str | None" = "plasma", - label: "str | None" = None, - validate: "bool" = True, - dap: "str | None" = None, - **kwargs, - ) -> "BECCurve": + def plot(widget, *args, **kwargs): """ - Plot a curve to the plot widget. - Args: - x(list | np.ndarray): Custom x data to plot. - y(list | np.ndarray): Custom y data to plot. - x_name(str): The name of the device for the x-axis. - y_name(str): The name of the device for the y-axis. - z_name(str): The name of the device for the z-axis. - x_entry(str): The name of the entry for the x-axis. - y_entry(str): The name of the entry for the y-axis. - z_entry(str): The name of the entry for the z-axis. - color(str): The color of the curve. - color_map_z(str): The color map to use for the z-axis. - label(str): The label of the curve. - validate(bool): If True, validate the device names and entries. - dap(str): The dap model to use for the curve. If not specified, none will be added. - - Returns: - BECCurve: The curve object. + None """ @rpc_call @@ -1846,6 +1820,7 @@ class BECWaveformWidget(RPCBase): y_entry: "str | None" = None, color: "str | None" = None, dap: "str" = "GaussianModel", + validate_bec: "bool" = True, **kwargs, ) -> "BECCurve": """ @@ -1857,9 +1832,8 @@ class BECWaveformWidget(RPCBase): y_name(str): Name of the y signal. y_entry(str): Entry of the y signal. color(str, optional): Color of the curve. Defaults to None. - color_map_z(str): The color map to use for the z-axis. - label(str, optional): Label of the curve. Defaults to None. dap(str): The dap model to use for the curve. + validate_bec(bool, optional): If True, validate the signal with BEC. Defaults to True. **kwargs: Additional keyword arguments for the curve configuration. Returns: diff --git a/bec_widgets/widgets/waveform/waveform_toolbar/curve_dialog/curve_dialog.py b/bec_widgets/widgets/waveform/waveform_toolbar/curve_dialog/curve_dialog.py index 4d752238..9436bb3a 100644 --- a/bec_widgets/widgets/waveform/waveform_toolbar/curve_dialog/curve_dialog.py +++ b/bec_widgets/widgets/waveform/waveform_toolbar/curve_dialog/curve_dialog.py @@ -3,19 +3,18 @@ from __future__ import annotations import os from typing import Literal -from pydantic import BaseModel from PySide6.QtCore import QObject from PySide6.QtGui import QIcon from PySide6.QtWidgets import QComboBox, QLineEdit, QPushButton, QSpinBox, QTableWidget +from pydantic import BaseModel from qtpy.QtCore import Slot from qtpy.QtWidgets import QVBoxLayout +from bec_widgets.qt_utils.error_popups import WarningPopupUtility from bec_widgets.qt_utils.settings_dialog import SettingWidget -from bec_widgets.utils import BECConnector, Colors, UILoader +from bec_widgets.utils import Colors, UILoader from bec_widgets.widgets.color_button.color_button import ColorButton from bec_widgets.widgets.device_line_edit.device_line_edit import DeviceLineEdit -from bec_widgets.widgets.figure.plots.plot_base import AxisConfig -from bec_widgets.widgets.figure.plots.waveform.waveform_curve import CurveConfig class CurveSettings(SettingWidget): @@ -25,6 +24,8 @@ class CurveSettings(SettingWidget): self.ui = UILoader(self).loader(os.path.join(current_path, "curve_dialog.ui")) + self.warning_util = WarningPopupUtility(self) + self.layout = QVBoxLayout(self) self.layout.addWidget(self.ui) @@ -86,6 +87,12 @@ class CurveSettings(SettingWidget): self.ui.x_entry.setEnabled(False) self.ui.dap_table.setEnabled(False) self.ui.add_dap.setEnabled(False) + if self.ui.dap_table.rowCount() > 0: + self.warning_util.show_warning( + title="DAP Warning", + message="DAP is not supported without specific x-axis device. All current DAP curves will be removed.", + detailed_text=f"Affected curves: {[self.ui.dap_table.cellWidget(row, 0).text() for row in range(self.ui.dap_table.rowCount())]}", + ) else: self.ui.x_name.setEnabled(True) self.ui.x_entry.setEnabled(True) @@ -148,6 +155,7 @@ class CurveSettings(SettingWidget): ) if x_mode not in ["index", "timestamp", "best_effort"]: + for row in range(self.ui.dap_table.rowCount()): y_name = self.ui.dap_table.cellWidget(row, 0).text() y_entry = self.ui.dap_table.cellWidget(row, 1).text() diff --git a/bec_widgets/widgets/waveform/waveform_widget.py b/bec_widgets/widgets/waveform/waveform_widget.py index 3286a75f..84ae7621 100644 --- a/bec_widgets/widgets/waveform/waveform_widget.py +++ b/bec_widgets/widgets/waveform/waveform_widget.py @@ -6,6 +6,7 @@ from typing import Literal import numpy as np from qtpy.QtWidgets import QVBoxLayout, QWidget +from bec_widgets.qt_utils.error_popups import error_managed from bec_widgets.qt_utils.settings_dialog import SettingsDialog from bec_widgets.qt_utils.toolbar import ModularToolBar from bec_widgets.utils import BECConnector @@ -179,6 +180,7 @@ class BECWaveformWidget(BECConnector, QWidget): """ self.waveform.set_colormap(colormap) + @error_managed def set_x(self, x_name: str, x_entry: str | None = None): """ Change the x axis of the plot widget. @@ -193,6 +195,7 @@ class BECWaveformWidget(BECConnector, QWidget): """ self.waveform.set_x(x_name, x_entry) + @error_managed def plot( self, x: list | np.ndarray | None = None, @@ -248,6 +251,7 @@ class BECWaveformWidget(BECConnector, QWidget): **kwargs, ) + @error_managed def add_dap( self, x_name: str,