diff --git a/labelme/app.py b/labelme/app.py index 7bbce4936..e65a810bd 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( @@ -1857,9 +1861,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(): @@ -1881,9 +1883,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(): @@ -2117,9 +2117,17 @@ 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(): + confirmed = True + else: + confirmed = ( + QtWidgets.QMessageBox.warning( + self, self.tr("Attention"), msg, yes | no, yes + ) + == yes + ) + if confirmed: self.remLabels(self.canvas.deleteSelected()) self.setDirty() if self.noShapes(): 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)