mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
fix(bar): ring saves current value in config
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
# This file was automatically generated by generate_cli.py
|
||||
|
||||
from bec_widgets.cli.client_utils import rpc_call, RPCBase, BECGuiClientMixin
|
||||
from typing import Literal, Optional, overload
|
||||
|
||||
from bec_widgets.cli.client_utils import BECGuiClientMixin, RPCBase, rpc_call
|
||||
|
||||
|
||||
class BECPlotBase(RPCBase):
|
||||
@property
|
||||
|
@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Literal, Optional, Any
|
||||
from typing import TYPE_CHECKING, Any, Literal, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pyqtgraph.dockarea import Dock
|
||||
|
@ -36,6 +36,7 @@ class RingConnections(BaseModel):
|
||||
|
||||
|
||||
class RingConfig(ConnectionConfig):
|
||||
value: int | float | None = Field(0, description="Value for the progress bars.")
|
||||
direction: int | None = Field(
|
||||
-1, description="Direction of the progress bars. -1 for clockwise, 1 for counter-clockwise."
|
||||
)
|
||||
@ -102,7 +103,6 @@ class Ring(BECConnector):
|
||||
self.background_color = None
|
||||
self.start_position = None
|
||||
self.config = config
|
||||
self.value = 0
|
||||
self.RID = None
|
||||
self._init_config_params()
|
||||
|
||||
@ -114,7 +114,7 @@ class Ring(BECConnector):
|
||||
self.set_connections(self.config.connections.slot, self.config.connections.endpoint)
|
||||
|
||||
def set_value(self, value: int | float):
|
||||
self.value = round(
|
||||
self.config.value = round(
|
||||
max(self.config.min_value, min(self.config.max_value, value)), self.config.precision
|
||||
)
|
||||
|
||||
|
@ -115,7 +115,6 @@ class SpiralProgressBar(BECConnector, QWidget):
|
||||
self.entry_validator = EntryValidator(self.dev)
|
||||
|
||||
self.RID = None
|
||||
self.values = None
|
||||
|
||||
# For updating bar behaviour
|
||||
self._auto_updates = True
|
||||
@ -544,7 +543,7 @@ class SpiralProgressBar(BECConnector, QWidget):
|
||||
pen = QtGui.QPen(ring.color, ring.config.line_width, QtCore.Qt.SolidLine)
|
||||
pen.setCapStyle(QtCore.Qt.RoundCap)
|
||||
painter.setPen(pen)
|
||||
proportion = (ring.value - ring.config.min_value) / (
|
||||
proportion = (ring.config.value - ring.config.min_value) / (
|
||||
(ring.config.max_value - ring.config.min_value) + 1e-3
|
||||
)
|
||||
angle = int(proportion * 360 * 16 * ring.config.direction)
|
||||
|
@ -163,7 +163,7 @@ def test_spiral_bar(rpc_server_dock):
|
||||
|
||||
expected_colors = Colors.golden_angle_color("viridis", 5, "RGB")
|
||||
bar_colors = [ring.color.getRgb() for ring in bar_server.rings]
|
||||
bar_values = [ring.value for ring in bar_server.rings]
|
||||
bar_values = [ring.config.value for ring in bar_server.rings]
|
||||
assert bar_values == [10, 20, 30, 40, 50]
|
||||
assert bar_colors == expected_colors
|
||||
|
||||
@ -188,7 +188,7 @@ def test_spiral_bar_scan_update(rpc_server_dock, qtbot):
|
||||
qtbot.wait(200)
|
||||
bar_server = dock_server.docks["dock_0"].widgets[0]
|
||||
assert bar_server.config.num_bars == 1
|
||||
np.testing.assert_allclose(bar_server.rings[0].value, 10, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.value, 10, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.min_value, 0, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.max_value, 10, atol=0.1)
|
||||
|
||||
@ -199,7 +199,7 @@ def test_spiral_bar_scan_update(rpc_server_dock, qtbot):
|
||||
|
||||
qtbot.wait(200)
|
||||
assert bar_server.config.num_bars == 1
|
||||
np.testing.assert_allclose(bar_server.rings[0].value, 16, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.value, 16, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.min_value, 0, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.max_value, 16, atol=0.1)
|
||||
|
||||
@ -218,8 +218,8 @@ def test_spiral_bar_scan_update(rpc_server_dock, qtbot):
|
||||
|
||||
qtbot.wait(200)
|
||||
assert bar_server.config.num_bars == 2
|
||||
np.testing.assert_allclose(bar_server.rings[0].value, final_samx, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[1].value, final_samy, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.value, final_samx, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[1].config.value, final_samy, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.min_value, init_samx, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[1].config.min_value, init_samy, atol=0.1)
|
||||
np.testing.assert_allclose(bar_server.rings[0].config.max_value, final_samx, atol=0.1)
|
||||
|
@ -145,12 +145,12 @@ def test_bar_set_value(spiral_progress_bar):
|
||||
assert len(spiral_progress_bar.rings) == 5
|
||||
|
||||
spiral_progress_bar.set_value([10, 20, 30, 40, 50])
|
||||
ring_values = [ring.value for ring in spiral_progress_bar.rings]
|
||||
ring_values = [ring.config.value for ring in spiral_progress_bar.rings]
|
||||
assert ring_values == [10, 20, 30, 40, 50]
|
||||
|
||||
# update just one bar
|
||||
spiral_progress_bar.set_value(90, 1)
|
||||
ring_values = [ring.value for ring in spiral_progress_bar.rings]
|
||||
ring_values = [ring.config.value for ring in spiral_progress_bar.rings]
|
||||
assert ring_values == [10, 90, 30, 40, 50]
|
||||
|
||||
|
||||
@ -166,7 +166,7 @@ def test_bar_set_precision(spiral_progress_bar):
|
||||
assert ring_precision == [2, 2, 2]
|
||||
|
||||
spiral_progress_bar.set_value([10.1234, 20.1234, 30.1234])
|
||||
ring_values = [ring.value for ring in spiral_progress_bar.rings]
|
||||
ring_values = [ring.config.value for ring in spiral_progress_bar.rings]
|
||||
assert ring_values == [10.12, 20.12, 30.12]
|
||||
|
||||
spiral_progress_bar.set_precision(4, 1)
|
||||
@ -174,7 +174,7 @@ def test_bar_set_precision(spiral_progress_bar):
|
||||
assert ring_precision == [2, 4, 2]
|
||||
|
||||
spiral_progress_bar.set_value([10.1234, 20.1234, 30.1234])
|
||||
ring_values = [ring.value for ring in spiral_progress_bar.rings]
|
||||
ring_values = [ring.config.value for ring in spiral_progress_bar.rings]
|
||||
assert ring_values == [10.12, 20.1234, 30.12]
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ def test_set_min_max_value(spiral_progress_bar):
|
||||
assert ring_max_values == [10, 10]
|
||||
|
||||
spiral_progress_bar.set_value([5, 15])
|
||||
ring_values = [ring.value for ring in spiral_progress_bar.rings]
|
||||
ring_values = [ring.config.value for ring in spiral_progress_bar.rings]
|
||||
assert ring_values == [5, 10]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user