From d41c19c2964d88f8157def5f2989291f05ca806e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 13 Aug 2024 23:59:16 +0300 Subject: [PATCH] Allow holding shift to delete polys without confirmation --- labelme/app.py | 26 +++++++++++++++----------- labelme/utils/qt.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/labelme/app.py b/labelme/app.py index 207a769cf..715baed33 100644 --- a/labelme/app.py +++ b/labelme/app.py @@ -19,12 +19,15 @@ from labelme import PY2 from labelme import __appname__ from labelme import ai +from labelme import utils from labelme.ai import MODELS from labelme.config import get_config from labelme.label_file import LabelFile from labelme.label_file import LabelFileError from labelme.logger import logger from labelme.shape import Shape +from labelme.utils.qt import shift_and_ctrl_pressed +from labelme.utils.qt import shift_pressed from labelme.widgets import AiPromptWidget from labelme.widgets import BrightnessContrastDialog from labelme.widgets import Canvas @@ -36,8 +39,6 @@ from labelme.widgets import UniqueLabelQListWidget from labelme.widgets import ZoomWidget -from . import utils - # FIXME # - [medium] Set max zoom value to something big enough for FitWidth/Window @@ -410,7 +411,10 @@ def __init__( self.deleteSelectedShape, shortcuts["delete_polygon"], "cancel", - self.tr("Delete the selected polygons"), + "{} {}".format( + self.tr("Delete the selected polygons"), + self.tr("(Hold Shift to skip confirmation)"), + ), enabled=False, ) duplicate = action( @@ -1846,9 +1850,7 @@ def loadRecent(self, filename): def openPrevImg(self, _value=False): keep_prev = self._config["keep_prev"] - if QtWidgets.QApplication.keyboardModifiers() == ( - Qt.ControlModifier | Qt.ShiftModifier - ): + if shift_and_ctrl_pressed(): self._config["keep_prev"] = True if not self.mayContinue(): @@ -1870,9 +1872,7 @@ def openPrevImg(self, _value=False): def openNextImg(self, _value=False, load=True): keep_prev = self._config["keep_prev"] - if QtWidgets.QApplication.keyboardModifiers() == ( - Qt.ControlModifier | Qt.ShiftModifier - ): + if shift_and_ctrl_pressed(): self._config["keep_prev"] = True if not self.mayContinue(): @@ -2106,8 +2106,12 @@ def deleteSelectedShape(self): msg = self.tr( "You are about to permanently delete {} polygons, " "proceed anyway?" ).format(len(self.canvas.selectedShapes)) - if yes == QtWidgets.QMessageBox.warning( - self, self.tr("Attention"), msg, yes | no, yes + + if shift_pressed() or ( + yes + == QtWidgets.QMessageBox.warning( + self, self.tr("Attention"), msg, yes | no, yes + ) ): self.remLabels(self.canvas.deleteSelected()) self.setDirty() diff --git a/labelme/utils/qt.py b/labelme/utils/qt.py index 7fed3ad18..d79dc94d4 100644 --- a/labelme/utils/qt.py +++ b/labelme/utils/qt.py @@ -96,3 +96,13 @@ def distancetoline(point, line): def fmtShortcut(text): mod, key = text.split("+", 1) return "%s+%s" % (mod, key) + + +def shift_and_ctrl_pressed() -> bool: + return QtWidgets.QApplication.keyboardModifiers() == ( + QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier + ) + + +def shift_pressed() -> bool: + return bool(QtWidgets.QApplication.keyboardModifiers() & QtCore.Qt.ShiftModifier)