Skip to content

Commit

Permalink
Update PlotPy dependency to version 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Jun 28, 2024
1 parent 454dd87 commit a98b70a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 90 deletions.
49 changes: 18 additions & 31 deletions cdl/core/gui/docks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@
RectZoomTool,
SelectTool,
)

# TODO: PlotPy 2.4 - Remove this try/except block
try:
# PlotPy 2.4 and later
from plotpy.tools.image import get_stats as get_image_stats
except ImportError:
# PlotPy 2.3 and earlier
pass

from plotpy.tools.image import get_stats as get_image_stats
from qtpy import QtCore as QC
from qtpy import QtGui as QG
from qtpy import QtWidgets as QW
Expand Down Expand Up @@ -250,30 +242,25 @@ def __register_other_tools(self) -> None:
mgr.add_separator_tool()
if self.options.type == PlotType.CURVE:
mgr.register_curve_tools()
# TODO: PlotPy 2.4 - Remove this condition
if compare_versions(plotpy.__version__, ">=", "2.4"):
# Customizing the CurveStatsTool
statstool = mgr.get_tool(CurveStatsTool)
statstool.set_labelfuncs(CURVESTATSTOOL_LABELFUNCS)
statstool = mgr.get_tool(CurveStatsTool)
statstool.set_labelfuncs(CURVESTATSTOOL_LABELFUNCS)
else:
mgr.register_image_tools()
# TODO: PlotPy 2.4 - Remove this condition
if compare_versions(plotpy.__version__, ">=", "2.4"):
# Customizing the ImageStatsTool
statstool = mgr.get_tool(ImageStatsTool)
statstool.set_stats_func(get_more_image_stats, replace=True)
# Customizing the X and Y cross section panels
plot = mgr.get_plot()
for panel in (mgr.get_xcs_panel(), mgr.get_ycs_panel()):
to_signal_action = create_action(
panel,
_("Process signal"),
icon=get_icon("to_signal.svg"),
triggered=lambda panel=panel: profile_to_signal(plot, panel),
)
tb = panel.toolbar
tb.insertSeparator(tb.actions()[0])
tb.insertAction(tb.actions()[0], to_signal_action)
# Customizing the ImageStatsTool
statstool = mgr.get_tool(ImageStatsTool)
statstool.set_stats_func(get_more_image_stats, replace=True)
# Customizing the X and Y cross section panels
plot = mgr.get_plot()
for panel in (mgr.get_xcs_panel(), mgr.get_ycs_panel()):
to_signal_action = create_action(
panel,
_("Process signal"),
icon=get_icon("to_signal.svg"),
triggered=lambda panel=panel: profile_to_signal(plot, panel),
)
tb = panel.toolbar
tb.insertSeparator(tb.actions()[0])
tb.insertAction(tb.actions()[0], to_signal_action)

mgr.add_separator_tool()
mgr.register_other_tools()
Expand Down
8 changes: 1 addition & 7 deletions cdl/core/gui/roieditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,7 @@ def update_roi_titles(self):
super().update_roi_titles()
for index, roi_item in enumerate(self.roi_items):
roi_item.annotationparam.title = f"ROI{index:02d}"
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
roi_item.annotationparam.update_item(roi_item)
except AttributeError:
# PlotPy 2.3 and earlier
roi_item.annotationparam.update_annotation(roi_item)
roi_item.annotationparam.update_item(roi_item)

@staticmethod
def get_roi_item_coords(roi_item):
Expand Down
37 changes: 6 additions & 31 deletions cdl/core/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,9 @@ def config_annotated_shape(

if isinstance(item, AnnotatedSegment):
item.label.labelparam.anchor = "T"
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
item.label.labelparam.update_item(item.label)
except AttributeError:
# PlotPy 2.3 and earlier
item.label.labelparam.update_label(item.label)

# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
param.update_item(item)
except AttributeError:
# PlotPy 2.3 and earlier
param.update_annotation(item)
item.label.labelparam.update_item(item.label)

param.update_item(item)
item.set_style("plot", option)


Expand Down Expand Up @@ -477,13 +465,7 @@ def create_label_item(self, obj: BaseObj) -> LabelItem | None:
font = get_font(PLOTPY_CONF, "plot", "label/properties/font")
item.set_style("plot", "label/properties")
item.labelparam.font.update_param(font)
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
item.labelparam.update_item(item)
except AttributeError:
# PlotPy 2.3 and earlier
item.labelparam.update_label(item)
item.labelparam.update_item(item)
return item

def get_label_item(self) -> LabelItem | None:
Expand Down Expand Up @@ -778,15 +760,8 @@ def create_shape_item(
sparam.sel_symbol.size = 6
aparam = item.annotationparam
aparam.title = self.title
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
sparam.update_item(item.shape)
aparam.update_item(item)
except AttributeError:
# PlotPy 2.3 and earlier
sparam.update_shape(item.shape)
aparam.update_annotation(item)
sparam.update_item(item.shape)
aparam.update_item(item)
elif self.shapetype is ShapeTypes.RECTANGLE:
x0, y0, x1, y1 = coords
item = make.annotated_rectangle(x0, y0, x1, y1, title=self.title)
Expand Down
16 changes: 2 additions & 14 deletions cdl/core/model/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,7 @@ def make_roi_rectangle(
param = roi_item.label.labelparam
param.anchor = "BL"
param.xc, param.yc = 5, -5
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
param.update_item(roi_item.label)
except AttributeError:
# PlotPy 2.3 and earlier
param.update_label(roi_item.label)
param.update_item(roi_item.label)
return roi_item


Expand All @@ -72,13 +66,7 @@ def make_roi_circle(x0: int, y0: int, x1: int, y1: int, title: str) -> Annotated
"""
item = AnnotatedCircle(x0, y0, x1, y1)
item.annotationparam.title = title
# TODO: PlotPy 2.4 - Remove this try-except block
try:
# PlotPy 2.4 and later
item.annotationparam.update_item(item)
except AttributeError:
# PlotPy 2.3 and earlier
item.annotationparam.update_annotation(item)
item.annotationparam.update_item(item)
item.set_style("plot", "shape/drag")
return item

Expand Down
6 changes: 0 additions & 6 deletions cdl/tests/features/common/stats_tools_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import numpy as np
import plotpy
import pytest
from guidata.qthelpers import exec_dialog, qt_app_context
from plotpy.constants import PlotType
from plotpy.tests.unit.utils import drag_mouse
Expand Down Expand Up @@ -49,11 +48,6 @@ def simulate_stats_tool(
return widget


# TODO: PlotPy 2.4 - Remove skipif decorator
@pytest.mark.skipif(
compare_versions(plotpy.__version__, "<", "2.4"),
reason="PlotPy version < 2.4",
)
def test_stats_tool() -> None:
"""Test CurveStatsTool with a custom signal."""
sig = create_paracetamol_signal()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies = [
"PyWavelets >= 1.1",
"psutil >= 5.5",
"guidata >= 3.5",
"PlotPy >= 2.3",
"PlotPy >= 2.4",
"QtPy >= 1.9",
]
dynamic = ["version"]
Expand Down

0 comments on commit a98b70a

Please sign in to comment.