Skip to content

Commit

Permalink
Fixed IndexError in Canvas widget's shape module (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
CVHub520 committed Mar 21, 2024
1 parent cbbdc19 commit 5b31655
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions anylabeling/views/labeling/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,12 @@ def mouseMoveEvent(self, ev): # noqa: C901
# Polygon/Vertex moving.
if QtCore.Qt.LeftButton & ev.buttons():
if self.selected_vertex():
self.bounded_move_vertex(pos)
self.repaint()
self.moving_shape = True
try:
self.bounded_move_vertex(pos)
self.repaint()
self.moving_shape = True
except IndexError:
return
if self.h_hape.shape_type == "rectangle":
p1 = self.h_hape[0]
p2 = self.h_hape[2]
Expand Down Expand Up @@ -423,7 +426,7 @@ def mouseMoveEvent(self, ev): # noqa: C901
self.setStatusTip(self.toolTip())
self.update()
break
if shape.contains_point(pos):
if len(shape.points) > 1 and shape.contains_point(pos):
if self.selected_vertex():
self.h_hape.highlight_clear()
self.prev_h_vertex = self.h_vertex
Expand Down Expand Up @@ -703,7 +706,7 @@ def select_shape_point(self, point, multiple_selection_mode):

else:
for shape in reversed(self.shapes):
if self.is_visible(shape) and shape.contains_point(point):
if self.is_visible(shape) and len(shape.points) > 1 and shape.contains_point(point):
self.set_hiding()
if shape not in self.selected_shapes:
if multiple_selection_mode:
Expand Down Expand Up @@ -1181,7 +1184,10 @@ def paintEvent(self, event): # noqa: C901
label = shape.label
d = shape.point_size / shape.scale
if label:
bbox = shape.bounding_rect()
try:
bbox = shape.bounding_rect()
except IndexError:
continue
fm = QtGui.QFontMetrics(p.font())
rect = fm.boundingRect(label)
x = bbox.x()
Expand All @@ -1199,7 +1205,10 @@ def paintEvent(self, event): # noqa: C901
d = 1.5 # default shape sacle
label = shape.label
if label:
bbox = shape.bounding_rect()
try:
bbox = shape.bounding_rect()
except IndexError:
continue
fm = QtGui.QFontMetrics(p.font())
rect = fm.boundingRect(label)
x = bbox.x()
Expand Down

0 comments on commit 5b31655

Please sign in to comment.