Skip to content

Commit 2b1ee0c

Browse files
committed
Add function to set annotation color in unit tests
(cherry picked from commit 90ed710)
1 parent 752e13b commit 2b1ee0c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cdl/tests/features/images/annotations_unit_test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# guitest: show
1313

1414
from plotpy.builder import make
15+
from plotpy.items import AnnotatedShape, PolygonShape
16+
from plotpy.plot import BasePlot
1517
from qtpy import QtWidgets as QW
1618

1719
from cdl.core.model.base import ANN_KEY
@@ -20,6 +22,19 @@
2022
from cdl.tests import data as test_data
2123

2224

25+
def set_annotation_color(annotation: AnnotatedShape, color: str) -> None:
26+
"""Set annotation color"""
27+
shape: PolygonShape = annotation.shape
28+
param = shape.shapeparam
29+
param.line.color = param.fill.color = color
30+
param.fill.alpha = 0.3
31+
param.fill.style = "SolidPattern"
32+
param.update_item(shape)
33+
plot: BasePlot = annotation.plot()
34+
if plot is not None:
35+
plot.replot()
36+
37+
2338
def test_annotations_unit():
2439
"""Run image tools test scenario"""
2540
with cdltest_app_context() as win:
@@ -29,14 +44,15 @@ def test_annotations_unit():
2944
ima1 = test_data.create_multigauss_image()
3045
ima1.title = "Annotations from items"
3146
rect = make.annotated_rectangle(100, 100, 200, 200, title="Test")
47+
set_annotation_color(rect, "#2222ff")
3248
circ = make.annotated_circle(300, 300, 400, 400, title="Test")
49+
set_annotation_color(circ, "#22ff22")
3350
elli = make.annotated_ellipse(
3451
500, 500, 800, 500, 650, 400, 650, 600, title="Test"
3552
)
3653
segm = make.annotated_segment(700, 700, 800, 800, title="Test")
3754
label = make.label("Test", (1000, 1000), (0, 0), "BR")
3855
ima1.add_annotations_from_items([rect, circ, elli, segm, label])
39-
ima1.add_annotations_from_file(test_data.get_test_fnames("annotations.json")[0])
4056
panel.add_object(ima1)
4157

4258
# Create another image with annotations

0 commit comments

Comments
 (0)