Skip to content

Commit

Permalink
Draw all points only when selecting the shape
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Apr 16, 2023
1 parent 8b97c9f commit 7331723
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ repos:
'flake8-implicit-str-concat',
'pydocstyle>=5.0.0',
]
exclude: ^tests/test_cases/no_closing_bracket\.py$
- repo: https://github.com/rstcheck/rstcheck
rev: v6.1.2
hooks:
Expand Down
30 changes: 19 additions & 11 deletions anylabeling/views/labeling/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class Shape:
vertex_fill_color = DEFAULT_VERTEX_FILL_COLOR
hvertex_fill_color = DEFAULT_HVERTEX_FILL_COLOR
point_type = P_ROUND
point_size = 8
scale = 1.0
point_size = 4
scale = 1.5

def __init__(
self,
Expand Down Expand Up @@ -145,7 +145,7 @@ def get_rect_from_line(self, pt1, pt2):
x2, y2 = pt2.x(), pt2.y()
return QtCore.QRectF(x1, y1, x2 - x1, y2 - y1)

def paint(self, painter: QtGui.QPainter):
def paint(self, painter: QtGui.QPainter): # noqa: max-complexity: 18
"""Paint shape using QPainter"""
if self.points:
color = (
Expand All @@ -164,36 +164,44 @@ def paint(self, painter: QtGui.QPainter):
if len(self.points) == 2:
rectangle = self.get_rect_from_line(*self.points)
line_path.addRect(rectangle)
for i in range(len(self.points)):
self.draw_vertex(vrtx_path, i)
if self.selected:
for i in range(len(self.points)):
self.draw_vertex(vrtx_path, i)
elif self.shape_type == "circle":
assert len(self.points) in [1, 2]
if len(self.points) == 2:
rectangle = self.get_circle_rect_from_line(self.points)
line_path.addEllipse(rectangle)
for i in range(len(self.points)):
self.draw_vertex(vrtx_path, i)
if self.selected:
for i in range(len(self.points)):
self.draw_vertex(vrtx_path, i)
elif self.shape_type == "linestrip":
line_path.moveTo(self.points[0])
for i, p in enumerate(self.points):
line_path.lineTo(p)
self.draw_vertex(vrtx_path, i)
if self.selected:
self.draw_vertex(vrtx_path, i)
elif self.shape_type == "point":
assert len(self.points) == 1
self.draw_vertex(vrtx_path, 0)
else:
line_path.moveTo(self.points[0])
# Uncommenting the following line will draw 2 paths
# for the 1st vertex, and make it non-filled, which
# may be desirable.
# self.draw_vertex(vrtx_path, 0)
self.draw_vertex(vrtx_path, 0)

for i, p in enumerate(self.points):
line_path.lineTo(p)
self.draw_vertex(vrtx_path, i)
if self.selected:
self.draw_vertex(vrtx_path, i)
if self.is_closed():
line_path.lineTo(self.points[0])

painter.drawPath(line_path)
painter.drawPath(vrtx_path)
painter.fillPath(vrtx_path, self._vertex_fill_color)
if self._vertex_fill_color is not None:
painter.fillPath(vrtx_path, self._vertex_fill_color)
if self.fill:
color = (
self.select_fill_color
Expand Down

0 comments on commit 7331723

Please sign in to comment.