Skip to content

Commit b00ab90

Browse files
authored
Merge pull request #139 from mbel-tech/fatina-del-codice/beautiful-hypatia-wlxfol
feat(ui): Views page pair list and same-IDs tick (ID correspondence, G)
2 parents f6d4f4e + cd77574 commit b00ab90

4 files changed

Lines changed: 886 additions & 6 deletions

File tree

‎tests/test_ui/test_trajectory_view.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
import pytest
7+
from PySide6.QtCore import Qt
78

89
pytest.importorskip("PySide6")
910

@@ -143,3 +144,63 @@ def test_empty_view_is_safe(qtbot) -> None:
143144
qtbot.addWidget(v)
144145
v.set_frame(3)
145146
assert v.n_frames == 0 and v.trail_item_count() == 0
147+
148+
149+
def test_set_highlight_thickens_one_animal(qtbot) -> None:
150+
xy = np.zeros((100, 4, 2))
151+
for a in range(4):
152+
xy[:, a, 0] = np.linspace(10, 190, 100)
153+
xy[:, a, 1] = 20 + 40 * a
154+
view = TrajectoryView()
155+
qtbot.addWidget(view)
156+
view.set_data(xy, xy, 30.0)
157+
view.set_frame(50)
158+
assert view.highlighted_animal is None
159+
160+
def trails():
161+
"""Pen (width, alpha) of each trail, in animal order, plus marker radii."""
162+
paths = [i for i in view.scene().items(order=Qt.SortOrder.AscendingOrder)
163+
if hasattr(i, "path") and i.zValue() == 2]
164+
dots = [i for i in view.scene().items(order=Qt.SortOrder.AscendingOrder)
165+
if i.zValue() == 3]
166+
return (
167+
[(i.pen().widthF(), i.pen().color().alphaF()) for i in paths],
168+
[d.rect().width() for d in dots],
169+
)
170+
171+
base_pens, base_dots = trails()
172+
assert len(set(base_pens)) == 1 and len(set(base_dots)) == 1
173+
view.set_highlight(2)
174+
assert view.highlighted_animal == 2
175+
pens, dots = trails()
176+
# Items are ordered by y here: animal index == position in the list.
177+
ys = sorted(range(4), key=lambda a: a)
178+
assert pens[2][0] >= 2 * max(pens[a][0] for a in ys if a != 2)
179+
assert dots[2] > max(dots[a] for a in ys if a != 2)
180+
assert all(pens[a][1] < pens[2][1] for a in ys if a != 2)
181+
view.set_highlight(99) # out of range: nothing highlighted, no crash
182+
view.set_highlight(None)
183+
assert view.highlighted_animal is None
184+
assert trails() == (base_pens, base_dots)
185+
186+
187+
def test_raw_trails_dimmed_when_highlighting(qtbot) -> None:
188+
view = TrajectoryView()
189+
qtbot.addWidget(view)
190+
view.set_data(_line_xy(animals=2), _line_xy(animals=2), 30.0)
191+
view.set_source("raw")
192+
view.set_frame(50)
193+
view.set_highlight(0)
194+
alphas = sorted(
195+
i.pen().color().alphaF() for i in view.scene().items()
196+
if hasattr(i, "path") and i.zValue() == 2
197+
)
198+
assert alphas[0] < alphas[1]
199+
200+
201+
def test_clear_drops_loaded_data(qtbot) -> None:
202+
view = TrajectoryView()
203+
qtbot.addWidget(view)
204+
view.set_data(_line_xy(), _line_xy(), 30.0)
205+
view.clear()
206+
assert view.n_frames == 0 and view.trail_item_count() == 0

0 commit comments

Comments
 (0)