Skip to content

Commit 70ae57a

Browse files
committed
Merge branch 'master' into develop
2 parents e3fde9e + a34583f commit 70ae57a

File tree

11 files changed

+77
-32
lines changed

11 files changed

+77
-32
lines changed

CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,43 @@ In this release, test coverage is 79%.
3232
* This is now fixed by introducing new constants for axis IDs in the
3333
`plotpy.constants` module, and using them everywhere in the code, thus avoiding
3434
to import the `plotpy.plot` module just to get the axis IDs
35+
* Fix empty label in X/Y cross section plots:
36+
* This is a regression introduced in V2.1.0
37+
* When showing the X/Y cross section plots (using the plot context menu), an empty
38+
label was displayed at the center of each of those plots
39+
* The label now shows "Enable a marker" as previously
40+
* Fix historic unexpected behavior of interactive tools:
41+
* When triggering an interactive tool (e.g. by clicking on the corresponding toolbar
42+
button), the tool `activate` method was called twice, which was not expected, but
43+
was not causing any issue given the current implementation
44+
* However, when defining custom interactive tools, this behavior could lead to
45+
unexpected results (i.e. really executing activation actions twice)
46+
* This is now fixed: the `activate` method is called only once when triggering an
47+
interactive tool
48+
49+
💥 New features / Enhancements:
50+
51+
* Alternative dictionary argument for plot options:
52+
* This new feature was introduced in the context of the cyclic import bug fix,
53+
to avoid importing the `plotpy.plot` module just to get the `PlotOptions` or
54+
`BasePlotOptions` classes
55+
* All classes (and a few functions) that used to take an `options` argument as
56+
a `BasePlotOptions` or `PlotOptions` instance now also accept a dictionary
57+
argument with the same keys as the `BasePlotOptions` or `PlotOptions` class
58+
attributes, and the same values as the corresponding attributes
59+
* This concerns the following classes and functions:
60+
* `plotpy.plot.BasePlot`
61+
* `plotpy.plot.PlotWidget`
62+
* `plotpy.plot.PlotDialog`
63+
* `plotpy.plot.PlotWindow`
64+
* `plotpy.plot.SubPlotWidget`
65+
* `plotpy.plot.SyncPlotWindow`
66+
* `plotpy.tools.RotateCropTool`
67+
* `plotpy.widgets.fit.FitDialog`
68+
* `plotpy.widgets.fliprotate.FlipRotateDialog`
69+
* `plotpy.widgets.rotatecrop.RotateCropDialog`
70+
* `plotpy.widgets.selectdialog.SelectDialog`
71+
* `plotpy.widgets.selectdialog.select_with_shape_tool`
3572

3673
## Version 2.4.2 ##
3774

plotpy/panels/csection/csplot.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
XCrossSectionItem,
1818
YCrossSectionItem,
1919
)
20+
from plotpy.plot.base import BasePlot
2021
from plotpy.styles.curve import CurveParam
2122

2223
LUT_AXIS_TITLE = _("LUT scale") + (" (0-%d)" % LUT_MAX)
@@ -27,7 +28,6 @@
2728

2829
from plotpy.items import BaseImageItem
2930
from plotpy.panels.csection.csitem import CrossSectionItem
30-
from plotpy.plot.base import BasePlot
3131

3232

3333
class BaseCrossSectionPlot(BasePlot):
@@ -364,6 +364,7 @@ def lut_changed(self, plot: BasePlot) -> None:
364364

365365

366366
class HorizontalCrossSectionPlot(BaseCrossSectionPlot):
367+
LABEL_TEXT = _("Enable a marker")
367368
CS_AXIS = X_BOTTOM
368369
Z_AXIS = Y_LEFT
369370

@@ -391,6 +392,7 @@ def axis_dir_changed(self, plot: BasePlot, axis_id: str) -> None:
391392

392393

393394
class VerticalCrossSectionPlot(BaseCrossSectionPlot):
395+
LABEL_TEXT = _("Enable a marker")
394396
CS_AXIS = Y_LEFT
395397
Z_AXIS = X_BOTTOM
396398
Z_MAX_MAJOR = 3
@@ -419,8 +421,6 @@ def axis_dir_changed(self, plot: BasePlot, axis_id: str) -> None:
419421

420422

