0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

refactor(plots): waveform and image rpc api review

This commit is contained in:
2025-04-29 17:55:01 +02:00
parent 8eef4253b0
commit a3de1f0a31
7 changed files with 57 additions and 89 deletions

View File

@ -951,48 +951,6 @@ class Image(RPCBase):
Set auto range for the y-axis. 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 @property
@rpc_call @rpc_call
def color_map(self) -> "str": def color_map(self) -> "str":
@ -1187,16 +1145,16 @@ class Image(RPCBase):
@property @property
@rpc_call @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 @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 @property
@ -3364,6 +3322,20 @@ class Waveform(RPCBase):
None 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 @property
@rpc_call @rpc_call
def color_palette(self) -> "str": def color_palette(self) -> "str":

View File

@ -79,12 +79,6 @@ class Image(PlotBase):
"auto_range_x.setter", "auto_range_x.setter",
"auto_range_y", "auto_range_y",
"auto_range_y.setter", "auto_range_y.setter",
"x_log",
"x_log.setter",
"y_log",
"y_log.setter",
"legend_label_size",
"legend_label_size.setter",
# ImageView Specific Settings # ImageView Specific Settings
"color_map", "color_map",
"color_map.setter", "color_map.setter",
@ -111,8 +105,8 @@ class Image(PlotBase):
"fft.setter", "fft.setter",
"log", "log",
"log.setter", "log.setter",
"rotation", "num_rotation_90",
"rotation.setter", "num_rotation_90.setter",
"transpose", "transpose",
"transpose.setter", "transpose.setter",
"image", "image",
@ -656,21 +650,21 @@ class Image(PlotBase):
self._main_image.log = enable self._main_image.log = enable
@SafeProperty(int) @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 @num_rotation_90.setter
def rotation(self, value: int): 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: Args:
value(int): The number of 90° rotations to apply. value(int): The number of 90° rotations to apply.
""" """
self._main_image.rotation = value self._main_image.num_rotation_90 = value
@SafeProperty(bool) @SafeProperty(bool)
def transpose(self) -> bool: def transpose(self) -> bool:

View File

@ -239,13 +239,13 @@ class ImageItem(BECConnector, pg.ImageItem):
self._process_image() self._process_image()
@property @property
def rotation(self) -> Optional[int]: def num_rotation_90(self) -> Optional[int]:
"""Get or set the number of 90° rotations to apply.""" """Get or set the number of 90° rotations to apply."""
return self.config.processing.rotation return self.config.processing.num_rotation_90
@rotation.setter @num_rotation_90.setter
def rotation(self, value: Optional[int]): def num_rotation_90(self, value: Optional[int]):
self.config.processing.rotation = value self.config.processing.num_rotation_90 = value
self._process_image() self._process_image()
@property @property

View File

@ -37,7 +37,7 @@ class ProcessingConfig(BaseModel):
transpose: bool = Field( transpose: bool = Field(
False, description="Whether to transpose the monitor data before displaying." 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." 0, description="The rotation angle of the monitor data before displaying."
) )
stats: ImageStats = Field( stats: ImageStats = Field(
@ -140,8 +140,8 @@ class ImageProcessor(QObject):
"""Core processing logic without threading overhead.""" """Core processing logic without threading overhead."""
if self.config.fft: if self.config.fft:
data = self.FFT(data) data = self.FFT(data)
if self.config.rotation is not None: if self.config.num_rotation_90 is not None:
data = self.rotation(data, self.config.rotation) data = self.rotation(data, self.config.num_rotation_90)
if self.config.transpose: if self.config.transpose:
data = self.transpose(data) data = self.transpose(data)
if self.config.log: if self.config.log:

View File

@ -55,24 +55,24 @@ class ImageProcessingToolbarBundle(ToolbarBundle):
@SafeSlot() @SafeSlot()
def rotate_right(self): def rotate_right(self):
if self.target_widget.rotation is None: if self.target_widget.num_rotation_90 is None:
return return
rotation = (self.target_widget.rotation - 1) % 4 rotation = (self.target_widget.num_rotation_90 - 1) % 4
self.target_widget.rotation = rotation self.target_widget.num_rotation_90 = rotation
@SafeSlot() @SafeSlot()
def rotate_left(self): def rotate_left(self):
if self.target_widget.rotation is None: if self.target_widget.num_rotation_90 is None:
return return
rotation = (self.target_widget.rotation + 1) % 4 rotation = (self.target_widget.num_rotation_90 + 1) % 4
self.target_widget.rotation = rotation self.target_widget.num_rotation_90 = rotation
@SafeSlot() @SafeSlot()
def reset_settings(self): def reset_settings(self):
self.target_widget.fft = False self.target_widget.fft = False
self.target_widget.log = False self.target_widget.log = False
self.target_widget.transpose = False self.target_widget.transpose = False
self.target_widget.rotation = 0 self.target_widget.num_rotation_90 = 0
self.fft.action.setChecked(False) self.fft.action.setChecked(False)
self.log.action.setChecked(False) self.log.action.setChecked(False)

View File

@ -90,6 +90,8 @@ class Waveform(PlotBase):
"curves", "curves",
"x_mode", "x_mode",
"x_mode.setter", "x_mode.setter",
"x_entry",
"x_entry.setter",
"color_palette", "color_palette",
"color_palette.setter", "color_palette.setter",
"plot", "plot",

View File

@ -192,8 +192,8 @@ def test_image_processing_log_toggle(qtbot, mocked_client):
def test_image_rotation_and_transpose(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 = create_widget(qtbot, Image, client=mocked_client)
bec_image_view.rotation = 2 bec_image_view.num_rotation_90 = 2
assert bec_image_view.rotation == 2 assert bec_image_view.num_rotation_90 == 2
bec_image_view.transpose = True bec_image_view.transpose = True
assert bec_image_view.transpose is 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() bec_image_view.processing_bundle.right.action.trigger()
assert bec_image_view.rotation == 3 assert bec_image_view.num_rotation_90 == 3
assert bec_image_view.main_image.rotation == 3 assert bec_image_view.main_image.num_rotation_90 == 3
assert bec_image_view.main_image.config.processing.rotation == 3 assert bec_image_view.main_image.config.processing.num_rotation_90 == 3
def test_image_toggle_action_rotate_left(qtbot, mocked_client): 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() bec_image_view.processing_bundle.left.action.trigger()
assert bec_image_view.rotation == 1 assert bec_image_view.num_rotation_90 == 1
assert bec_image_view.main_image.rotation == 1 assert bec_image_view.main_image.num_rotation_90 == 1
assert bec_image_view.main_image.config.processing.rotation == 1 assert bec_image_view.main_image.config.processing.num_rotation_90 == 1
def test_image_toggle_action_reset(qtbot, mocked_client): 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.fft = True
bec_image_view.log = True bec_image_view.log = True
bec_image_view.transpose = 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() bec_image_view.processing_bundle.reset.action.trigger()
assert bec_image_view.rotation == 0 assert bec_image_view.num_rotation_90 == 0
assert bec_image_view.main_image.rotation == 0 assert bec_image_view.main_image.num_rotation_90 == 0
assert bec_image_view.main_image.config.processing.rotation == 0 assert bec_image_view.main_image.config.processing.num_rotation_90 == 0
assert bec_image_view.fft is False assert bec_image_view.fft is False
assert bec_image_view.main_image.fft is False assert bec_image_view.main_image.fft is False
assert bec_image_view.log is False assert bec_image_view.log is False