Skip to content

Commit

Permalink
Make group_id clearable by removing the already set value
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Sep 20, 2024
1 parent 4c3d527 commit f8ad3bc
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,17 +1221,6 @@ def _edit_label(self, value=None):
assert description is None
return

self.canvas.storeShapes()
for item in items:
self._update_item(
item=item,
text=text if edit_text else None,
flags=flags if edit_flags else None,
group_id=group_id if edit_group_id else None,
description=description if edit_description else None,
)

def _update_item(self, item, text, flags, group_id, description):
if not self.validateLabel(text):
self.errorMessage(
self.tr("Invalid label"),
Expand All @@ -1241,32 +1230,34 @@ def _update_item(self, item, text, flags, group_id, description):
)
return

shape = item.shape()

if text is not None:
shape.label = text
if flags is not None:
shape.flags = flags
if group_id is not None:
shape.group_id = group_id
if description is not None:
shape.description = description

self._update_shape_color(shape)
if shape.group_id is None:
item.setText(
'{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
html.escape(shape.label), *shape.fill_color.getRgb()[:3]
self.canvas.storeShapes()
for item in items:
shape: Shape = item.shape()

if edit_text:
shape.label = text
if edit_flags:
shape.flags = flags
if edit_group_id:
shape.group_id = group_id
if edit_description:
shape.description = description

self._update_shape_color(shape)
if shape.group_id is None:
item.setText(
'{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
html.escape(shape.label), *shape.fill_color.getRgb()[:3]
)
)
)
else:
item.setText("{} ({})".format(shape.label, shape.group_id))
self.setDirty()
if self.uniqLabelList.findItemByLabel(shape.label) is None:
item = self.uniqLabelList.createItemFromLabel(shape.label)
self.uniqLabelList.addItem(item)
rgb = self._get_rgb_by_label(shape.label)
self.uniqLabelList.setItemLabel(item, shape.label, rgb)
else:
item.setText("{} ({})".format(shape.label, shape.group_id))
self.setDirty()
if self.uniqLabelList.findItemByLabel(shape.label) is None:
item = self.uniqLabelList.createItemFromLabel(shape.label)
self.uniqLabelList.addItem(item)
rgb = self._get_rgb_by_label(shape.label)
self.uniqLabelList.setItemLabel(item, shape.label, rgb)

def fileSearchChanged(self):
self.importDirImages(
Expand Down

0 comments on commit f8ad3bc

Please sign in to comment.