From 4f4c063ae5dd79d6d188e201d44b8d57eba71909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= <16781833+dalthviz@users.noreply.github.com> Date: Wed, 7 Feb 2024 04:06:23 -0500 Subject: [PATCH] Keep vertex selection after shape drawing finishes (#6640) # References and relevant issues Closes #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 <76622105+psobolewskiPhD@users.noreply.github.com> --- .../shapes/_tests/test_shapes_mouse_bindings.py | 16 ++++++++++++++++ napari/layers/shapes/shapes.py | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py b/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py index 388d80c5e1b..ade9643d6ba 100644 --- a/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py +++ b/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py @@ -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.""" @@ -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""" @@ -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""" @@ -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.""" diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py index cf18ad5b219..a9f3aa25eff 100644 --- a/napari/layers/shapes/shapes.py +++ b/napari/layers/shapes/shapes.py @@ -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