Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/machinevisiontoolbox/ImageIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def on_mouse_move(self, event: Any) -> None:
if event.inaxes == self.ax2 and self.leftclicked:
x, y = event.xdata, event.ydata
# update the line positions
self.vertical_line3.set_xdata(x)
self.vertical_line3.set_xdata([x, x])
self.text.set_text("d={:.2f}".format(self.x_left - x))
self.ax2.figure.canvas.draw()
# if event.inaxes:
Expand All @@ -754,10 +754,10 @@ def on_click(self, event: Any) -> None:
self.set_cross_hair_visible(True)
x, y = event.xdata, event.ydata
# update the line positions
self.horizontal_line.set_ydata(y)
self.vertical_line.set_xdata(x)
self.horizontal_line2.set_ydata(y)
self.vertical_line2.set_xdata(x)
self.horizontal_line.set_ydata([y, y])
self.vertical_line.set_xdata([x, x])
self.horizontal_line2.set_ydata([y, y])
self.vertical_line2.set_xdata([x, x])
self.ax.figure.canvas.draw()
self.leftclicked = True
self.x_left = x
Expand All @@ -776,6 +776,10 @@ def on_click(self, event: Any) -> None:

if interactive:
cursor = Cursor(ax1, ax2)
# Matplotlib holds bound-method callbacks weakly, so keep the cursor
# alive for as long as the figure, or the clicks stop working when
# show() does not block (a notebook, or a non-interactive backend)
fig._stdisp_cursor = cursor # type: ignore[attr-defined]
fig.canvas.mpl_connect("motion_notify_event", cursor.on_mouse_move)
fig.canvas.mpl_connect("button_press_event", cursor.on_click)
safe_plt_show(block=True)
Expand Down
13 changes: 0 additions & 13 deletions tests/test_image_io_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,6 @@ def event(fig, name, ax, u, v):
x, y = ax.transData.transform((u, v))
return MouseEvent(name, fig.canvas, x, y, button=1)

@pytest.mark.xfail(
strict=True,
raises=RuntimeError,
reason="the click handler passes a scalar to Line2D.set_xdata/set_ydata, "
"which Matplotlib 3.11 refuses: 'y must be a sequence'",
)
def test_clicking_places_the_cross_hairs_and_dragging_measures_disparity(
self, pair, monkeypatch
):
Expand Down Expand Up @@ -377,13 +371,6 @@ def user(block=False):
assert seen["after"] == ["d=-4.00"]
assert seen["dashed"] == pytest.approx(14)

@pytest.mark.xfail(
strict=True,
raises=AssertionError,
reason="stdisp() keeps its cursor object only in a local variable, and "
"Matplotlib holds callbacks weakly, so when plt.show() does not block "
"(a notebook, or a non-interactive backend) the clicks do nothing",
)
def test_cursor_survives_when_show_does_not_block(self, pair):
left, right = pair
left.stdisp(right, interactive=True)
Expand Down
Loading