mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat(widgets/figure): clear_all method for BECFigure
This commit is contained in:
@ -62,19 +62,33 @@ class BECPlotBase(RPCBase):
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_x_lim(self, x_lim: "tuple") -> "None":
|
||||
def set_x_lim(self, *args) -> "None":
|
||||
"""
|
||||
Set the limits of the x-axis.
|
||||
Set the limits of the x-axis. This method can accept either two separate arguments
|
||||
for the minimum and maximum x-axis values, or a single tuple containing both limits.
|
||||
|
||||
Usage:
|
||||
set_x_lim(x_min, x_max)
|
||||
set_x_lim((x_min, x_max))
|
||||
|
||||
Args:
|
||||
x_lim(tuple): Limits of the x-axis.
|
||||
*args: A variable number of arguments. Can be two integers (x_min and x_max)
|
||||
or a single tuple with two integers.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def set_y_lim(self, y_lim: "tuple") -> "None":
|
||||
def set_y_lim(self, *args) -> "None":
|
||||
"""
|
||||
Set the limits of the y-axis.
|
||||
Set the limits of the y-axis. This method can accept either two separate arguments
|
||||
for the minimum and maximum y-axis values, or a single tuple containing both limits.
|
||||
|
||||
Usage:
|
||||
set_y_lim(y_min, y_max)
|
||||
set_y_lim((y_min, y_max))
|
||||
|
||||
Args:
|
||||
y_lim(tuple): Limits of the y-axis.
|
||||
*args: A variable number of arguments. Can be two integers (y_min and y_max)
|
||||
or a single tuple with two integers.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
@ -273,6 +287,12 @@ class BECFigure(RPCBase, BECFigureClientMixin):
|
||||
theme(Literal["dark","light"]): The theme to set for the figure widget.
|
||||
"""
|
||||
|
||||
@rpc_call
|
||||
def clear_all(self):
|
||||
"""
|
||||
Clear all widgets from the figure and reset to default state
|
||||
"""
|
||||
|
||||
|
||||
class BECCurve(RPCBase):
|
||||
@rpc_call
|
||||
|
@ -83,7 +83,7 @@ class WidgetHandler:
|
||||
|
||||
|
||||
class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
|
||||
USER_ACCESS = ["add_plot", "remove", "change_layout", "change_theme"]
|
||||
USER_ACCESS = ["add_plot", "remove", "change_layout", "change_theme", "clear_all"]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -381,6 +381,16 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
|
||||
self._reindex_grid() # This method should be updated to handle reshuffling correctly
|
||||
self._replot_layout() # Assumes this method re-adds widgets to the layout based on self.grid
|
||||
|
||||
def clear_all(self):
|
||||
"""Clear all widgets from the figure and reset to default state"""
|
||||
self.clear()
|
||||
self.widgets = defaultdict(dict)
|
||||
self.grid = []
|
||||
theme = self.config.theme
|
||||
self.config = FigureConfig(
|
||||
widget_class=self.__class__.__name__, gui_id=self.gui_id, theme=theme
|
||||
)
|
||||
|
||||
def start(self):
|
||||
import sys
|
||||
|
||||
|
9
setup.py
9
setup.py
@ -32,7 +32,14 @@ if __name__ == "__main__":
|
||||
"pyqtdarktheme",
|
||||
],
|
||||
extras_require={
|
||||
"dev": ["pytest", "pytest-random-order", "coverage", "pytest-qt", "black"],
|
||||
"dev": [
|
||||
"pytest",
|
||||
"pytest-random-order",
|
||||
"pytest-timeout",
|
||||
"coverage",
|
||||
"pytest-qt",
|
||||
"black",
|
||||
],
|
||||
"pyqt5": ["PyQt5>=5.9"],
|
||||
"pyqt6": ["PyQt6>=6.0"],
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
# pylint: disable = no-name-in-module,missing-class-docstring, missing-module-docstring
|
||||
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
@ -212,3 +212,15 @@ def test_change_layout(bec_figure):
|
||||
assert bec_figure[0, 1] == w2
|
||||
assert bec_figure[0, 2] == w3
|
||||
assert bec_figure[0, 3] == w4
|
||||
|
||||
|
||||
def test_clear_all(bec_figure):
|
||||
bec_figure.add_plot(widget_id="test_waveform_1", row=0, col=0)
|
||||
bec_figure.add_plot(widget_id="test_waveform_2", row=0, col=1)
|
||||
bec_figure.add_plot(widget_id="test_waveform_3", row=1, col=0)
|
||||
bec_figure.add_plot(widget_id="test_waveform_4", row=1, col=1)
|
||||
|
||||
bec_figure.clear_all()
|
||||
|
||||
assert len(bec_figure.widgets) == 0
|
||||
assert np.shape(bec_figure.grid) == (0,)
|
||||
|
@ -1,3 +1,4 @@
|
||||
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||
import pytest
|
||||
from .client_mocks import mocked_client
|
||||
from .test_bec_figure import bec_figure
|
||||
|
Reference in New Issue
Block a user