Skip to content

fix: support other than 'left' click - #49

Open
jokasimr wants to merge 3 commits into
mainfrom
fix-click-support
Open

fix: support other than 'left' click#49
jokasimr wants to merge 3 commits into
mainfrom
fix-click-support

Conversation

@jokasimr

Copy link
Copy Markdown

@jokasimr
jokasimr marked this pull request as draft August 10, 2026 12:07
@jokasimr
jokasimr marked this pull request as ready for review August 14, 2026 13:18
@jokasimr
jokasimr requested a review from nvaytet August 14, 2026 13:18
Comment thread tests/points_test.py Outdated
Comment thread src/mpltoolbox/tool.py Outdated
if button == 1 and not modifiers:
self._on_button_press(click_event)
elif kind := self._pick(click_event):
self._release_owner(click_event, kind=kind)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it slightly strange that we release the owner immediately.
Now that you added the functionality for programmatically firing pick events (which was lacking), it opens up the door for being able to simulate things like click, drag and then release, which would vastly improve test coverage.

Maybe we need two methods? A click and a click_and_drag (or a better name) where we provide both start and end positions, and the mouse button is held during the move?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I changed .click() so that it 1. uses the matplotlib pick machinery and we don't have to implement our own ._pick(). 2. explicitly does one button press and one release at the same position. I also added .click_and_drag() for "press-drag-release" style interactions.

Comment thread tests/points_test.py Outdated
assert events == []


def test_canvas_middle_click_removes_point():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this test is adding? Isn't the code that creates the event here basically the same code as in the _make_click_event function?

Comment thread tests/points_test.py
Comment thread tests/points_test.py

assert len(points.children) == 0


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the Rectangles, can we add a test that checks that the on_remove callback is called when the point is removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tested for various types in tests/tool_test.py::test_middle_click_removes_owner_and_calls_callback

Comment thread tests/rectangles_test.py
Comment thread tests/rectangles_test.py
Comment thread tests/rectangles_test.py Outdated
Comment thread tests/rectangles_test.py Outdated
Comment thread tests/rectangles_test.py
rects.click(x=50, y=60, button=2)
assert len(ax.patches) == 1
rects.start()
rects.click(x=30, y=60)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the tests were done not only on the Points and Rectangles, but the other artists as well. Maybe we can parametrize the tests and put them in common files? It could be in the lines_test for Lines and Points, and a new patch_test for the Rectangles, Ellipses, Vspans and Hspans. And polygons_test for polygons.

@jokasimr
jokasimr requested a review from nvaytet September 3, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool click method does not work with button=2

2 participants