mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(plot_indicators): plot indicators added to the PlotBase
This commit is contained in:
@ -171,7 +171,7 @@ class BECArrowItem(BECIndicatorItem):
|
|||||||
|
|
||||||
def __init__(self, plot_item: pg.PlotItem = None, parent=None):
|
def __init__(self, plot_item: pg.PlotItem = None, parent=None):
|
||||||
super().__init__(plot_item=plot_item, parent=parent)
|
super().__init__(plot_item=plot_item, parent=parent)
|
||||||
self.arrow_item = pg.ArrowItem(parent=parent)
|
self.arrow_item = pg.ArrowItem()
|
||||||
self.arrow_item.skip_auto_range = True
|
self.arrow_item.skip_auto_range = True
|
||||||
self._pos = (0, 0)
|
self._pos = (0, 0)
|
||||||
self.arrow_item.setVisible(False)
|
self.arrow_item.setVisible(False)
|
||||||
|
@ -16,6 +16,7 @@ from bec_widgets.qt_utils.toolbar import MaterialIconAction, ModularToolBar, Too
|
|||||||
from bec_widgets.utils import ConnectionConfig, Crosshair, EntryValidator
|
from bec_widgets.utils import ConnectionConfig, Crosshair, EntryValidator
|
||||||
from bec_widgets.utils.bec_widget import BECWidget
|
from bec_widgets.utils.bec_widget import BECWidget
|
||||||
from bec_widgets.utils.fps_counter import FPSCounter
|
from bec_widgets.utils.fps_counter import FPSCounter
|
||||||
|
from bec_widgets.utils.plot_indicator_items import BECArrowItem, BECTickItem
|
||||||
from bec_widgets.utils.widget_state_manager import WidgetStateManager
|
from bec_widgets.utils.widget_state_manager import WidgetStateManager
|
||||||
from bec_widgets.widgets.containers.layout_manager.layout_manager import LayoutManagerWidget
|
from bec_widgets.widgets.containers.layout_manager.layout_manager import LayoutManagerWidget
|
||||||
from bec_widgets.widgets.plots_next_gen.setting_menus.axis_settings import AxisSettings
|
from bec_widgets.widgets.plots_next_gen.setting_menus.axis_settings import AxisSettings
|
||||||
@ -115,6 +116,10 @@ class PlotBase(BECWidget, QWidget):
|
|||||||
self._user_y_label = ""
|
self._user_y_label = ""
|
||||||
self._y_label_suffix = ""
|
self._y_label_suffix = ""
|
||||||
|
|
||||||
|
# Plot Indicator Items
|
||||||
|
self.tick_item = BECTickItem(parent=self, plot_item=self.plot_item)
|
||||||
|
self.arrow_item = BECArrowItem(parent=self, plot_item=self.plot_item)
|
||||||
|
|
||||||
self._init_ui()
|
self._init_ui()
|
||||||
|
|
||||||
self._connect_to_theme_change()
|
self._connect_to_theme_change()
|
||||||
@ -967,6 +972,8 @@ class PlotBase(BECWidget, QWidget):
|
|||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
self.unhook_crosshair()
|
self.unhook_crosshair()
|
||||||
self.unhook_fps_monitor(delete_label=True)
|
self.unhook_fps_monitor(delete_label=True)
|
||||||
|
self.tick_item.cleanup()
|
||||||
|
self.arrow_item.cleanup()
|
||||||
if self.axis_settings_dialog is not None:
|
if self.axis_settings_dialog is not None:
|
||||||
self.axis_settings_dialog.close()
|
self.axis_settings_dialog.close()
|
||||||
self.axis_settings_dialog = None
|
self.axis_settings_dialog = None
|
||||||
|
@ -1,114 +1,111 @@
|
|||||||
# TODO temporary disabled until migrate tick and arrow items to new system
|
import pytest
|
||||||
# import pytest
|
from qtpy.QtCore import QPointF
|
||||||
# from qtpy.QtCore import QPointF
|
|
||||||
#
|
from bec_widgets.widgets.plots_next_gen.waveform.waveform import Waveform
|
||||||
# from bec_widgets.widgets.containers.figure import BECFigure
|
|
||||||
#
|
from .client_mocks import mocked_client
|
||||||
# from .client_mocks import mocked_client
|
|
||||||
#
|
|
||||||
#
|
@pytest.fixture
|
||||||
# @pytest.fixture
|
def plot_widget_with_arrow_item(qtbot, mocked_client):
|
||||||
# def plot_widget_with_arrow_item(qtbot, mocked_client):
|
widget = Waveform(client=mocked_client())
|
||||||
# widget = BECFigure(client=mocked_client())
|
qtbot.addWidget(widget)
|
||||||
# qtbot.addWidget(widget)
|
qtbot.waitExposed(widget)
|
||||||
# qtbot.waitExposed(widget)
|
|
||||||
# waveform = widget.plot()
|
yield widget.arrow_item, widget.plot_item
|
||||||
#
|
|
||||||
# yield waveform.arrow_item, waveform.plot_item
|
|
||||||
#
|
@pytest.fixture
|
||||||
#
|
def plot_widget_with_tick_item(qtbot, mocked_client):
|
||||||
# @pytest.fixture
|
widget = Waveform(client=mocked_client())
|
||||||
# def plot_widget_with_tick_item(qtbot, mocked_client):
|
qtbot.addWidget(widget)
|
||||||
# widget = BECFigure(client=mocked_client())
|
qtbot.waitExposed(widget)
|
||||||
# qtbot.addWidget(widget)
|
|
||||||
# qtbot.waitExposed(widget)
|
yield widget.tick_item, widget.plot_item
|
||||||
# waveform = widget.plot()
|
|
||||||
#
|
|
||||||
# yield waveform.tick_item, waveform.plot_item
|
def test_arrow_item_add_to_plot(plot_widget_with_arrow_item):
|
||||||
#
|
"""Test the add_to_plot method"""
|
||||||
#
|
arrow_item, plot_item = plot_widget_with_arrow_item
|
||||||
# def test_arrow_item_add_to_plot(plot_widget_with_arrow_item):
|
assert arrow_item.plot_item is not None
|
||||||
# """Test the add_to_plot method"""
|
assert arrow_item.plot_item.items == []
|
||||||
# arrow_item, plot_item = plot_widget_with_arrow_item
|
arrow_item.add_to_plot()
|
||||||
# assert arrow_item.plot_item is not None
|
assert arrow_item.plot_item.items == [arrow_item.arrow_item]
|
||||||
# assert arrow_item.plot_item.items == []
|
arrow_item.remove_from_plot()
|
||||||
# arrow_item.add_to_plot()
|
|
||||||
# assert arrow_item.plot_item.items == [arrow_item.arrow_item]
|
|
||||||
# arrow_item.remove_from_plot()
|
def test_arrow_item_set_position(plot_widget_with_arrow_item):
|
||||||
#
|
"""Test the set_position method"""
|
||||||
#
|
arrow_item, plot_item = plot_widget_with_arrow_item
|
||||||
# def test_arrow_item_set_position(plot_widget_with_arrow_item):
|
container = []
|
||||||
# """Test the set_position method"""
|
|
||||||
# arrow_item, plot_item = plot_widget_with_arrow_item
|
def signal_callback(tup: tuple):
|
||||||
# container = []
|
container.append(tup)
|
||||||
#
|
|
||||||
# def signal_callback(tup: tuple):
|
arrow_item.add_to_plot()
|
||||||
# container.append(tup)
|
arrow_item.position_changed.connect(signal_callback)
|
||||||
#
|
arrow_item.set_position(pos=(1, 1))
|
||||||
# arrow_item.add_to_plot()
|
point = QPointF(1.0, 1.0)
|
||||||
# arrow_item.position_changed.connect(signal_callback)
|
assert arrow_item.arrow_item.pos() == point
|
||||||
# arrow_item.set_position(pos=(1, 1))
|
arrow_item.set_position(pos=(2, 2))
|
||||||
# point = QPointF(1.0, 1.0)
|
point = QPointF(2.0, 2.0)
|
||||||
# assert arrow_item.arrow_item.pos() == point
|
assert arrow_item.arrow_item.pos() == point
|
||||||
# arrow_item.set_position(pos=(2, 2))
|
assert container == [(1, 1), (2, 2)]
|
||||||
# point = QPointF(2.0, 2.0)
|
arrow_item.remove_from_plot()
|
||||||
# assert arrow_item.arrow_item.pos() == point
|
|
||||||
# assert container == [(1, 1), (2, 2)]
|
|
||||||
# arrow_item.remove_from_plot()
|
def test_arrow_item_cleanup(plot_widget_with_arrow_item):
|
||||||
#
|
"""Test cleanup procedure"""
|
||||||
#
|
arrow_item, plot_item = plot_widget_with_arrow_item
|
||||||
# def test_arrow_item_cleanup(plot_widget_with_arrow_item):
|
arrow_item.add_to_plot()
|
||||||
# """Test cleanup procedure"""
|
assert arrow_item.item_on_plot is True
|
||||||
# arrow_item, plot_item = plot_widget_with_arrow_item
|
arrow_item.cleanup()
|
||||||
# arrow_item.add_to_plot()
|
assert arrow_item.plot_item.items == []
|
||||||
# assert arrow_item.item_on_plot is True
|
assert arrow_item.item_on_plot is False
|
||||||
# arrow_item.cleanup()
|
assert arrow_item.arrow_item is None
|
||||||
# assert arrow_item.plot_item.items == []
|
|
||||||
# assert arrow_item.item_on_plot is False
|
|
||||||
# assert arrow_item.arrow_item is None
|
def test_tick_item_add_to_plot(plot_widget_with_tick_item):
|
||||||
#
|
"""Test the add_to_plot method"""
|
||||||
#
|
tick_item, plot_item = plot_widget_with_tick_item
|
||||||
# def test_tick_item_add_to_plot(plot_widget_with_tick_item):
|
assert tick_item.plot_item is not None
|
||||||
# """Test the add_to_plot method"""
|
assert tick_item.plot_item.items == []
|
||||||
# tick_item, plot_item = plot_widget_with_tick_item
|
tick_item.add_to_plot()
|
||||||
# assert tick_item.plot_item is not None
|
assert tick_item.plot_item.layout.itemAt(2, 1) == tick_item.tick_item
|
||||||
# assert tick_item.plot_item.items == []
|
assert tick_item.item_on_plot is True
|
||||||
# tick_item.add_to_plot()
|
new_pos = plot_item.vb.geometry().bottom()
|
||||||
# assert tick_item.plot_item.layout.itemAt(2, 1) == tick_item.tick_item
|
pos = tick_item.tick.pos()
|
||||||
# assert tick_item.item_on_plot is True
|
new_pos = tick_item.tick_item.mapFromParent(QPointF(pos.x(), new_pos))
|
||||||
# new_pos = plot_item.vb.geometry().bottom()
|
assert new_pos.y() == pos.y()
|
||||||
# pos = tick_item.tick.pos()
|
tick_item.remove_from_plot()
|
||||||
# new_pos = tick_item.tick_item.mapFromParent(QPointF(pos.x(), new_pos))
|
|
||||||
# assert new_pos.y() == pos.y()
|
|
||||||
# tick_item.remove_from_plot()
|
def test_tick_item_set_position(plot_widget_with_tick_item):
|
||||||
#
|
"""Test the set_position method"""
|
||||||
#
|
tick_item, plot_item = plot_widget_with_tick_item
|
||||||
# def test_tick_item_set_position(plot_widget_with_tick_item):
|
container = []
|
||||||
# """Test the set_position method"""
|
|
||||||
# tick_item, plot_item = plot_widget_with_tick_item
|
def signal_callback(val: float):
|
||||||
# container = []
|
container.append(val)
|
||||||
#
|
|
||||||
# def signal_callback(val: float):
|
tick_item.add_to_plot()
|
||||||
# container.append(val)
|
tick_item.position_changed.connect(signal_callback)
|
||||||
#
|
|
||||||
# tick_item.add_to_plot()
|
tick_item.set_position(pos=1)
|
||||||
# tick_item.position_changed.connect(signal_callback)
|
assert tick_item._pos == 1
|
||||||
#
|
tick_item.set_position(pos=2)
|
||||||
# tick_item.set_position(pos=1)
|
assert tick_item._pos == 2
|
||||||
# assert tick_item._pos == 1
|
assert container == [1.0, 2.0]
|
||||||
# tick_item.set_position(pos=2)
|
tick_item.remove_from_plot()
|
||||||
# assert tick_item._pos == 2
|
|
||||||
# assert container == [1.0, 2.0]
|
|
||||||
# tick_item.remove_from_plot()
|
def test_tick_item_cleanup(plot_widget_with_tick_item):
|
||||||
#
|
"""Test cleanup procedure"""
|
||||||
#
|
tick_item, plot_item = plot_widget_with_tick_item
|
||||||
# def test_tick_item_cleanup(plot_widget_with_tick_item):
|
tick_item.add_to_plot()
|
||||||
# """Test cleanup procedure"""
|
assert tick_item.item_on_plot is True
|
||||||
# tick_item, plot_item = plot_widget_with_tick_item
|
tick_item.cleanup()
|
||||||
# tick_item.add_to_plot()
|
ticks = getattr(tick_item.plot_item.layout.itemAt(3, 1), "ticks", None)
|
||||||
# assert tick_item.item_on_plot is True
|
assert ticks == None
|
||||||
# tick_item.cleanup()
|
assert tick_item.item_on_plot is False
|
||||||
# ticks = getattr(tick_item.plot_item.layout.itemAt(3, 1), "ticks", None)
|
assert tick_item.tick_item is None
|
||||||
# assert ticks == None
|
|
||||||
# assert tick_item.item_on_plot is False
|
|
||||||
# assert tick_item.tick_item is None
|
|
||||||
|
Reference in New Issue
Block a user