From a3de1f0a31dfb9048493fb61983167960577fb97 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 29 Apr 2025 17:55:01 +0200 Subject: [PATCH] refactor(plots): waveform and image rpc api review --- bec_widgets/cli/client.py | 66 ++++++------------- bec_widgets/widgets/plots/image/image.py | 24 +++---- bec_widgets/widgets/plots/image/image_item.py | 10 +-- .../widgets/plots/image/image_processor.py | 6 +- .../plots/image/toolbar_bundles/processing.py | 14 ++-- .../widgets/plots/waveform/waveform.py | 2 + tests/unit_tests/test_image_view_next_gen.py | 24 +++---- 7 files changed, 57 insertions(+), 89 deletions(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 544ee802..9aedfaa3 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -951,48 +951,6 @@ 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 color_map(self) -> "str": @@ -1187,16 +1145,16 @@ class Image(RPCBase): @property @rpc_call - def rotation(self) -> "int": + def num_rotation_90(self) -> "int": """ - The number of 90° rotations to apply. + The number of 90° rotations to apply counterclockwise. """ - @rotation.setter + @num_rotation_90.setter @rpc_call - def rotation(self) -> "int": + def num_rotation_90(self) -> "int": """ - The number of 90° rotations to apply. + The number of 90° rotations to apply counterclockwise. """ @property @@ -3364,6 +3322,20 @@ class Waveform(RPCBase): None """ + @property + @rpc_call + def x_entry(self) -> "str | None": + """ + The x signal name. + """ + + @x_entry.setter + @rpc_call + def x_entry(self) -> "str | None": + """ + The x signal name. + """ + @property @rpc_call def color_palette(self) -> "str": diff --git a/bec_widgets/widgets/plots/image/image.py b/bec_widgets/widgets/plots/image/image.py index 5330044a..4b02eba1 100644 --- a/bec_widgets/widgets/plots/image/image.py +++ b/bec_widgets/widgets/plots/image/image.py @@ -79,12 +79,6 @@ class Image(PlotBase): "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", # ImageView Specific Settings "color_map", "color_map.setter", @@ -111,8 +105,8 @@ class Image(PlotBase): "fft.setter", "log", "log.setter", - "rotation", - "rotation.setter", + "num_rotation_90", + "num_rotation_90.setter", "transpose", "transpose.setter", "image", @@ -656,21 +650,21 @@ class Image(PlotBase): self._main_image.log = enable @SafeProperty(int) - def rotation(self) -> int: + def num_rotation_90(self) -> int: """ - The number of 90° rotations to apply. + The number of 90° rotations to apply counterclockwise. """ - return self._main_image.rotation + return self._main_image.num_rotation_90 - @rotation.setter - def rotation(self, value: int): + @num_rotation_90.setter + def num_rotation_90(self, value: int): """ - Set the number of 90° rotations to apply. + Set the number of 90° rotations to apply counterclockwise. Args: value(int): The number of 90° rotations to apply. """ - self._main_image.rotation = value + self._main_image.num_rotation_90 = value @SafeProperty(bool) def transpose(self) -> bool: diff --git a/bec_widgets/widgets/plots/image/image_item.py b/bec_widgets/widgets/plots/image/image_item.py index 7c36e5dd..72ffc6a3 100644 --- a/bec_widgets/widgets/plots/image/image_item.py +++ b/bec_widgets/widgets/plots/image/image_item.py @@ -239,13 +239,13 @@ class ImageItem(BECConnector, pg.ImageItem): self._process_image() @property - def rotation(self) -> Optional[int]: + def num_rotation_90(self) -> Optional[int]: """Get or set the number of 90° rotations to apply.""" - return self.config.processing.rotation + return self.config.processing.num_rotation_90 - @rotation.setter - def rotation(self, value: Optional[int]): - self.config.processing.rotation = value + @num_rotation_90.setter + def num_rotation_90(self, value: Optional[int]): + self.config.processing.num_rotation_90 = value self._process_image() @property diff --git a/bec_widgets/widgets/plots/image/image_processor.py b/bec_widgets/widgets/plots/image/image_processor.py index 77360fec..f1662dca 100644 --- a/bec_widgets/widgets/plots/image/image_processor.py +++ b/bec_widgets/widgets/plots/image/image_processor.py @@ -37,7 +37,7 @@ class ProcessingConfig(BaseModel): transpose: bool = Field( False, description="Whether to transpose the monitor data before displaying." ) - rotation: int = Field( + num_rotation_90: int = Field( 0, description="The rotation angle of the monitor data before displaying." ) stats: ImageStats = Field( @@ -140,8 +140,8 @@ class ImageProcessor(QObject): """Core processing logic without threading overhead.""" if self.config.fft: data = self.FFT(data) - if self.config.rotation is not None: - data = self.rotation(data, self.config.rotation) + if self.config.num_rotation_90 is not None: + data = self.rotation(data, self.config.num_rotation_90) if self.config.transpose: data = self.transpose(data) if self.config.log: diff --git a/bec_widgets/widgets/plots/image/toolbar_bundles/processing.py b/bec_widgets/widgets/plots/image/toolbar_bundles/processing.py index f39fdc5b..2dc16e9e 100644 --- a/bec_widgets/widgets/plots/image/toolbar_bundles/processing.py +++ b/bec_widgets/widgets/plots/image/toolbar_bundles/processing.py @@ -55,24 +55,24 @@ class ImageProcessingToolbarBundle(ToolbarBundle): @SafeSlot() def rotate_right(self): - if self.target_widget.rotation is None: + if self.target_widget.num_rotation_90 is None: return - rotation = (self.target_widget.rotation - 1) % 4 - self.target_widget.rotation = rotation + rotation = (self.target_widget.num_rotation_90 - 1) % 4 + self.target_widget.num_rotation_90 = rotation @SafeSlot() def rotate_left(self): - if self.target_widget.rotation is None: + if self.target_widget.num_rotation_90 is None: return - rotation = (self.target_widget.rotation + 1) % 4 - self.target_widget.rotation = rotation + rotation = (self.target_widget.num_rotation_90 + 1) % 4 + self.target_widget.num_rotation_90 = rotation @SafeSlot() def reset_settings(self): self.target_widget.fft = False self.target_widget.log = False self.target_widget.transpose = False - self.target_widget.rotation = 0 + self.target_widget.num_rotation_90 = 0 self.fft.action.setChecked(False) self.log.action.setChecked(False) diff --git a/bec_widgets/widgets/plots/waveform/waveform.py b/bec_widgets/widgets/plots/waveform/waveform.py index bb092d82..e74b2133 100644 --- a/bec_widgets/widgets/plots/waveform/waveform.py +++ b/bec_widgets/widgets/plots/waveform/waveform.py @@ -90,6 +90,8 @@ class Waveform(PlotBase): "curves", "x_mode", "x_mode.setter", + "x_entry", + "x_entry.setter", "color_palette", "color_palette.setter", "plot", diff --git a/tests/unit_tests/test_image_view_next_gen.py b/tests/unit_tests/test_image_view_next_gen.py index 9adf9485..231b7e54 100644 --- a/tests/unit_tests/test_image_view_next_gen.py +++ b/tests/unit_tests/test_image_view_next_gen.py @@ -192,8 +192,8 @@ def test_image_processing_log_toggle(qtbot, mocked_client): def test_image_rotation_and_transpose(qtbot, mocked_client): bec_image_view = create_widget(qtbot, Image, client=mocked_client) - bec_image_view.rotation = 2 - assert bec_image_view.rotation == 2 + bec_image_view.num_rotation_90 = 2 + assert bec_image_view.num_rotation_90 == 2 bec_image_view.transpose = True assert bec_image_view.transpose is True @@ -294,9 +294,9 @@ def test_image_toggle_action_rotate_right(qtbot, mocked_client): bec_image_view.processing_bundle.right.action.trigger() - assert bec_image_view.rotation == 3 - assert bec_image_view.main_image.rotation == 3 - assert bec_image_view.main_image.config.processing.rotation == 3 + assert bec_image_view.num_rotation_90 == 3 + assert bec_image_view.main_image.num_rotation_90 == 3 + assert bec_image_view.main_image.config.processing.num_rotation_90 == 3 def test_image_toggle_action_rotate_left(qtbot, mocked_client): @@ -304,9 +304,9 @@ def test_image_toggle_action_rotate_left(qtbot, mocked_client): bec_image_view.processing_bundle.left.action.trigger() - assert bec_image_view.rotation == 1 - assert bec_image_view.main_image.rotation == 1 - assert bec_image_view.main_image.config.processing.rotation == 1 + assert bec_image_view.num_rotation_90 == 1 + assert bec_image_view.main_image.num_rotation_90 == 1 + assert bec_image_view.main_image.config.processing.num_rotation_90 == 1 def test_image_toggle_action_reset(qtbot, mocked_client): @@ -316,13 +316,13 @@ def test_image_toggle_action_reset(qtbot, mocked_client): bec_image_view.fft = True bec_image_view.log = True bec_image_view.transpose = True - bec_image_view.rotation = 2 + bec_image_view.num_rotation_90 = 2 bec_image_view.processing_bundle.reset.action.trigger() - assert bec_image_view.rotation == 0 - assert bec_image_view.main_image.rotation == 0 - assert bec_image_view.main_image.config.processing.rotation == 0 + assert bec_image_view.num_rotation_90 == 0 + assert bec_image_view.main_image.num_rotation_90 == 0 + assert bec_image_view.main_image.config.processing.num_rotation_90 == 0 assert bec_image_view.fft is False assert bec_image_view.main_image.fft is False assert bec_image_view.log is False