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

NEW FEATURE: Quick edit multiple labels at once #1369

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 30 additions & 1 deletion labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@ def __init__(
enabled=False,
)

multi_edit = action(
self.tr("&Multi Edit"),
self.multiEditLabel,
shortcuts["multi_edit_labels"],
"multi_edit",
self.tr("Modify the label of the selected polygons"),
enabled=False,
)

fill_drawing = action(
self.tr("Fill Drawing Polygon"),
self.canvas.setFillDrawing,
Expand All @@ -609,7 +618,7 @@ def __init__(

# Lavel list context menu.
labelMenu = QtWidgets.QMenu()
utils.addActions(labelMenu, (edit, delete))
utils.addActions(labelMenu, (edit, multi_edit, delete))
self.labelList.setContextMenuPolicy(Qt.CustomContextMenu)
self.labelList.customContextMenuRequested.connect(
self.popLabelListMenu
Expand All @@ -628,6 +637,7 @@ def __init__(
toggleKeepPrevMode=toggle_keep_prev_mode,
delete=delete,
edit=edit,
multi_edit=multi_edit,
duplicate=duplicate,
copy=copy,
paste=paste,
Expand Down Expand Up @@ -1097,6 +1107,9 @@ def editLabel(self, item=None):
)
if text is None:
return
return self._updateLabel(item, shape, text, flags, group_id, description)

def _updateLabel(self, item, shape, text, flags, group_id, description):
if not self.validateLabel(text):
self.errorMessage(
self.tr("Invalid label"),
Expand Down Expand Up @@ -1126,6 +1139,21 @@ def editLabel(self, item=None):
rgb = self._get_rgb_by_label(shape.label)
self.uniqLabelList.setItemLabel(item, shape.label, rgb)

def multiEditLabel(self):
items = self.labelList.selectedItems()
if not items:
return
shape = items[0].shape()
text, flags, group_id, description = self.labelDialog.popUp(
text=shape.label,
flags=shape.flags,
group_id=shape.group_id,
description=shape.description,
)
if text is None:
return
for item in items:
self._updateLabel(item, item.shape(), text, flags, group_id, description)
def fileSearchChanged(self):
self.importDirImages(
self.lastOpenDir,
Expand Down Expand Up @@ -1166,6 +1194,7 @@ def shapeSelectionChanged(self, selected_shapes):
self.actions.duplicate.setEnabled(n_selected)
self.actions.copy.setEnabled(n_selected)
self.actions.edit.setEnabled(n_selected == 1)
self.actions.multi_edit.setEnabled(n_selected > 1)

def addLabel(self, shape):
if shape.group_id is None:
Expand Down
1 change: 1 addition & 0 deletions labelme/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ shortcuts:
undo_last_point: Ctrl+Z
add_point_to_edge: Ctrl+Shift+P
edit_label: Ctrl+E
multi_edit_labels: Ctrl+M
toggle_keep_prev_mode: Ctrl+P
remove_selected_point: [Meta+H, Backspace]