Skip to content

Commit

Permalink
Allow holding shift to delete polys without confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Oct 1, 2024
1 parent b9c83ff commit d41c19c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
26 changes: 15 additions & 11 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions labelme/utils/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ def distancetoline(point, line):
def fmtShortcut(text):
mod, key = text.split("+", 1)
return "<b>%s</b>+<b>%s</b>" % (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)

0 comments on commit d41c19c

Please sign in to comment.