Skip to content

Commit

Permalink
Merge branch 'main' into Pan
Browse files Browse the repository at this point in the history
  • Loading branch information
Delone2002 authored Oct 17, 2024
2 parents d38e6ca + b9c83ff commit edecaa8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
63 changes: 27 additions & 36 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,17 +1093,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 @@ -1113,32 +1102,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
27 changes: 10 additions & 17 deletions labelme/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ def mouseMoveEvent(self, ev):
self.hEdge = None
shape.highlightVertex(index, shape.MOVE_VERTEX)
self.overrideCursor(CURSOR_POINT)
self.setToolTip(self.tr("Click & drag to move point"))
self.setToolTip(
self.tr(
"Click & Drag to move point\n"
"ALT + SHIFT + Click to delete point"
)
)
self.setStatusTip(self.toolTip())
self.update()
break
Expand All @@ -344,7 +349,7 @@ def mouseMoveEvent(self, ev):
self.prevhShape = self.hShape = shape
self.prevhEdge = self.hEdge = index_edge
self.overrideCursor(CURSOR_POINT)
self.setToolTip(self.tr("Click to create point"))
self.setToolTip(self.tr("ALT + Click to create point"))
self.setStatusTip(self.toolTip())
self.update()
break
Expand Down Expand Up @@ -472,13 +477,11 @@ def mousePressEvent(self, ev):
self.drawingPolygon.emit(True)
self.update()
elif self.editing():
if self.selectedEdge():
if self.selectedEdge() and ev.modifiers() == QtCore.Qt.AltModifier:
self.addPointToEdge()
elif (
self.selectedVertex()
and int(ev.modifiers()) == QtCore.Qt.ShiftModifier
elif self.selectedVertex() and ev.modifiers() == (
QtCore.Qt.AltModifier | QtCore.Qt.ShiftModifier
):
# Delete point if: left-click + SHIFT on a point
self.removeSelectedPoint()

group_mode = int(ev.modifiers()) == QtCore.Qt.ControlModifier
Expand Down Expand Up @@ -687,16 +690,6 @@ def deleteShape(self, shape:Shape):
self.storeShapes()
self.update()

def boundedShiftShapes(self, shapes):
# Try to move in one direction, and if it fails in another.
# Give up if both fail.
point = shapes[0][0]
offset = QtCore.QPointF(2.0, 2.0)
self.offsets = QtCore.QPoint(), QtCore.QPoint()
self.prevPoint = point
if not self.boundedMoveShapes(shapes, point - offset):
self.boundedMoveShapes(shapes, point + offset)

def paintEvent(self, event):
if not self.cropped_image:
return super(Canvas, self).paintEvent(event)
Expand Down
4 changes: 4 additions & 0 deletions labelme/widgets/label_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ def labelSelected(self, item):
self.edit.setText(item.text())

def validate(self):
if not self.edit.isEnabled():
self.accept()
return

text = self.edit.text()
if hasattr(text, "strip"):
text = text.strip()
Expand Down

0 comments on commit edecaa8

Please sign in to comment.