421423
class XYCrossSectionMixin:
422-
LABEL_TEXT = _("Enable a marker")
423-
424424
def connect_plot(self, plot: BasePlot) -> None:
425425
"""Connect plot to cross section plot
426426

plotpy/plot/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,11 @@ class BasePlot(qwt.QwtPlot):
298298
def __init__(
299299
self,
300300
parent: QW.QWidget | None = None,
301-
options: BasePlotOptions | None = None,
301+
options: BasePlotOptions | dict[str, Any] | None = None,
302302
) -> None:
303303
super().__init__(parent)
304+
if isinstance(options, dict):
305+
options = BasePlotOptions(**options)
304306
self.options = options = options if options is not None else BasePlotOptions()
305307

306308
self.__autoscale_excluded_items: list[itf.IBasePlotItem] = []

plotpy/plot/plotwidget.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import abc
66
import warnings
77
from dataclasses import dataclass
8-
from typing import TYPE_CHECKING
8+
from typing import TYPE_CHECKING, Any
99

1010
from guidata.configtools import get_icon
1111
from guidata.qthelpers import win32_fix_title_bar_background
@@ -115,10 +115,12 @@ class BasePlotWidget(QW.QSplitter):
115115
def __init__(
116116
self,
117117
parent: QWidget = None,
118-
options: PlotOptions | None = None,
118+
options: PlotOptions | dict[str, Any] | None = None,
119119
) -> None:
120120
super().__init__(parent)
121121
self.manager: PlotManager | None = None
122+
if isinstance(options, dict):
123+
options = PlotOptions(**options)
122124
self.options = options = options if options is not None else PlotOptions()
123125
self.setSizePolicy(QW.QSizePolicy.Expanding, QW.QSizePolicy.Expanding)
124126
self.plot = self.create_plot()
@@ -304,7 +306,7 @@ def __init__(
304306
self,
305307
parent: QWidget | None = None,
306308
toolbar: bool = False,
307-
options: PlotOptions | None = None,
309+
options: PlotOptions | dict[str, Any] | None = None,
308310
panels: tuple[PanelWidget] | None = None,
309311
auto_tools: bool = True,
310312
) -> None:
@@ -456,7 +458,7 @@ def get_manager(self) -> PlotManager:
456458
def setup_widget(
457459
self,
458460
toolbar: bool = False,
459-
options: dict | None = None,
461+
options: PlotOptions | dict[str, Any] | None = None,
460462
panels: list[PanelWidget] | None = None,
461463
auto_tools: bool = False,
462464
) -> None:
@@ -539,7 +541,7 @@ def __init__(
539541
self,
540542
parent: QWidget | None = None,
541543
toolbar: bool = False,
542-
options: PlotOptions | None = None,
544+
options: PlotOptions | dict[str, Any] | None = None,
543545
panels: list[PanelWidget] | None = None,
544546
auto_tools: bool = True,
545547
title: str = "PlotPy",
@@ -590,7 +592,7 @@ def get_manager(self) -> PlotManager:
590592
def setup_widget(
591593
self,
592594
toolbar: bool = False,
593-
options: PlotOptions | None = None,
595+
options: PlotOptions | dict[str, Any] | None = None,
594596
panels: list[PanelWidget] | None = None,
595597
auto_tools: bool = False,
596598
) -> None:
@@ -696,7 +698,7 @@ def __init__(
696698
self,
697699
parent: QWidget | None = None,
698700
toolbar: bool = False,
699-
options: PlotOptions | None = None,
701+
options: PlotOptions | dict[str, Any] | None = None,
700702
panels: list[PanelWidget] | None = None,
701703
auto_tools: bool = True,
702704
title: str = "PlotPy",
@@ -742,7 +744,7 @@ def get_manager(self) -> PlotManager:
742744
def setup_widget(
743745
self,
744746
toolbar: bool = False,
745-
options: PlotOptions | None = None,
747+
options: PlotOptions | dict[str, Any] | None = None,
746748
panels: list[PanelWidget] | None = None,
747749
auto_tools: bool = False,
748750
) -> None:
@@ -843,7 +845,7 @@ def __init__(
843845
self,
844846
manager: PlotManager,
845847
parent: QWidget | None = None,
846-
options: PlotOptions | None = None,
848+
options: PlotOptions | dict[str, Any] | None = None,
847849
) -> None:
848850
self.plotlayout: QW.QGridLayout | None = None
849851
super().__init__(parent, options=options)
@@ -914,7 +916,7 @@ def __init__(
914916
self,
915917
parent: QWidget | None = None,
916918
toolbar: bool = True,
917-
options: PlotOptions | None = None,
919+
options: PlotOptions | dict[str, Any] | None = None,
918920
auto_tools: bool = True,
919921
title: str = "PlotPy",
920922
icon: str = "plotpy.svg",

plotpy/tools/base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ def register_plot(self, baseplot: BasePlot) -> None:
236236
filter.set_cursor(curs, start_state)
237237

238238
def interactive_triggered(self, action: QW.QAction) -> None:
239-
"""Slot called when the tool action is triggered
239+
"""Slot called when the interactive tool action group is triggered.
240+
The purpose is to deactivate all other tools in the group.
241+
242+
Note that the tool itself has already been activated because the action
243+
triggered the `activate` method.
240244
241245
Args:
242246
action: tool action
243247
"""
244-
if action is self.action:
245-
self.activate()
246-
else:
248+
if action is not self.action:
247249
self.deactivate()
248250

