Skip to content

Commit 1623667

Browse files
committed
Fix annotations appareance settings
Fix Issue #103 (cherry picked from commit f86d566)
1 parent 2b1ee0c commit 1623667

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

cdl/config.py

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -334,59 +334,20 @@ def reset():
334334

335335
PLOTPY_DEFAULTS = {
336336
"plot": {
337+
#
338+
# XXX: If needed in the future, add here the default settings for PlotPy:
339+
# that will override the PlotPy settings.
340+
# That is the right way to customize the PlotPy settings for shapes and
341+
# annotations when they are added using tools from the DataLab application
342+
# (see `BaseDataPanel.ANNOTATION_TOOLS`).
343+
# For example, for shapes:
344+
# "shape/drag/line/color": "#00ffff",
345+
#
337346
# Overriding default plot settings from PlotPy
338347
"marker/curve/text/textcolor": "black",
339348
"marker/cross/text/textcolor": "black",
340349
"marker/cross/text/background_alpha": 0.7,
341350
},
342-
"annotations": { # Annotated shape style for annotations
343-
# Signals:
344-
"s/shape/line/style": "SolidLine",
345-
"s/shape/line/color": "#ffff00",
346-
"s/shape/line/width": 1,
347-
"s/shape/fill/style": "SolidPattern",
348-
"s/shape/fill/color": MAIN_BG_COLOR,
349-
"s/shape/fill/alpha": 0.1,
350-
"s/shape/symbol/marker": "Rect",
351-
"s/shape/symbol/size": 3,
352-
"s/shape/symbol/edgecolor": "#ffff00",
353-
"s/shape/symbol/facecolor": "#ffff00",
354-
"s/shape/symbol/alpha": 1.0,
355-
"s/shape/sel_line/style": "SolidLine",
356-
"s/shape/sel_line/color": "#00ff00",
357-
"s/shape/sel_line/width": 1,
358-
"s/shape/sel_fill/style": "SolidPattern",
359-
"s/shape/sel_fill/color": MAIN_BG_COLOR,
360-
"s/shape/sel_fill/alpha": 0.1,
361-
"s/shape/sel_symbol/marker": "Rect",
362-
"s/shape/sel_symbol/size": 9,
363-
"s/shape/sel_symbol/edgecolor": "#00aa00",
364-
"s/shape/sel_symbol/facecolor": "#00ff00",
365-
"s/shape/sel_symbol/alpha": 0.7,
366-
# Images:
367-
"i/shape/line/style": "SolidLine",
368-
"i/shape/line/color": "#ffff00",
369-
"i/shape/line/width": 1,
370-
"i/shape/fill/style": "SolidPattern",
371-
"i/shape/fill/color": MAIN_BG_COLOR,
372-
"i/shape/fill/alpha": 0.1,
373-
"i/shape/symbol/marker": "Rect",
374-
"i/shape/symbol/size": 3,
375-
"i/shape/symbol/edgecolor": "#ffff00",
376-
"i/shape/symbol/facecolor": "#ffff00",
377-
"i/shape/symbol/alpha": 1.0,
378-
"i/shape/sel_line/style": "SolidLine",
379-
"i/shape/sel_line/color": "#00ff00",
380-
"i/shape/sel_line/width": 1,
381-
"i/shape/sel_fill/style": "SolidPattern",
382-
"i/shape/sel_fill/color": MAIN_BG_COLOR,
383-
"i/shape/sel_fill/alpha": 0.1,
384-
"i/shape/sel_symbol/marker": "Rect",
385-
"i/shape/sel_symbol/size": 9,
386-
"i/shape/sel_symbol/edgecolor": "#00aa00",
387-
"i/shape/sel_symbol/facecolor": "#00ff00",
388-
"i/shape/sel_symbol/alpha": 0.7,
389-
},
390351
"results": { # Annotated shape style for result shapes
391352
# Signals:
392353
"s/line/style": "SolidLine",

cdl/core/gui/panel/image.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class ImagePanel(BaseDataPanel):
5050
PANEL_STR_ID = "image"
5151
PARAMCLASS = ImageObj
5252
MINDIALOGSIZE = (800, 800)
53+
54+
# The following tools are used to create annotations on images. The annotation
55+
# items are created using PlotPy's default settings. Those appearance settings
56+
# may be modified in the configuration (see `cdl.config`).
5357
ANNOTATION_TOOLS = (
5458
AnnotatedCircleTool,
5559
AnnotatedSegmentTool,
@@ -58,6 +62,7 @@ class ImagePanel(BaseDataPanel):
5862
AnnotatedEllipseTool,
5963
LabelTool,
6064
)
65+
6166
IO_REGISTRY = ImageIORegistry
6267
H5_PREFIX = "DataLab_Ima"
6368
ROIDIALOGOPTIONS = {"show_itemlist": True, "show_contrast": False}

cdl/core/gui/panel/signal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class SignalPanel(BaseDataPanel):
4949
PANEL_STR = _("Signal Panel")
5050
PANEL_STR_ID = "signal"
5151
PARAMCLASS = SignalObj
52+
53+
# The following tools are used to create annotations on signals. The annotation
54+
# items are created using PlotPy's default settings. Those appearance settings
55+
# may be modified in the configuration (see `cdl.config`).
5256
ANNOTATION_TOOLS = (
5357
LabelTool,
5458
VCursorTool,
@@ -58,6 +62,7 @@ class SignalPanel(BaseDataPanel):
5862
RectangleTool,
5963
HRangeTool,
6064
)
65+
6166
IO_REGISTRY = SignalIORegistry
6267
H5_PREFIX = "DataLab_Sig"
6368
ROIDIALOGCLASS = roieditor.SignalROIEditor

cdl/core/model/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def config_annotated_shape(
179179
item: AnnotatedShape,
180180
fmt: str,
181181
lbl: bool,
182-
section: str,
183-
option: str,
182+
section: str | None = None,
183+
option: str | None = None,
184184
cmp: bool | None = None,
185185
):
186186
"""Configurate annotated shape.
@@ -204,7 +204,8 @@ def config_annotated_shape(
204204
item.label.labelparam.update_item(item.label)
205205

206206
param.update_item(item)
207-
item.set_style(section, option)
207+
if section is not None and option is not None:
208+
item.set_style(section, option)
208209

209210

210211
# TODO: [P3] Move this function as a method of plot items in PlotPy
@@ -1313,11 +1314,8 @@ def iterate_shape_items(self, editable: bool = False):
13131314
if self.annotations:
13141315
try:
13151316
for item in json_to_items(self.annotations):
1316-
section, option = "annotations", f"{self.PREFIX}/shape"
13171317
if isinstance(item, AnnotatedShape):
1318-
config_annotated_shape(item, fmt, lbl, section, option)
1319-
elif isinstance(item, PolygonShape):
1320-
item.set_style(section, option)
1318+
config_annotated_shape(item, fmt, lbl)
13211319
set_plot_item_editable(item, editable)
13221320
yield item
13231321
except json.decoder.JSONDecodeError:

0 commit comments

Comments
 (0)