Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow holding shift to delete polys without confirmation #1481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)