Skip to content

Commit

Permalink
Keep vertex selection after shape drawing finishes (napari#6640)
Browse files Browse the repository at this point in the history
# References and relevant issues

Closes napari#6624 

# Description

Keep shape vertex selected after drawing finishes enabling attributes
changes like face/edge color, edge with, etc over the last created
shape.

A preview:


![vertex_selection](https://github.com/napari/napari/assets/16781833/aa4308a8-9421-4f47-9563-7d14727a6a10)

---------

Co-authored-by: Peter Sobolewski <[email protected]>
  • Loading branch information
dalthviz and psobolewskiPhD authored Feb 7, 2024
1 parent 817cc8e commit 4f4c063
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions napari/layers/shapes/_tests/test_shapes_mouse_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def test_add_simple_shape(shape_type, create_known_shapes_layer):
np.testing.assert_allclose(new_shape_max, known_non_shape_end)
assert layer.shape_type[-1] == shape_type

# Ensure it's selected, accounting for zero-indexing
assert len(layer.selected_data) == 1
assert layer.selected_data == {n_shapes}


def test_polygon_lasso_tablet(create_known_shapes_layer):
"""Draw polygon with tablet simulated by mouse drag event."""
Expand Down Expand Up @@ -145,6 +149,10 @@ def test_polygon_lasso_tablet(create_known_shapes_layer):
assert layer.shape_type[-1] == 'polygon'
assert not layer._is_creating

# Ensure it's selected, accounting for zero-indexing
assert len(layer.selected_data) == 1
assert layer.selected_data == {n_shapes}


def test_polygon_lasso_mouse(create_known_shapes_layer):
"""Draw polygon with mouse. Events in sequence are mouse press, release, move, press, release"""
Expand Down Expand Up @@ -182,6 +190,10 @@ def test_polygon_lasso_mouse(create_known_shapes_layer):
assert layer.shape_type[-1] == 'polygon'
assert not layer._is_creating

# Ensure it's selected, accounting for zero-indexing
assert len(layer.selected_data) == 1
assert layer.selected_data == {n_shapes}


def test_distance_polygon_creating(create_known_shapes_layer):
"""Test that distance threshold in polygon creating works as intended"""
Expand Down Expand Up @@ -249,6 +261,10 @@ def test_add_complex_shape(shape_type, create_known_shapes_layer):
np.testing.assert_allclose(layer.data[-1], desired_shape)
assert layer.shape_type[-1] == shape_type

# Ensure it's selected, accounting for zero-indexing
assert len(layer.selected_data) == 1
assert layer.selected_data == {n_shapes}


def test_vertex_insert(create_known_shapes_layer):
"""Add vertex to shape."""
Expand Down
1 change: 0 additions & 1 deletion napari/layers/shapes/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,6 @@ def _finish_drawing(self, event=None):
"""Reset properties used in shape drawing."""
index = copy(self._moving_value[0])
self._is_moving = False
self.selected_data = set()
self._drag_start = None
self._drag_box = None
self._is_selecting = False
Expand Down

0 comments on commit 4f4c063

Please sign in to comment.