249251
def activate(self) -> None:

plotpy/tools/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ def __init__(
13211321
self,
13221322
manager: PlotManager,
13231323
toolbar_id=DefaultToolbarID,
1324-
options: PlotOptions | None = None,
1324+
options: PlotOptions | dict[str, Any] | None = None,
13251325
) -> None:
13261326
super().__init__(
13271327
manager,

plotpy/widgets/basetransform.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Union
17+
from typing import TYPE_CHECKING, Any, Union
1818

1919
from guidata.configtools import get_icon
2020
from guidata.qthelpers import create_toolbutton
@@ -166,9 +166,11 @@ def __init__(
166166
self,
167167
parent: QW.QWidget,
168168
toolbar: bool = False,
169-
options: PlotOptions | None = None,
169+
options: PlotOptions | dict[str, Any] | None = None,
170170
) -> None:
171171
super().__init__(parent)
172+
if isinstance(options, dict):
173+
options = PlotOptions(**options)
172174
options = options if options is not None else PlotOptions()
173175
options.type = "image"
174176
self.plot_widget = PlotWidget(self, options=options, toolbar=toolbar)

plotpy/widgets/fit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from __future__ import annotations
4848

4949
from collections.abc import Callable
50-
from typing import TYPE_CHECKING
50+
from typing import TYPE_CHECKING, Any
5151

5252
import guidata
5353
import numpy as np
@@ -857,7 +857,7 @@ def __init__(
857857
edit: bool = True,
858858
toolbar: bool = False,
859859
auto_tools: bool = True,
860-
options: PlotOptions | None = None,
860+
options: PlotOptions | dict[str, Any] | None = None,
861861
parent: QWidget | None = None,
862862
panels: list[PanelWidget] | None = None,
863863
param_cols: int = 1,

plotpy/widgets/fliprotate.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING
27+
from typing import TYPE_CHECKING, Any
2828

2929
import numpy as np
3030
from guidata.configtools import get_icon
@@ -99,7 +99,7 @@ def __init__(
9999
self,
100100
parent: QWidget,
101101
title: str | None = None,
102-
options: dict | None = None,
102+
options: PlotOptions | dict[str, Any] | None = None,
103103
resize_to: tuple[int, int] | None = None,
104104
edit: bool = True,
105105
toolbar: bool = False,
@@ -169,7 +169,7 @@ def __init__(
169169
self,
170170
parent: QWidget,
171171
toolbar: bool = False,
172-
options: PlotOptions | None = None,
172+
options: PlotOptions | dict[str, Any] | None = None,
173173
):
174174
self.angle_combo = None
175175
self.hflip_btn = None

plotpy/widgets/rotatecrop.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING
27+
from typing import TYPE_CHECKING, Any
2828

2929
from guidata.qthelpers import win32_fix_title_bar_background
3030
from qtpy import QtCore as QC
@@ -138,7 +138,7 @@ def __init__(
138138
self,
139139
parent: QWidget,
140140
title: str | None = None,
141-
options: PlotOptions | None = None,
141+
options: PlotOptions | dict[str, Any] | None = None,
142142
resize_to: tuple[int, int] | None = None,
143143
edit: bool = True,
144144
toolbar: bool = False,
@@ -204,7 +204,7 @@ def __init__(
204204
self,
205205
parent: QWidget,
206206
toolbar: bool = False,
207-
options: PlotOptions | None = None,
207+
options: PlotOptions | dict[str, Any] | None = None,
208208
) -> None:
209209
super().__init__(parent, toolbar=toolbar, options=options)
210210
self.transform = RotateCropTransform(self, self.plot_widget.manager)

plotpy/widgets/selectdialog.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
from __future__ import annotations
4141

42-
from typing import TYPE_CHECKING
42+
from typing import TYPE_CHECKING, Any
4343

4444
from guidata.configtools import get_icon
4545
from guidata.qthelpers import exec_dialog
@@ -75,7 +75,7 @@ def __init__(
7575
self,
7676
parent: QWidget | None = None,
7777
toolbar: bool = False,
78-
options: PlotOptions | None = None,
78+
options: PlotOptions | dict[str, Any] | None = None,
7979
panels: list[PanelWidget] | None = None,
8080
auto_tools: bool = True,
8181
title: str = "PlotPy",
@@ -142,7 +142,7 @@ def select_with_shape_tool(
142142
other_items: list[QwtPlotItem] = [],
143143
tooldialogclass: SelectDialog = SelectDialog,
144144
toolbar: bool = False,
145-
options: PlotOptions | None = None,
145+
options: PlotOptions | dict[str, Any] | None = None,
146146
icon=None,
147147
**kwargs,
148148
) -> AbstractShape:

0 commit comments

Comments
 (0)