From 1432f64bfb0277635549463f74238f8be80237ad Mon Sep 17 00:00:00 2001 From: nstelter Date: Wed, 10 Apr 2024 22:41:35 -0700 Subject: [PATCH 1/5] ENH: Add option to change size of arrows on drawn lines --- pydm/widgets/drawing.py | 69 +++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/pydm/widgets/drawing.py b/pydm/widgets/drawing.py index 1ba7ea93d..5ba434b97 100644 --- a/pydm/widgets/drawing.py +++ b/pydm/widgets/drawing.py @@ -472,6 +472,7 @@ def __init__(self, parent=None, init_channel=None): self._arrow_start_point_selection = False self._arrow_mid_point_selection = False self._mid_point_arrow_flipped = False + self._arrow_size = 6 self.rotation = 0 self.penStyle = Qt.SolidLine self.penWidth = 1 @@ -553,24 +554,48 @@ def draw_item(self, painter): # Draw the arrows if self._arrow_end_point_selection: - points = self._arrow_points(start_point, end_point, 6, 6) + points = self._arrow_points(start_point, end_point, self._arrow_size, self._arrow_size) painter.drawPolygon(points) if self._arrow_start_point_selection: - points = self._arrow_points(end_point, start_point, 6, 6) + points = self._arrow_points(end_point, start_point, self._arrow_size, self._arrow_size) painter.drawPolygon(points) if self._arrow_mid_point_selection: if self._mid_point_arrow_flipped: - points = self._arrow_points(start_point, mid_point, 6, 6) + points = self._arrow_points(start_point, mid_point, self._arrow_size, self._arrow_size) else: - points = self._arrow_points(end_point, mid_point, 6, 6) + points = self._arrow_points(end_point, mid_point, self._arrow_size, self._arrow_size) painter.drawPolygon(points) + @Property(int) + def arrowSize(self): + """ + If True, an arrow will be drawn at the end of the line. + + Returns + ------- + bool + """ + return self._arrow_size + + @arrowSize.setter + def arrowSize(self, new_size): + """ + Size to render line arrows. + + Parameters + ------- + new_selection : bool + """ + if self._arrow_size != new_size: + self._arrow_size = new_size + self.update() + @Property(bool) def arrowEndPoint(self): """ - If True, an arrow will be drawn at the end of the line. + Size to render line arrows. Returns ------- @@ -1204,6 +1229,8 @@ def __init__(self, parent=None, init_channel=None): self._arrow_start_point_selection = False self._arrow_mid_point_selection = False self._arrow_mid_point_flipped = False + self._arrow_size = 6 + self.penStyle = Qt.SolidLine self.penWidth = 1 self._points = [] @@ -1241,20 +1268,20 @@ def p2d(pt): midpoint_x = (point1.x() + point2.x()) / 2 midpoint_y = (point1.y() + point2.y()) / 2 midpoint = QPointF(midpoint_x, midpoint_y) - points = PyDMDrawingLine._arrow_points(point1, midpoint, 6, 6) # 6 = arbitrary arrow size + points = PyDMDrawingLine._arrow_points(point1, midpoint, self._arrow_size, self._arrow_size) # 6 = arbitrary arrow size painter.drawPolygon(points) # Draw the arrows if self._arrow_end_point_selection and (len(self._points[1]) >= 2): - points = PyDMDrawingLine._arrow_points(p2d(self._points[1]), p2d(self._points[0]), 6, 6) + points = PyDMDrawingLine._arrow_points(p2d(self._points[1]), p2d(self._points[0]), self._arrow_size, self._arrow_size) painter.drawPolygon(points) if self._arrow_start_point_selection and (len(self._points[1]) >= 2): points = PyDMDrawingLine._arrow_points( p2d(self._points[len(self._points) - 2]), p2d(self._points[len(self._points) - 1]), - 6, - 6, + self._arrow_size, + self._arrow_size, ) painter.drawPolygon(points) @@ -1339,6 +1366,30 @@ def resetPoints(self): self._points = [] self.update() + @Property(int) + def arrowSize(self): + """ + If True, an arrow will be drawn at the end of the line. + + Returns + ------- + bool + """ + return self._arrow_size + + @arrowSize.setter + def arrowSize(self, new_size): + """ + Size to render line arrows. + + Parameters + ------- + new_selection : bool + """ + if self._arrow_size != new_size: + self._arrow_size = new_size + self.update() + @Property(bool) def arrowEndPoint(self): """ From 1fa298b32f16c6e70587685158bd81892f52fb9b Mon Sep 17 00:00:00 2001 From: nstelter Date: Thu, 11 Apr 2024 11:52:33 -0600 Subject: [PATCH 2/5] TST: add test to make sure changing arrow size doesn't blow anything up --- pydm/tests/widgets/test_drawing.py | 43 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/pydm/tests/widgets/test_drawing.py b/pydm/tests/widgets/test_drawing.py index 2b126414a..993470ed7 100644 --- a/pydm/tests/widgets/test_drawing.py +++ b/pydm/tests/widgets/test_drawing.py @@ -1230,21 +1230,42 @@ def test_pydmdrawingpolyline_arrows(qapp, qtbot, points, num_points): num_points :int The actual number of vertices of the polygon. """ - drawing = PyDMDrawingPolyline() - qtbot.addWidget(drawing) + # try with polyline + polyLine = PyDMDrawingPolyline() + qtbot.addWidget(polyLine) # make sure points seutp correctly before drawing arrows - drawing.setPoints(points) - assert len(drawing.getPoints()) == num_points + polyLine.setPoints(points) + assert len(polyLine.getPoints()) == num_points # enable all arrow options - drawing._arrow_end_point_selection = True - drawing._arrow_start_point_selection = True - drawing._arrow_mid_point_selection = True - drawing._arrow_mid_point_flipped = True - drawing.draw_item(drawing._painter) - - drawing.show() + polyLine._arrow_end_point_selection = True + polyLine._arrow_start_point_selection = True + polyLine._arrow_mid_point_selection = True + polyLine._arrow_mid_point_flipped = True + polyLine.draw_item(polyLine._painter) + polyLine.show() + + # just be sure size prop exists and can be changed without breaking things + polyLine._arrow_size += 3 + polyLine.draw_item(polyLine._painter) + polyLine.show() + + # now try with line + line = PyDMDrawingLine() + qtbot.addWidget(line) + + # enable all arrow options + line._arrow_end_point_selection = True + line._arrow_start_point_selection = True + line._arrow_mid_point_selection = True + line._arrow_mid_point_flipped = True + line.draw_item(polyLine._painter) + line.show() + + line._arrow_size += 3 + line.draw_item(polyLine._painter) + line.show() # # --------------------------- From 99f544903d9f1c611b222fc75d3dce72ca876c15 Mon Sep 17 00:00:00 2001 From: nstelter Date: Thu, 11 Apr 2024 11:56:27 -0600 Subject: [PATCH 3/5] STY: appease pre-commit --- pydm/tests/widgets/test_drawing.py | 2 +- pydm/widgets/drawing.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pydm/tests/widgets/test_drawing.py b/pydm/tests/widgets/test_drawing.py index 993470ed7..f1b2de8c5 100644 --- a/pydm/tests/widgets/test_drawing.py +++ b/pydm/tests/widgets/test_drawing.py @@ -1254,7 +1254,7 @@ def test_pydmdrawingpolyline_arrows(qapp, qtbot, points, num_points): # now try with line line = PyDMDrawingLine() qtbot.addWidget(line) - + # enable all arrow options line._arrow_end_point_selection = True line._arrow_start_point_selection = True diff --git a/pydm/widgets/drawing.py b/pydm/widgets/drawing.py index 5ba434b97..dad89a850 100644 --- a/pydm/widgets/drawing.py +++ b/pydm/widgets/drawing.py @@ -1268,12 +1268,16 @@ def p2d(pt): midpoint_x = (point1.x() + point2.x()) / 2 midpoint_y = (point1.y() + point2.y()) / 2 midpoint = QPointF(midpoint_x, midpoint_y) - points = PyDMDrawingLine._arrow_points(point1, midpoint, self._arrow_size, self._arrow_size) # 6 = arbitrary arrow size + points = PyDMDrawingLine._arrow_points( + point1, midpoint, self._arrow_size, self._arrow_size + ) # 6 = arbitrary arrow size painter.drawPolygon(points) # Draw the arrows if self._arrow_end_point_selection and (len(self._points[1]) >= 2): - points = PyDMDrawingLine._arrow_points(p2d(self._points[1]), p2d(self._points[0]), self._arrow_size, self._arrow_size) + points = PyDMDrawingLine._arrow_points( + p2d(self._points[1]), p2d(self._points[0]), self._arrow_size, self._arrow_size + ) painter.drawPolygon(points) if self._arrow_start_point_selection and (len(self._points[1]) >= 2): From 8542970d46909e6ced088026ec12ae9e6456682e Mon Sep 17 00:00:00 2001 From: nstelter Date: Thu, 11 Apr 2024 23:35:03 -0700 Subject: [PATCH 4/5] STY: comment on arrow size units --- pydm/widgets/drawing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydm/widgets/drawing.py b/pydm/widgets/drawing.py index dad89a850..903119ad7 100644 --- a/pydm/widgets/drawing.py +++ b/pydm/widgets/drawing.py @@ -472,7 +472,7 @@ def __init__(self, parent=None, init_channel=None): self._arrow_start_point_selection = False self._arrow_mid_point_selection = False self._mid_point_arrow_flipped = False - self._arrow_size = 6 + self._arrow_size = 6 # 6 is arbitrary size that looked good for default, not in any specific 'units' self.rotation = 0 self.penStyle = Qt.SolidLine self.penWidth = 1 From e09b52b67f01601fe272a0303f1896855624e253 Mon Sep 17 00:00:00 2001 From: nstelter Date: Thu, 11 Apr 2024 23:40:22 -0700 Subject: [PATCH 5/5] STY: fix up some line + poyline comments --- pydm/widgets/drawing.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pydm/widgets/drawing.py b/pydm/widgets/drawing.py index 903119ad7..983b6be64 100644 --- a/pydm/widgets/drawing.py +++ b/pydm/widgets/drawing.py @@ -472,7 +472,7 @@ def __init__(self, parent=None, init_channel=None): self._arrow_start_point_selection = False self._arrow_mid_point_selection = False self._mid_point_arrow_flipped = False - self._arrow_size = 6 # 6 is arbitrary size that looked good for default, not in any specific 'units' + self._arrow_size = 6 # 6 is arbitrary size that looked good for default, not in any specific 'units' self.rotation = 0 self.penStyle = Qt.SolidLine self.penWidth = 1 @@ -571,7 +571,7 @@ def draw_item(self, painter): @Property(int) def arrowSize(self): """ - If True, an arrow will be drawn at the end of the line. + Size to render line arrows. Returns ------- @@ -595,7 +595,7 @@ def arrowSize(self, new_size): @Property(bool) def arrowEndPoint(self): """ - Size to render line arrows. + If True, an arrow will be drawn at the end of the line. Returns ------- @@ -1229,8 +1229,7 @@ def __init__(self, parent=None, init_channel=None): self._arrow_start_point_selection = False self._arrow_mid_point_selection = False self._arrow_mid_point_flipped = False - self._arrow_size = 6 - + self._arrow_size = 6 # 6 is arbitrary size that looked good for default, not in any specific 'units' self.penStyle = Qt.SolidLine self.penWidth = 1 self._points = [] @@ -1268,9 +1267,7 @@ def p2d(pt): midpoint_x = (point1.x() + point2.x()) / 2 midpoint_y = (point1.y() + point2.y()) / 2 midpoint = QPointF(midpoint_x, midpoint_y) - points = PyDMDrawingLine._arrow_points( - point1, midpoint, self._arrow_size, self._arrow_size - ) # 6 = arbitrary arrow size + points = PyDMDrawingLine._arrow_points(point1, midpoint, self._arrow_size, self._arrow_size) painter.drawPolygon(points) # Draw the arrows @@ -1373,7 +1370,7 @@ def resetPoints(self): @Property(int) def arrowSize(self): """ - If True, an arrow will be drawn at the end of the line. + Size to render line arrows. Returns -------