Skip to content
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
23 changes: 14 additions & 9 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from labelme._label_file import ShapeDict
from labelme.config import get_config
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 Down Expand Up @@ -398,7 +400,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)"),
),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why separate translation texts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't want to invalidate existing translations.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know, but is that the right thing to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you. I'm fine doing it either this way or by changing the entire translation.

enabled=False,
)
duplicate = action(
Expand Down Expand Up @@ -1836,9 +1841,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 @@ -1860,9 +1863,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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - just using the same new function for the same functionality.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean, this pr is for deleting poly right? why you change keep_prev?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bit of a side effect – I think, back last year when I originally made this PR, I figured it'd be worth it to unify the modifier key functionality used both for "hold shift to delete polys" and "hold shift+ctrl" as used here, into canonical helper functions.

self._config["keep_prev"] = True

if not self.mayContinue():
Expand Down Expand Up @@ -2097,8 +2098,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
5 changes: 5 additions & 0 deletions labelme/translate/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,11 @@ Polygons</source>
<source>AI Mask Model</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../app.py" line="0"/>
<source>(Hold Shift to skip confirmation)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>_IouThresholdWidget</name>
Expand Down
10 changes: 10 additions & 0 deletions labelme/utils/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ def distancetoline(point, line):
def fmtShortcut(text):
mod, key = text.split("+", 1)
return f"<b>{mod}</b>+<b>{key}</b>"


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)
Loading