Skip to content

Commit

Permalink
Add feature to display shape label when cursor hovers over it
Browse files Browse the repository at this point in the history
  • Loading branch information
healthonrails committed Mar 4, 2024
1 parent 7804475 commit 768f92b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions annolid/gui/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self, *args, **kwargs):
self.hShapeIsSelected = False
self._painter = QtGui.QPainter()
self._cursor = CURSOR_DEFAULT
self.mouse_xy_text = ""

self.label = QLabel(self)
self.label.setAlignment(QtCore.Qt.AlignCenter)
Expand Down Expand Up @@ -165,7 +166,7 @@ def initializeAiModel(self, name):
if name not in [model.name for model in labelme.ai.MODELS]:
logger.warning("Unsupported ai model: %s" % name)
model = labelme.ai.MODELS[3]
else:
else:
model = [model for model in labelme.ai.MODELS if model.name == name][0]

if self._ai_model is not None and self._ai_model.name == model.name:
Expand Down Expand Up @@ -383,8 +384,8 @@ def mouseMoveEvent(self, ev):
return

x, y = ev.x(), ev.y()
text = f'x:{pos.x():.1f},y:{pos.y():.1f}'
self.label.setText(text)
self.mouse_xy_text = f'x:{pos.x():.1f},y:{pos.y():.1f}'
self.label.setText(self.mouse_xy_text)
self.label.adjustSize()
label_width = self.label.width()
label_height = self.label.height()
Expand Down Expand Up @@ -495,7 +496,9 @@ 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(f"Click & drag to move point"))
self.label.setText(shape.label + "," + self.mouse_xy_text)
self.label.adjustSize()
self.setStatusTip(self.toolTip())
self.update()
break
Expand All @@ -508,6 +511,8 @@ def mouseMoveEvent(self, ev):
self.prevhEdge = self.hEdge = index_edge
self.overrideCursor(CURSOR_POINT)
self.setToolTip(self.tr("Click to create point"))
self.label.setText(shape.label + "," + self.mouse_xy_text)
self.label.adjustSize()
self.setStatusTip(self.toolTip())
self.update()
break
Expand All @@ -519,6 +524,8 @@ def mouseMoveEvent(self, ev):
self.prevhShape = self.hShape = shape
self.prevhEdge = self.hEdge
self.hEdge = None
self.label.setText(shape.label + "," + self.mouse_xy_text)
self.label.adjustSize()
self.setToolTip(
self.tr("Click & drag to move shape '%s'") % shape.label
)
Expand Down Expand Up @@ -1017,7 +1024,8 @@ def finalise(self):
# assert self.current
if self.createMode == "ai_polygon":
# convert points to polygon by an AI model
assert self.current.shape_type == "points"
if self.current.shape_type != "points":
return
points = self._ai_model.predict_polygon_from_points(
points=[
[point.x(), point.y()] for point in self.current.points
Expand Down

0 comments on commit 768f92b

Please sign in to comment.