Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrgsp committed Aug 5, 2024
1 parent 204e598 commit 80e0ccb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/temp/plate_navigator_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pymmcore_widgets/hcs/_plate_navigator_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
77 changes: 70 additions & 7 deletions tests/test_hcs/test_plate_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

0 comments on commit 80e0ccb

Please sign in to comment.