Skip to content

Commit

Permalink
Add function to set annotation color in unit tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 90ed710)
  • Loading branch information
PierreRaybaut committed Nov 5, 2024
1 parent 752e13b commit 2b1ee0c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cdl/tests/features/images/annotations_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# guitest: show

from plotpy.builder import make
from plotpy.items import AnnotatedShape, PolygonShape
from plotpy.plot import BasePlot
from qtpy import QtWidgets as QW

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


def set_annotation_color(annotation: AnnotatedShape, color: str) -> None:
"""Set annotation color"""
shape: PolygonShape = annotation.shape
param = shape.shapeparam
param.line.color = param.fill.color = color
param.fill.alpha = 0.3
param.fill.style = "SolidPattern"
param.update_item(shape)
plot: BasePlot = annotation.plot()
if plot is not None:
plot.replot()


def test_annotations_unit():
"""Run image tools test scenario"""
with cdltest_app_context() as win:
Expand All @@ -29,14 +44,15 @@ def test_annotations_unit():
ima1 = test_data.create_multigauss_image()
ima1.title = "Annotations from items"
rect = make.annotated_rectangle(100, 100, 200, 200, title="Test")
set_annotation_color(rect, "#2222ff")
circ = make.annotated_circle(300, 300, 400, 400, title="Test")
set_annotation_color(circ, "#22ff22")
elli = make.annotated_ellipse(
500, 500, 800, 500, 650, 400, 650, 600, title="Test"
)
segm = make.annotated_segment(700, 700, 800, 800, title="Test")
label = make.label("Test", (1000, 1000), (0, 0), "BR")
ima1.add_annotations_from_items([rect, circ, elli, segm, label])
ima1.add_annotations_from_file(test_data.get_test_fnames("annotations.json")[0])
panel.add_object(ima1)

# Create another image with annotations
Expand Down

0 comments on commit 2b1ee0c

Please sign in to comment.