From 80e0ccbeb7c4ea0b664e0feafbe8d31b207cf9fa Mon Sep 17 00:00:00 2001 From: fdrgsp Date: Sun, 4 Aug 2024 20:35:43 -0400 Subject: [PATCH] test: update --- examples/temp/plate_navigator_widget.py | 4 +- .../hcs/_plate_navigator_widget.py | 2 +- tests/test_hcs/test_plate_navigator.py | 77 +++++++++++++++++-- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/examples/temp/plate_navigator_widget.py b/examples/temp/plate_navigator_widget.py index 3fd26326d..1a091eba1 100644 --- a/examples/temp/plate_navigator_widget.py +++ b/examples/temp/plate_navigator_widget.py @@ -10,8 +10,8 @@ mmc.loadSystemConfiguration() plate = useq.WellPlatePlan( plate=useq.WellPlate.from_str("96-well"), - a1_center_xy=(1000, 1000), - rotation=3, + a1_center_xy=(0, 0), + # rotation=3, ) wdg = PlateNavigatorWidget(mmcore=mmc) wdg.set_plan(plate) diff --git a/src/pymmcore_widgets/hcs/_plate_navigator_widget.py b/src/pymmcore_widgets/hcs/_plate_navigator_widget.py index 881ffae2a..da6a29499 100644 --- a/src/pymmcore_widgets/hcs/_plate_navigator_widget.py +++ b/src/pymmcore_widgets/hcs/_plate_navigator_widget.py @@ -64,6 +64,7 @@ def __init__( def mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent | None) -> None: """Move the stage to the clicked position in the well.""" + print("mouseDoubleClickEvent") if event and event.button() == Qt.MouseButton.LeftButton: x, y = self._get_current_xy_coords(event) self._current_position = (x, y) @@ -349,7 +350,6 @@ def _add_preset_position_item( self, rect: QRectF, pos: useq.Position, rotation: float | None = None ) -> None: item = _PresetPositionItem(rect, self._mmc) - item.setZValue(1) center_x, center_y = rect.center().x(), rect.center().y() # adjust position if rotation diff --git a/tests/test_hcs/test_plate_navigator.py b/tests/test_hcs/test_plate_navigator.py index 11f7e37be..1c20dabe5 100644 --- a/tests/test_hcs/test_plate_navigator.py +++ b/tests/test_hcs/test_plate_navigator.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING import useq +from qtpy.QtCore import QPointF, Qt from pymmcore_widgets.hcs._plate_navigator_widget import ( DATA_POSITION, @@ -39,29 +40,91 @@ def test_plate_navigator_widget(qtbot: QtBot, global_mmcore: CMMCorePlus): # 96 * 11 (QGraphicsEllipseItem * 6, _PresetPositionItem * 5) assert len(scene.items()) == 1056 + +def test_hover_item(qtbot: QtBot, global_mmcore: CMMCorePlus): + wdg = PlateNavigatorWidget(mmcore=global_mmcore) + qtbot.addWidget(wdg) + wdg.show() + + wdg.set_plan(wp96) + scene = wdg._plate_view._scene + + # get the _HoverWellItem for A1 + a1_hover_well = list(reversed(scene.items()))[96] + assert a1_hover_well._current_position is None + assert a1_hover_well.data(DATA_POSITION) == useq.AbsolutePosition( + x=0.0, y=0.0, name="A1" + ) + + # simulate mouse double-click on center of A1 well + global_mmcore.setXYPosition(100, 100) + global_mmcore.waitForSystem() + assert round(global_mmcore.getXPosition()) == 100 + assert round(global_mmcore.getYPosition()) == 100 + center_pos = a1_hover_well.boundingRect().center() + scene_pos = a1_hover_well.mapToScene(center_pos) + view_pos = wdg._plate_view.mapFromScene(scene_pos) + qtbot.mouseDClick( + wdg._plate_view.viewport(), Qt.MouseButton.LeftButton, pos=view_pos + ) + global_mmcore.waitForSystem() + assert a1_hover_well._current_position == (0.0, 0.0) + assert global_mmcore.getXPosition() == 0 + assert global_mmcore.getYPosition() == 0 + + +def test_preset_position_item(qtbot: QtBot, global_mmcore: CMMCorePlus): + wdg = PlateNavigatorWidget(mmcore=global_mmcore) + qtbot.addWidget(wdg) + wdg.show() + + wdg.set_plan(wp96) + # toggle preset movements checkbox + wdg._on_preset_movements_toggled(True) + # get all the items of type _PresetPositionItem preset_items = [ item - for item in reversed(scene.items()) + for item in reversed(wdg._plate_view._scene.items()) if isinstance(item, _PresetPositionItem) ] - # make sure the stored positions for a1 are correct + + # get the item for A1 a1 = preset_items[:5] - pos = [item.data(DATA_POSITION) for item in a1] - assert [(p.x, p.y) for p in pos] == [ + # make sure the stored positions for a1 are correct + a1_pos = [item.data(DATA_POSITION) for item in a1] + assert [(p.x, p.y) for p in a1_pos] == [ (0.0, 0.0), (-3200.0, 0.0), (3200.0, 0.0), (0.0, -3200.0), (0.0, 3200.0), ] - # make sure the stored positions for h12 are correct + + # get the item for H12 h12 = preset_items[-5:] - pos = [item.data(DATA_POSITION) for item in h12] - assert [(p.x, p.y) for p in pos] == [ + # make sure the stored positions for h12 are correct + h12_pos = [item.data(DATA_POSITION) for item in h12] + assert [(p.x, p.y) for p in h12_pos] == [ (99000.0, -63000.0), (95800.0, 63000.0), (102200.0, 63000.0), (99000.0, 59800.0), (99000.0, 66200.0), ] + + # simulate mouse double-click on edge of A1 well + global_mmcore.setXYPosition(100, 100) + global_mmcore.waitForSystem() + assert round(global_mmcore.getXPosition()) == 100 + assert round(global_mmcore.getYPosition()) == 100 + + right_edge = a1_pos[2] + scene_pos = QPointF(right_edge.x, right_edge.y) + view_pos = wdg._plate_view.mapFromScene(scene_pos) + qtbot.mouseDClick( + wdg._plate_view.viewport(), Qt.MouseButton.LeftButton, pos=view_pos + ) + global_mmcore.waitForSystem() + assert round(global_mmcore.getXPosition()) == 3200 + assert round(global_mmcore.getYPosition()) == 0