1212# guitest: show
1313
1414from plotpy .builder import make
15+ from plotpy .items import AnnotatedShape , PolygonShape
16+ from plotpy .plot import BasePlot
1517from qtpy import QtWidgets as QW
1618
1719from cdl .core .model .base import ANN_KEY
2022from 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+
2338def 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