Skip to content

Commit

Permalink
Fix annotations appareance settings
Browse files Browse the repository at this point in the history
Fix Issue #103

(cherry picked from commit f86d566)
  • Loading branch information
PierreRaybaut committed Nov 5, 2024
1 parent 2b1ee0c commit 1623667
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 55 deletions.
57 changes: 9 additions & 48 deletions cdl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,59 +334,20 @@ def reset():

PLOTPY_DEFAULTS = {
"plot": {
#
# XXX: If needed in the future, add here the default settings for PlotPy:
# that will override the PlotPy settings.
# That is the right way to customize the PlotPy settings for shapes and
# annotations when they are added using tools from the DataLab application
# (see `BaseDataPanel.ANNOTATION_TOOLS`).
# For example, for shapes:
# "shape/drag/line/color": "#00ffff",
#
# Overriding default plot settings from PlotPy
"marker/curve/text/textcolor": "black",
"marker/cross/text/textcolor": "black",
"marker/cross/text/background_alpha": 0.7,
},
"annotations": { # Annotated shape style for annotations
# Signals:
"s/shape/line/style": "SolidLine",
"s/shape/line/color": "#ffff00",
"s/shape/line/width": 1,
"s/shape/fill/style": "SolidPattern",
"s/shape/fill/color": MAIN_BG_COLOR,
"s/shape/fill/alpha": 0.1,
"s/shape/symbol/marker": "Rect",
"s/shape/symbol/size": 3,
"s/shape/symbol/edgecolor": "#ffff00",
"s/shape/symbol/facecolor": "#ffff00",
"s/shape/symbol/alpha": 1.0,
"s/shape/sel_line/style": "SolidLine",
"s/shape/sel_line/color": "#00ff00",
"s/shape/sel_line/width": 1,
"s/shape/sel_fill/style": "SolidPattern",
"s/shape/sel_fill/color": MAIN_BG_COLOR,
"s/shape/sel_fill/alpha": 0.1,
"s/shape/sel_symbol/marker": "Rect",
"s/shape/sel_symbol/size": 9,
"s/shape/sel_symbol/edgecolor": "#00aa00",
"s/shape/sel_symbol/facecolor": "#00ff00",
"s/shape/sel_symbol/alpha": 0.7,
# Images:
"i/shape/line/style": "SolidLine",
"i/shape/line/color": "#ffff00",
"i/shape/line/width": 1,
"i/shape/fill/style": "SolidPattern",
"i/shape/fill/color": MAIN_BG_COLOR,
"i/shape/fill/alpha": 0.1,
"i/shape/symbol/marker": "Rect",
"i/shape/symbol/size": 3,
"i/shape/symbol/edgecolor": "#ffff00",
"i/shape/symbol/facecolor": "#ffff00",
"i/shape/symbol/alpha": 1.0,
"i/shape/sel_line/style": "SolidLine",
"i/shape/sel_line/color": "#00ff00",
"i/shape/sel_line/width": 1,
"i/shape/sel_fill/style": "SolidPattern",
"i/shape/sel_fill/color": MAIN_BG_COLOR,
"i/shape/sel_fill/alpha": 0.1,
"i/shape/sel_symbol/marker": "Rect",
"i/shape/sel_symbol/size": 9,
"i/shape/sel_symbol/edgecolor": "#00aa00",
"i/shape/sel_symbol/facecolor": "#00ff00",
"i/shape/sel_symbol/alpha": 0.7,
},
"results": { # Annotated shape style for result shapes
# Signals:
"s/line/style": "SolidLine",
Expand Down
5 changes: 5 additions & 0 deletions cdl/core/gui/panel/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class ImagePanel(BaseDataPanel):
PANEL_STR_ID = "image"
PARAMCLASS = ImageObj
MINDIALOGSIZE = (800, 800)

# The following tools are used to create annotations on images. The annotation
# items are created using PlotPy's default settings. Those appearance settings
# may be modified in the configuration (see `cdl.config`).
ANNOTATION_TOOLS = (
AnnotatedCircleTool,
AnnotatedSegmentTool,
Expand All @@ -58,6 +62,7 @@ class ImagePanel(BaseDataPanel):
AnnotatedEllipseTool,
LabelTool,
)

IO_REGISTRY = ImageIORegistry
H5_PREFIX = "DataLab_Ima"
ROIDIALOGOPTIONS = {"show_itemlist": True, "show_contrast": False}
Expand Down
5 changes: 5 additions & 0 deletions cdl/core/gui/panel/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class SignalPanel(BaseDataPanel):
PANEL_STR = _("Signal Panel")
PANEL_STR_ID = "signal"
PARAMCLASS = SignalObj

# The following tools are used to create annotations on signals. The annotation
# items are created using PlotPy's default settings. Those appearance settings
# may be modified in the configuration (see `cdl.config`).
ANNOTATION_TOOLS = (
LabelTool,
VCursorTool,
Expand All @@ -58,6 +62,7 @@ class SignalPanel(BaseDataPanel):
RectangleTool,
HRangeTool,
)

IO_REGISTRY = SignalIORegistry
H5_PREFIX = "DataLab_Sig"
ROIDIALOGCLASS = roieditor.SignalROIEditor
Expand Down
12 changes: 5 additions & 7 deletions cdl/core/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def config_annotated_shape(
item: AnnotatedShape,
fmt: str,
lbl: bool,
section: str,
option: str,
section: str | None = None,
option: str | None = None,
cmp: bool | None = None,
):
"""Configurate annotated shape.
Expand All @@ -204,7 +204,8 @@ def config_annotated_shape(
item.label.labelparam.update_item(item.label)

param.update_item(item)
item.set_style(section, option)
if section is not None and option is not None:
item.set_style(section, option)


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

0 comments on commit 1623667

Please sign in to comment.