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

feat(waveform_widget): added error handle utility

This commit is contained in:
2024-07-16 13:24:57 +02:00
parent 47fcb9ebfe
commit a8ff1d4cd0
3 changed files with 29 additions and 43 deletions

View File

@ -1564,8 +1564,6 @@ class BECWaveform(RPCBase):
y_name(str): Name of the y signal. y_name(str): Name of the y signal.
y_entry(str): Entry of the y signal. y_entry(str): Entry of the y signal.
color(str, optional): Color of the curve. Defaults to None. 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. dap(str): The dap model to use for the curve.
validate_bec(bool, optional): If True, validate the signal with BEC. Defaults to True. validate_bec(bool, optional): If True, validate the signal with BEC. Defaults to True.
**kwargs: Additional keyword arguments for the curve configuration. **kwargs: Additional keyword arguments for the curve configuration.
@ -1757,6 +1755,15 @@ class BECWaveform(RPCBase):
y(bool): Show grid on the y-axis. 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 @rpc_call
def lock_aspect_ratio(self, lock): def lock_aspect_ratio(self, lock):
""" """
@ -1799,42 +1806,9 @@ class BECWaveformWidget(RPCBase):
""" """
@rpc_call @rpc_call
def plot( def plot(widget, *args, **kwargs):
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":
""" """
Plot a curve to the plot widget. None
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.
""" """
@rpc_call @rpc_call
@ -1846,6 +1820,7 @@ class BECWaveformWidget(RPCBase):
y_entry: "str | None" = None, y_entry: "str | None" = None,
color: "str | None" = None, color: "str | None" = None,
dap: "str" = "GaussianModel", dap: "str" = "GaussianModel",
validate_bec: "bool" = True,
**kwargs, **kwargs,
) -> "BECCurve": ) -> "BECCurve":
""" """
@ -1857,9 +1832,8 @@ class BECWaveformWidget(RPCBase):
y_name(str): Name of the y signal. y_name(str): Name of the y signal.
y_entry(str): Entry of the y signal. y_entry(str): Entry of the y signal.
color(str, optional): Color of the curve. Defaults to None. 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. 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. **kwargs: Additional keyword arguments for the curve configuration.
Returns: Returns:

View File

@ -3,19 +3,18 @@ from __future__ import annotations
import os import os
from typing import Literal from typing import Literal
from pydantic import BaseModel
from PySide6.QtCore import QObject from PySide6.QtCore import QObject
from PySide6.QtGui import QIcon from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QComboBox, QLineEdit, QPushButton, QSpinBox, QTableWidget from PySide6.QtWidgets import QComboBox, QLineEdit, QPushButton, QSpinBox, QTableWidget
from pydantic import BaseModel
from qtpy.QtCore import Slot from qtpy.QtCore import Slot
from qtpy.QtWidgets import QVBoxLayout 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.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.color_button.color_button import ColorButton
from bec_widgets.widgets.device_line_edit.device_line_edit import DeviceLineEdit 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): class CurveSettings(SettingWidget):
@ -25,6 +24,8 @@ class CurveSettings(SettingWidget):
self.ui = UILoader(self).loader(os.path.join(current_path, "curve_dialog.ui")) self.ui = UILoader(self).loader(os.path.join(current_path, "curve_dialog.ui"))
self.warning_util = WarningPopupUtility(self)
self.layout = QVBoxLayout(self) self.layout = QVBoxLayout(self)
self.layout.addWidget(self.ui) self.layout.addWidget(self.ui)
@ -86,6 +87,12 @@ class CurveSettings(SettingWidget):
self.ui.x_entry.setEnabled(False) self.ui.x_entry.setEnabled(False)
self.ui.dap_table.setEnabled(False) self.ui.dap_table.setEnabled(False)
self.ui.add_dap.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: else:
self.ui.x_name.setEnabled(True) self.ui.x_name.setEnabled(True)
self.ui.x_entry.setEnabled(True) self.ui.x_entry.setEnabled(True)
@ -148,6 +155,7 @@ class CurveSettings(SettingWidget):
) )
if x_mode not in ["index", "timestamp", "best_effort"]: if x_mode not in ["index", "timestamp", "best_effort"]:
for row in range(self.ui.dap_table.rowCount()): for row in range(self.ui.dap_table.rowCount()):
y_name = self.ui.dap_table.cellWidget(row, 0).text() y_name = self.ui.dap_table.cellWidget(row, 0).text()
y_entry = self.ui.dap_table.cellWidget(row, 1).text() y_entry = self.ui.dap_table.cellWidget(row, 1).text()

View File

@ -6,6 +6,7 @@ from typing import Literal
import numpy as np import numpy as np
from qtpy.QtWidgets import QVBoxLayout, QWidget 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.settings_dialog import SettingsDialog
from bec_widgets.qt_utils.toolbar import ModularToolBar from bec_widgets.qt_utils.toolbar import ModularToolBar
from bec_widgets.utils import BECConnector from bec_widgets.utils import BECConnector
@ -179,6 +180,7 @@ class BECWaveformWidget(BECConnector, QWidget):
""" """
self.waveform.set_colormap(colormap) self.waveform.set_colormap(colormap)
@error_managed
def set_x(self, x_name: str, x_entry: str | None = None): def set_x(self, x_name: str, x_entry: str | None = None):
""" """
Change the x axis of the plot widget. Change the x axis of the plot widget.
@ -193,6 +195,7 @@ class BECWaveformWidget(BECConnector, QWidget):
""" """
self.waveform.set_x(x_name, x_entry) self.waveform.set_x(x_name, x_entry)
@error_managed
def plot( def plot(
self, self,
x: list | np.ndarray | None = None, x: list | np.ndarray | None = None,
@ -248,6 +251,7 @@ class BECWaveformWidget(BECConnector, QWidget):
**kwargs, **kwargs,
) )
@error_managed
def add_dap( def add_dap(
self, self,
x_name: str, x_name: str,