From d5e6f095fe60223972235acd3ea68389aa7a1a14 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 5 Nov 2025 19:37:27 +0100 Subject: [PATCH] refactor(plot_base): consolidated user access for the PlotBase --- bec_widgets/cli/client.py | 265 +++++++++++++++--- bec_widgets/widgets/plots/heatmap/heatmap.py | 37 +-- bec_widgets/widgets/plots/image/image.py | 37 +-- .../widgets/plots/motor_map/motor_map.py | 40 +-- .../plots/multi_waveform/multi_waveform.py | 42 +-- bec_widgets/widgets/plots/plot_base.py | 44 +++ .../scatter_waveform/scatter_waveform.py | 42 +-- .../widgets/plots/waveform/waveform.py | 43 +-- 8 files changed, 274 insertions(+), 276 deletions(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 30ca1954..950cd6b6 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -1205,6 +1205,12 @@ class EllipticalROI(RPCBase): class Heatmap(RPCBase): """Heatmap widget for visualizing 2d grid data with color mapping for the z-axis.""" + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + @property @rpc_call def enable_toolbar(self) -> "bool": @@ -1392,6 +1398,29 @@ class Heatmap(RPCBase): Show the outer axes of the plot widget. """ + @property + @rpc_call + def lock_aspect_ratio(self) -> "bool": + """ + Whether the aspect ratio is locked. + """ + + @lock_aspect_ratio.setter + @rpc_call + def lock_aspect_ratio(self) -> "bool": + """ + Whether the aspect ratio is locked. + """ + + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -1420,6 +1449,48 @@ class Heatmap(RPCBase): Set auto range for the y-axis. """ + @property + @rpc_call + def x_log(self) -> "bool": + """ + Set X-axis to log scale if True, linear if False. + """ + + @x_log.setter + @rpc_call + def x_log(self) -> "bool": + """ + Set X-axis to log scale if True, linear if False. + """ + + @property + @rpc_call + def y_log(self) -> "bool": + """ + Set Y-axis to log scale if True, linear if False. + """ + + @y_log.setter + @rpc_call + def y_log(self) -> "bool": + """ + Set Y-axis to log scale if True, linear if False. + """ + + @property + @rpc_call + def legend_label_size(self) -> "int": + """ + The font size of the legend font. + """ + + @legend_label_size.setter + @rpc_call + def legend_label_size(self) -> "int": + """ + The font size of the legend font. + """ + @property @rpc_call def minimal_crosshair_precision(self) -> "int": @@ -1497,20 +1568,6 @@ class Heatmap(RPCBase): Get the maximum value of the v_range. """ - @property - @rpc_call - def lock_aspect_ratio(self) -> "bool": - """ - Whether the aspect ratio is locked. - """ - - @lock_aspect_ratio.setter - @rpc_call - def lock_aspect_ratio(self) -> "bool": - """ - Whether the aspect ratio is locked. - """ - @property @rpc_call def autorange(self) -> "bool": @@ -1750,6 +1807,12 @@ class Heatmap(RPCBase): class Image(RPCBase): """Image widget for displaying 2D data.""" + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + @property @rpc_call def enable_toolbar(self) -> "bool": @@ -1937,6 +2000,29 @@ class Image(RPCBase): Show the outer axes of the plot widget. """ + @property + @rpc_call + def lock_aspect_ratio(self) -> "bool": + """ + Whether the aspect ratio is locked. + """ + + @lock_aspect_ratio.setter + @rpc_call + def lock_aspect_ratio(self) -> "bool": + """ + Whether the aspect ratio is locked. + """ + + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -1965,6 +2051,48 @@ class Image(RPCBase): Set auto range for the y-axis. """ + @property + @rpc_call + def x_log(self) -> "bool": + """ + Set X-axis to log scale if True, linear if False. + """ + + @x_log.setter + @rpc_call + def x_log(self) -> "bool": + """ + Set X-axis to log scale if True, linear if False. + """ + + @property + @rpc_call + def y_log(self) -> "bool": + """ + Set Y-axis to log scale if True, linear if False. + """ + + @y_log.setter + @rpc_call + def y_log(self) -> "bool": + """ + Set Y-axis to log scale if True, linear if False. + """ + + @property + @rpc_call + def legend_label_size(self) -> "int": + """ + The font size of the legend font. + """ + + @legend_label_size.setter + @rpc_call + def legend_label_size(self) -> "int": + """ + The font size of the legend font. + """ + @property @rpc_call def minimal_crosshair_precision(self) -> "int": @@ -2042,20 +2170,6 @@ class Image(RPCBase): Get the maximum value of the v_range. """ - @property - @rpc_call - def lock_aspect_ratio(self) -> "bool": - """ - Whether the aspect ratio is locked. - """ - - @lock_aspect_ratio.setter - @rpc_call - def lock_aspect_ratio(self) -> "bool": - """ - Whether the aspect ratio is locked. - """ - @property @rpc_call def autorange(self) -> "bool": @@ -2595,6 +2709,12 @@ class MonacoWidget(RPCBase): class MotorMap(RPCBase): """Motor map widget for plotting motor positions in 2D including a trace of the last points.""" + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + @property @rpc_call def enable_toolbar(self) -> "bool": @@ -2796,6 +2916,15 @@ class MotorMap(RPCBase): Lock aspect ratio of the plot widget. """ + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -2866,6 +2995,20 @@ class MotorMap(RPCBase): The font size of the legend font. """ + @property + @rpc_call + def minimal_crosshair_precision(self) -> "int": + """ + Minimum decimal places for crosshair when dynamic precision is enabled. + """ + + @minimal_crosshair_precision.setter + @rpc_call + def minimal_crosshair_precision(self) -> "int": + """ + Minimum decimal places for crosshair when dynamic precision is enabled. + """ + @rpc_timeout(None) @rpc_call def screenshot(self, file_name: "str | None" = None): @@ -2993,6 +3136,12 @@ class MotorMap(RPCBase): class MultiWaveform(RPCBase): """MultiWaveform widget for displaying multiple waveforms emitted by a single signal.""" + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + @property @rpc_call def enable_toolbar(self) -> "bool": @@ -3194,6 +3343,15 @@ class MultiWaveform(RPCBase): Lock aspect ratio of the plot widget. """ + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -4202,6 +4360,12 @@ class ScatterCurve(RPCBase): class ScatterWaveform(RPCBase): + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + @property @rpc_call def enable_toolbar(self) -> "bool": @@ -4403,6 +4567,15 @@ class ScatterWaveform(RPCBase): Lock aspect ratio of the plot widget. """ + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -4821,14 +4994,10 @@ class VSCodeEditor(RPCBase): class Waveform(RPCBase): """Widget for plotting waveforms.""" - @property @rpc_call - def _config_dict(self) -> "dict": + def remove(self): """ - Get the configuration of the widget. - - Returns: - dict: The configuration of the widget. + Cleanup the BECConnector """ @property @@ -5032,6 +5201,15 @@ class Waveform(RPCBase): Lock aspect ratio of the plot widget. """ + @rpc_call + def auto_range(self, value: "bool" = True): + """ + On demand apply autorange to the plot item based on the visible curves. + + Args: + value(bool): If True, apply autorange to the visible curves. + """ + @property @rpc_call def auto_range_x(self) -> "bool": @@ -5060,15 +5238,6 @@ class Waveform(RPCBase): Set auto range for the y-axis. """ - @rpc_call - def auto_range(self, value: "bool" = True): - """ - On demand apply autorange to the plot item based on the visible curves. - - Args: - value(bool): If True, apply autorange to the visible curves. - """ - @property @rpc_call def x_log(self) -> "bool": @@ -5132,6 +5301,16 @@ class Waveform(RPCBase): Take a screenshot of the dock area and save it to a file. """ + @property + @rpc_call + def _config_dict(self) -> "dict": + """ + Get the configuration of the widget. + + Returns: + dict: The configuration of the widget. + """ + @property @rpc_call def curves(self) -> "list[Curve]": diff --git a/bec_widgets/widgets/plots/heatmap/heatmap.py b/bec_widgets/widgets/plots/heatmap/heatmap.py index 3173806b..8b3cbb26 100644 --- a/bec_widgets/widgets/plots/heatmap/heatmap.py +++ b/bec_widgets/widgets/plots/heatmap/heatmap.py @@ -26,6 +26,7 @@ from bec_widgets.utils.toolbars.actions import MaterialIconAction from bec_widgets.widgets.plots.heatmap.settings.heatmap_setting import HeatmapSettings from bec_widgets.widgets.plots.image.image_base import ImageBase from bec_widgets.widgets.plots.image.image_item import ImageItem +from bec_widgets.widgets.plots.plot_base import PlotBase logger = bec_logger.logger @@ -83,39 +84,7 @@ class Heatmap(ImageBase): """ USER_ACCESS = [ - # General PlotBase Settings - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "minimal_crosshair_precision", - "minimal_crosshair_precision.setter", - "screenshot", + *PlotBase.USER_ACCESS, # ImageView Specific Settings "color_map", "color_map.setter", @@ -125,8 +94,6 @@ class Heatmap(ImageBase): "v_min.setter", "v_max", "v_max.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", "autorange", "autorange.setter", "autorange_mode", diff --git a/bec_widgets/widgets/plots/image/image.py b/bec_widgets/widgets/plots/image/image.py index 241eec4f..a3c01be3 100644 --- a/bec_widgets/widgets/plots/image/image.py +++ b/bec_widgets/widgets/plots/image/image.py @@ -22,6 +22,7 @@ from bec_widgets.widgets.control.device_input.base_classes.device_input_base imp from bec_widgets.widgets.control.device_input.device_combobox.device_combobox import DeviceComboBox from bec_widgets.widgets.plots.image.image_base import ImageBase from bec_widgets.widgets.plots.image.image_item import ImageItem +from bec_widgets.widgets.plots.plot_base import PlotBase logger = bec_logger.logger @@ -59,39 +60,7 @@ class Image(ImageBase): RPC = True ICON_NAME = "image" USER_ACCESS = [ - # General PlotBase Settings - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "minimal_crosshair_precision", - "minimal_crosshair_precision.setter", - "screenshot", + *PlotBase.USER_ACCESS, # ImageView Specific Settings "color_map", "color_map.setter", @@ -101,8 +70,6 @@ class Image(ImageBase): "v_min.setter", "v_max", "v_max.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", "autorange", "autorange.setter", "autorange_mode", diff --git a/bec_widgets/widgets/plots/motor_map/motor_map.py b/bec_widgets/widgets/plots/motor_map/motor_map.py index cde4c5d0..0241ce10 100644 --- a/bec_widgets/widgets/plots/motor_map/motor_map.py +++ b/bec_widgets/widgets/plots/motor_map/motor_map.py @@ -90,45 +90,7 @@ class MotorMap(PlotBase): RPC = True ICON_NAME = "my_location" USER_ACCESS = [ - # General PlotBase Settings - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "x_log", - "x_log.setter", - "y_log", - "y_log.setter", - "legend_label_size", - "legend_label_size.setter", - "screenshot", + *PlotBase.USER_ACCESS, # motor_map specific "color", "color.setter", diff --git a/bec_widgets/widgets/plots/multi_waveform/multi_waveform.py b/bec_widgets/widgets/plots/multi_waveform/multi_waveform.py index 4a891e80..e0e214db 100644 --- a/bec_widgets/widgets/plots/multi_waveform/multi_waveform.py +++ b/bec_widgets/widgets/plots/multi_waveform/multi_waveform.py @@ -56,47 +56,7 @@ class MultiWaveform(PlotBase): RPC = True ICON_NAME = "ssid_chart" USER_ACCESS = [ - # General PlotBase Settings - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "x_log", - "x_log.setter", - "y_log", - "y_log.setter", - "legend_label_size", - "legend_label_size.setter", - "minimal_crosshair_precision", - "minimal_crosshair_precision.setter", - "screenshot", + *PlotBase.USER_ACCESS, # MultiWaveform Specific RPC Access "highlighted_index", "highlighted_index.setter", diff --git a/bec_widgets/widgets/plots/plot_base.py b/bec_widgets/widgets/plots/plot_base.py index 3e6f71b8..ea8bcf07 100644 --- a/bec_widgets/widgets/plots/plot_base.py +++ b/bec_widgets/widgets/plots/plot_base.py @@ -63,6 +63,50 @@ class UIMode(Enum): class PlotBase(BECWidget, QWidget): PLUGIN = False RPC = False + BASE_USER_ACCESS = [ + "enable_toolbar", + "enable_toolbar.setter", + "enable_side_panel", + "enable_side_panel.setter", + "enable_fps_monitor", + "enable_fps_monitor.setter", + "set", + "title", + "title.setter", + "x_label", + "x_label.setter", + "y_label", + "y_label.setter", + "x_limits", + "x_limits.setter", + "y_limits", + "y_limits.setter", + "x_grid", + "x_grid.setter", + "y_grid", + "y_grid.setter", + "inner_axes", + "inner_axes.setter", + "outer_axes", + "outer_axes.setter", + "lock_aspect_ratio", + "lock_aspect_ratio.setter", + "auto_range", + "auto_range_x", + "auto_range_x.setter", + "auto_range_y", + "auto_range_y.setter", + "x_log", + "x_log.setter", + "y_log", + "y_log.setter", + "legend_label_size", + "legend_label_size.setter", + "minimal_crosshair_precision", + "minimal_crosshair_precision.setter", + "screenshot", + ] + USER_ACCESS = [*BECWidget.USER_ACCESS, *BASE_USER_ACCESS] # Custom Signals property_changed = Signal(str, object) diff --git a/bec_widgets/widgets/plots/scatter_waveform/scatter_waveform.py b/bec_widgets/widgets/plots/scatter_waveform/scatter_waveform.py index 9f4adc6f..3ed5ea65 100644 --- a/bec_widgets/widgets/plots/scatter_waveform/scatter_waveform.py +++ b/bec_widgets/widgets/plots/scatter_waveform/scatter_waveform.py @@ -44,47 +44,7 @@ class ScatterWaveform(PlotBase): RPC = True ICON_NAME = "scatter_plot" USER_ACCESS = [ - # General PlotBase Settings - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "x_log", - "x_log.setter", - "y_log", - "y_log.setter", - "legend_label_size", - "legend_label_size.setter", - "minimal_crosshair_precision", - "minimal_crosshair_precision.setter", - "screenshot", + *PlotBase.USER_ACCESS, # Scatter Waveform Specific RPC Access "main_curve", "color_map", diff --git a/bec_widgets/widgets/plots/waveform/waveform.py b/bec_widgets/widgets/plots/waveform/waveform.py index fb71c8b1..410c07cc 100644 --- a/bec_widgets/widgets/plots/waveform/waveform.py +++ b/bec_widgets/widgets/plots/waveform/waveform.py @@ -67,49 +67,8 @@ class Waveform(PlotBase): RPC = True ICON_NAME = "show_chart" USER_ACCESS = [ - # General PlotBase Settings + *PlotBase.USER_ACCESS, "_config_dict", - "enable_toolbar", - "enable_toolbar.setter", - "enable_side_panel", - "enable_side_panel.setter", - "enable_fps_monitor", - "enable_fps_monitor.setter", - "set", - "title", - "title.setter", - "x_label", - "x_label.setter", - "y_label", - "y_label.setter", - "x_limits", - "x_limits.setter", - "y_limits", - "y_limits.setter", - "x_grid", - "x_grid.setter", - "y_grid", - "y_grid.setter", - "inner_axes", - "inner_axes.setter", - "outer_axes", - "outer_axes.setter", - "lock_aspect_ratio", - "lock_aspect_ratio.setter", - "auto_range_x", - "auto_range_x.setter", - "auto_range_y", - "auto_range_y.setter", - "auto_range", - "x_log", - "x_log.setter", - "y_log", - "y_log.setter", - "legend_label_size", - "legend_label_size.setter", - "minimal_crosshair_precision", - "minimal_crosshair_precision.setter", - "screenshot", # Waveform Specific RPC Access "curves", "x_mode",