Skip to content

Commit ded457d

Browse files
committed
Alternative dictionary argument for plot options
1 parent cdae8db commit ded457d

File tree

9 files changed

+55
-25
lines changed

9 files changed

+55
-25
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@ In this release, test coverage is 79%.
1313
`plotpy.constants` module, and using them everywhere in the code, thus avoiding
1414
to import the `plotpy.plot` module just to get the axis IDs
1515

16+
💥 New features / Enhancements:
17+
18+
* Alternative dictionary argument for plot options:
19+
* This new feature was introduced in the context of the cyclic import bug fix,
20+
to avoid importing the `plotpy.plot` module just to get the `PlotOptions` or
21+
`BasePlotOptions` classes
22+
* All classes (and a few functions) that used to take an `options` argument as
23+
a `BasePlotOptions` or `PlotOptions` instance now also accept a dictionary
24+
argument with the same keys as the `BasePlotOptions` or `PlotOptions` class
25+
attributes, and the same values as the corresponding attributes
26+
* This concerns the following classes and functions:
27+
* `plotpy.plot.BasePlot`
28+
* `plotpy.plot.PlotWidget`
29+
* `plotpy.plot.PlotDialog`
30+
* `plotpy.plot.PlotWindow`
31+
* `plotpy.plot.SubPlotWidget`
32+
* `plotpy.plot.SyncPlotWindow`
33+
* `plotpy.tools.RotateCropTool`
34+
* `plotpy.widgets.fit.FitDialog`
35+
* `plotpy.widgets.fliprotate.FlipRotateDialog`
36+
* `plotpy.widgets.rotatecrop.RotateCropDialog`
37+
* `plotpy.widgets.selectdialog.SelectDialog`
38+
* `plotpy.widgets.selectdialog.select_with_shape_tool`
39+
1640
## Version 2.4.2 ##
1741

1842
In this release, test coverage is 79%.

plotpy/plot/base.py

Lines changed: 3 additions & 1 deletion
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

Lines changed: 12 additions & 10 deletions
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/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ def __init__(
12651265
self,
12661266
manager: PlotManager,
12671267
toolbar_id=DefaultToolbarID,
1268-
options: PlotOptions | None = None,
1268+
options: PlotOptions | dict[str, Any] | None = None,
12691269
) -> None:
12701270
super().__init__(
12711271
manager,

plotpy/widgets/basetransform.py

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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)