Parcourir la source

Deselect shape when clicking and already selected (#944)

* Deselect shape when clicking and already selected

* fixed selectShapePoint()

* keep multiple_selection_mode=group_mode

* fixed RIGHT-CLICK

* black

* update canvas.py

* update canvas.py
Bc. Martin Kubovčík il y a 3 ans
Parent
commit
9d9914e8a4
2 fichiers modifiés avec 23 ajouts et 13 suppressions
  1. 0 1
      labelme/app.py
  2. 23 12
      labelme/widgets/canvas.py

+ 0 - 1
labelme/app.py

@@ -38,7 +38,6 @@ from labelme.widgets import ZoomWidget
 
 # TODO(unknown):
 # - [high] Add polygon movement with arrow keys
-# - [high] Deselect shape when clicking and already selected(?)
 # - [low,maybe] Preview images on file dialogs.
 # - Zoom is too "steppy".
 

+ 23 - 12
labelme/widgets/canvas.py

@@ -381,6 +381,12 @@ class Canvas(QtWidgets.QWidget):
             elif self.editing():
                 if self.selectedEdge():
                     self.addPointToEdge()
+                elif (
+                    self.selectedVertex()
+                    and int(ev.modifiers()) == QtCore.Qt.ShiftModifier
+                ):
+                    # Delete point if: left-click + SHIFT on a point
+                    self.removeSelectedPoint()
 
                 group_mode = int(ev.modifiers()) == QtCore.Qt.ControlModifier
                 self.selectShapePoint(pos, multiple_selection_mode=group_mode)
@@ -388,9 +394,13 @@ class Canvas(QtWidgets.QWidget):
                 self.repaint()
         elif ev.button() == QtCore.Qt.RightButton and self.editing():
             group_mode = int(ev.modifiers()) == QtCore.Qt.ControlModifier
-            self.selectShapePoint(pos, multiple_selection_mode=group_mode)
+            if not self.selectedShapes or (
+                self.hShape is not None
+                and self.hShape not in self.selectedShapes
+            ):
+                self.selectShapePoint(pos, multiple_selection_mode=group_mode)
+                self.repaint()
             self.prevPoint = pos
-            self.repaint()
 
     def mouseReleaseEvent(self, ev):
         if ev.button() == QtCore.Qt.RightButton:
@@ -403,13 +413,6 @@ class Canvas(QtWidgets.QWidget):
                 # Cancel the move by deleting the shadow copy.
                 self.selectedShapesCopy = []
                 self.repaint()
-        elif ev.button() == QtCore.Qt.LeftButton and self.selectedVertex():
-            if (
-                self.editing()
-                and int(ev.modifiers()) == QtCore.Qt.ShiftModifier
-            ):
-                # Delete point if: left-click + SHIFT on a point
-                self.removeSelectedPoint()
 
         if self.movingShape and self.hShape:
             index = self.shapes.index(self.hShape)
@@ -478,13 +481,21 @@ class Canvas(QtWidgets.QWidget):
                 if self.isVisible(shape) and shape.containsPoint(point):
                     self.calculateOffsets(shape, point)
                     self.setHiding()
-                    if multiple_selection_mode:
-                        if shape not in self.selectedShapes:
+                    if shape not in self.selectedShapes:
+                        if multiple_selection_mode:
                             self.selectionChanged.emit(
                                 self.selectedShapes + [shape]
                             )
+                        else:
+                            self.selectionChanged.emit([shape])
                     else:
-                        self.selectionChanged.emit([shape])
+                        self.selectionChanged.emit(
+                            [
+                                x
+                                for x in self.selectedShapes
+                                if x != self.hShape
+                            ]
+                        )
                     return
         self.deSelectShape()