Skip to content

Commit 1a78117

Browse files
committed
API cleanup for DataSet style parameters: generalize update_item instead of update_{obj}
1 parent 49640b9 commit 1a78117

File tree

21 files changed

+619
-288
lines changed

21 files changed

+619
-288
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ In this release, test coverage is 79%.
2424
* The `stats_func` parameter is a function that takes the image item and selected
2525
rectangle coordinates, and returns a string with the statistics to display
2626

27+
🧹 API cleanup:
28+
29+
* Deprecated `AnnotationParam.update_annotation` method: use `update_item` instead
30+
* Deprecated `AxesShapeParam.update_axes` method: use `update_item` instead
31+
* Deprecated `AxesParam.update_axes` method: use `update_item` instead
32+
* Deprecated `ImageAxesParam.update_axes` method: use `update_item` instead
33+
* Deprecated `LabelParam.update_label` method: use `update_item` instead
34+
* Deprecated `MarkerParam.update_marker` method: use `update_item` instead
35+
* Deprecated `RangeShapeParam.update_range` method: use `update_item` instead
36+
* Deprecated `ShapeParam.update_shape` method: use `update_item` instead
37+
2738
## Version 2.3.5 ##
2839

2940
This release is mainly intended to fix the Windows binary distribution, which was not
@@ -107,7 +118,6 @@ in version 2.3.1. The latter is a fugitive release that was not announced.
107118
* Fixed issue with oblique averaged cross section computation (`AttributeError` when
108119
clicking on the empty cross section plot)
109120

110-
111121
## Version 2.3.0 ##
112122

113123
In this release, test coverage is 75%.

plotpy/items/annotation.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, annotationparam: AnnotationParam | None = None) -> None:
7575
)
7676
else:
7777
self.annotationparam = annotationparam
78-
self.annotationparam.update_annotation(self)
78+
self.annotationparam.update_item(self)
7979
self.setIcon(get_icon("annotation.png"))
8080

8181
def types(self) -> tuple[type[IItemType], ...]:
@@ -98,8 +98,8 @@ def __setstate__(self, state: tuple) -> None:
9898
shape, label, param = state
9999
self.shape = shape
100100
self.label = label
101-
self.annotationparam = param
102-
self.annotationparam.update_annotation(self)
101+
self.annotationparam: AnnotationParam = param
102+
self.annotationparam.update_item(self)
103103

104104
def serialize(
105105
self,
@@ -125,7 +125,7 @@ def deserialize(
125125
"""
126126
self.annotationparam = AnnotationParam(_("Annotation"), icon="annotation.png")
127127
reader.read("annotationparam", instance=self.annotationparam)
128-
self.annotationparam.update_annotation(self)
128+
self.annotationparam.update_item(self)
129129
self.shape.deserialize(reader)
130130
self.label.deserialize(reader)
131131

@@ -434,7 +434,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
434434
update_dataset(
435435
self.annotationparam, itemparams.get("AnnotationParam"), visible_only=True
436436
)
437-
self.annotationparam.update_annotation(self)
437+
self.annotationparam.update_item(self)
438438
self.plot().SIG_ANNOTATION_CHANGED.emit(self)
439439

440440
# Autoscalable types API
@@ -471,6 +471,7 @@ class AnnotatedPoint(AnnotatedShape):
471471

472472
def __init__(self, x=0, y=0, annotationparam=None):
473473
AnnotatedShape.__init__(self, annotationparam)
474+
self.shape: PointShape
474475
self.set_pos(x, y)
475476
self.setIcon(get_icon("point_shape.png"))
476477

@@ -526,6 +527,7 @@ class AnnotatedSegment(AnnotatedShape):
526527

527528
def __init__(self, x1=0, y1=0, x2=0, y2=0, annotationparam=None):
528529
AnnotatedShape.__init__(self, annotationparam)
530+
self.shape: SegmentShape
529531
self.set_rect(x1, y1, x2, y2)
530532
self.setIcon(get_icon("segment.png"))
531533

@@ -585,6 +587,7 @@ class AnnotatedRectangle(AnnotatedShape):
585587

586588
def __init__(self, x1=0, y1=0, x2=0, y2=0, annotationparam=None):
587589
AnnotatedShape.__init__(self, annotationparam)
590+
self.shape: RectangleShape
588591
self.set_rect(x1, y1, x2, y2)
589592
self.setIcon(get_icon("rectangle.png"))
590593

@@ -645,6 +648,7 @@ def __init__(
645648
self, x0=0, y0=0, x1=0, y1=0, x2=0, y2=0, x3=0, y3=0, annotationparam=None
646649
):
647650
AnnotatedShape.__init__(self, annotationparam)
651+
self.shape: ObliqueRectangleShape
648652
self.set_rect(x0, y0, x1, y1, x2, y2, x3, y3)
649653
self.setIcon(get_icon("oblique_rectangle.png"))
650654

@@ -740,6 +744,7 @@ class AnnotatedEllipse(AnnotatedShape):
740744

741745
def __init__(self, x1=0, y1=0, x2=0, y2=0, annotationparam=None):
742746
AnnotatedShape.__init__(self, annotationparam)
747+
self.shape: EllipseShape
743748
self.set_xdiameter(x1, y1, x2, y2)
744749
self.setIcon(get_icon("ellipse_shape.png"))
745750
self.switch_to_ellipse()

plotpy/items/grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
248248
Args:
249249
itemparams: Item parameters
250250
"""
251-
self.gridparam = itemparams.get("GridParam")
251+
self.gridparam: GridParam = itemparams.get("GridParam")
252252
self.gridparam.update_grid(self)
253253

254254

plotpy/items/label.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(self, labelparam: LabelParam = None) -> None:
8383
self.labelparam = LabelParam(_("Label"), icon="label.png")
8484
else:
8585
self.labelparam = labelparam
86-
self.labelparam.update_label(self)
86+
self.labelparam.update_item(self)
8787
self._can_select = True
8888
self._can_resize = False
8989
self._can_move = True
@@ -97,7 +97,7 @@ def set_style(self, section: str, option: str) -> None:
9797
option: Option
9898
"""
9999
self.labelparam.read_config(CONF, section, option)
100-
self.labelparam.update_label(self)
100+
self.labelparam.update_item(self)
101101

102102
def __reduce__(self) -> tuple[type, tuple]:
103103
"""Return a tuple containing the constructor and its arguments"""
@@ -126,7 +126,7 @@ def deserialize(
126126
"""
127127
self.labelparam = LabelParam(_("Label"), icon="label.png")
128128
reader.read("labelparam", instance=self.labelparam)
129-
self.labelparam.update_label(self)
129+
self.labelparam.update_item(self)
130130
if isinstance(self.G, np.ndarray):
131131
self.G = tuple(self.G)
132132

@@ -333,7 +333,7 @@ def unselect(self) -> None:
333333
highlight the fact that it's not selected anymore
334334
"""
335335
self.selected = False
336-
self.labelparam.update_label(self)
336+
self.labelparam.update_item(self)
337337
self.invalidate_plot()
338338

339339
def hit_test(self, pos: QPointF) -> tuple[float, float, bool, None]:
@@ -407,7 +407,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
407407
itemparams: Item parameters
408408
"""
409409
update_dataset(self.labelparam, itemparams.get("LabelParam"), visible_only=True)
410-
self.labelparam.update_label(self)
410+
self.labelparam.update_item(self)
411411
if self.selected:
412412
self.select()
413413

@@ -837,7 +837,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
837837
update_dataset(
838838
self.labelparam, itemparams.get("LegendParam"), visible_only=True
839839
)
840-
self.labelparam.update_label(self)
840+
self.labelparam.update_item(self)
841841
if self.selected:
842842
self.select()
843843

plotpy/items/shape/axis.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def __setstate__(self, state: tuple) -> None:
7373
shapeparam, axesparam, points, z = state
7474
self.points = points
7575
self.setZ(z)
76-
self.shapeparam = shapeparam
77-
self.shapeparam.update_shape(self)
78-
self.axesparam = axesparam
79-
self.axesparam.update_axes(self)
76+
self.shapeparam: ShapeParam = shapeparam
77+
self.shapeparam.update_item(self)
78+
self.axesparam: AxesShapeParam = axesparam
79+
self.axesparam.update_item(self)
8080

8181
def serialize(
8282
self,
@@ -103,7 +103,7 @@ def deserialize(
103103
super().deserialize(reader)
104104
self.axesparam = AxesShapeParam(_("Axes"), icon="gtaxes.png")
105105
reader.read("axesparam", instance=self.axesparam)
106-
self.axesparam.update_axes(self)
106+
self.axesparam.update_item(self)
107107

108108
def get_transform_matrix(self, dx: float = 1.0, dy: float = 1.0) -> np.ndarray:
109109
"""Return the transformation matrix
@@ -143,7 +143,7 @@ def set_style(self, section: str, option: str) -> None:
143143
"""
144144
PolygonShape.set_style(self, section, option + "/border")
145145
self.axesparam.read_config(CONF, section, option)
146-
self.axesparam.update_axes(self)
146+
self.axesparam.update_item(self)
147147

148148
def move_point_to(
149149
self, handle: int, pos: tuple[float, float], ctrl: bool = False
@@ -304,7 +304,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
304304
update_dataset(
305305
self.axesparam, itemparams.get("AxesShapeParam"), visible_only=True
306306
)
307-
self.axesparam.update_axes(self)
307+
self.axesparam.update_item(self)
308308

309309

310310
assert_interfaces_valid(Axes)

plotpy/items/shape/ellipse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def __setstate__(self, state: tuple) -> None:
339339
"""Set the state of the object from a tuple"""
340340
self.shapeparam, self.points, z = state
341341
self.setZ(z)
342-
self.shapeparam.update_shape(self)
342+
self.shapeparam.update_item(self)
343343

344344

345345
assert_interfaces_valid(EllipseShape)

plotpy/items/shape/marker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(
7070
self.markerparam.read_config(CONF, "plot", "marker/cursor")
7171
else:
7272
self.markerparam = markerparam
73-
self.markerparam.update_marker(self)
73+
self.markerparam.update_item(self)
7474
self.setIcon(get_icon("marker.png"))
7575

7676
def __reduce__(self) -> tuple[type, tuple, tuple]:
@@ -85,7 +85,7 @@ def __setstate__(self, state: tuple) -> None:
8585
self.setXValue(xvalue)
8686
self.setYValue(yvalue)
8787
self.setZ(z)
88-
self.markerparam.update_marker(self)
88+
self.markerparam.update_item(self)
8989

9090
def serialize(
9191
self,
@@ -113,7 +113,7 @@ def deserialize(
113113
"""
114114
self.markerparam = MarkerParam(_("Marker"), icon="marker.png")
115115
reader.read("markerparam", instance=self.markerparam)
116-
self.markerparam.update_marker(self)
116+
self.markerparam.update_item(self)
117117
self.setXValue(reader.read("x"))
118118
self.setYValue(reader.read("y"))
119119
self.setZ(reader.read("z"))
@@ -260,7 +260,7 @@ def select(self) -> None:
260260
# Already selected
261261
return
262262
self.selected = True
263-
self.markerparam.update_marker(self)
263+
self.markerparam.update_item(self)
264264
self.invalidate_plot()
265265

266266
def unselect(self) -> None:
@@ -269,7 +269,7 @@ def unselect(self) -> None:
269269
highlight the fact that it's not selected anymore
270270
"""
271271
self.selected = False
272-
self.markerparam.update_marker(self)
272+
self.markerparam.update_item(self)
273273
self.invalidate_plot()
274274

275275
def hit_test(self, pos: QPointF) -> tuple[float, float, bool, None]:
@@ -335,7 +335,7 @@ def set_item_parameters(self, itemparams):
335335
update_dataset(
336336
self.markerparam, itemparams.get("MarkerParam"), visible_only=True
337337
)
338-
self.markerparam.update_marker(self)
338+
self.markerparam.update_item(self)
339339
if self.selected:
340340
self.select()
341341

@@ -377,7 +377,7 @@ def set_style(self, section: str, option: str) -> None:
377377
option: Option
378378
"""
379379
self.markerparam.read_config(CONF, section, option)
380-
self.markerparam.update_marker(self)
380+
self.markerparam.update_item(self)
381381

382382
def set_pos(self, x: float | None = None, y: float | None = None) -> None:
383383
"""Set marker position
@@ -412,7 +412,7 @@ def set_markerstyle(self, style: str | int | None) -> None:
412412
"""
413413
param = self.markerparam
414414
param.set_markerstyle(style)
415-
param.update_marker(self)
415+
param.update_item(self)
416416

417417
def is_vertical(self) -> bool:
418418
"""Is it a vertical cursor?

plotpy/items/shape/point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __setstate__(self, state: tuple) -> None:
7272
"""Set object state from pickled state"""
7373
self.shapeparam, self.points, z = state
7474
self.setZ(z)
75-
self.shapeparam.update_shape(self)
75+
self.shapeparam.update_item(self)
7676

7777
def boundingRect(self) -> QC.QRectF:
7878
"""Return the bounding rectangle of the shape

plotpy/items/shape/polygon.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
self.shapeparam = ShapeParam(_("Shape"), icon="rectangle.png")
6161
else:
6262
self.shapeparam = shapeparam
63-
self.shapeparam.update_shape(self)
63+
self.shapeparam.update_item(self)
6464

6565
self.pen = QG.QPen()
6666
self.brush = QG.QBrush()
@@ -92,7 +92,7 @@ def __setstate__(self, state: tuple) -> None:
9292
"""Set state information for unpickling"""
9393
self.shapeparam, self.points, self.closed, z = state
9494
self.setZ(z)
95-
self.shapeparam.update_shape(self)
95+
self.shapeparam.update_item(self)
9696

9797
def serialize(
9898
self,
@@ -121,7 +121,7 @@ def deserialize(
121121
self.closed = reader.read("closed")
122122
self.shapeparam = ShapeParam(_("Shape"), icon="rectangle.png")
123123
reader.read("shapeparam", instance=self.shapeparam)
124-
self.shapeparam.update_shape(self)
124+
self.shapeparam.update_item(self)
125125
self.points = reader.read(group_name="points", func=reader.read_array)
126126
self.setZ(reader.read("z"))
127127

@@ -135,7 +135,7 @@ def set_style(self, section: str, option: str) -> None:
135135
option: Option
136136
"""
137137
self.shapeparam.read_config(CONF, section, option)
138-
self.shapeparam.update_shape(self)
138+
self.shapeparam.update_item(self)
139139

140140
def set_points(self, points: list[tuple[float, float]]) -> None:
141141
"""Set polygon points
@@ -435,7 +435,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
435435
itemparams: Item parameters
436436
"""
437437
update_dataset(self.shapeparam, itemparams.get("ShapeParam"), visible_only=True)
438-
self.shapeparam.update_shape(self)
438+
self.shapeparam.update_item(self)
439439

440440

441441
assert_interfaces_valid(PolygonShape)

plotpy/items/shape/range.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
self.symbol = None
5757
self.sel_symbol = None
5858
if self._min is not None and self._max is not None:
59-
self.shapeparam.update_range(self) # creates all the above QObjects
59+
self.shapeparam.update_item(self) # creates all the above QObjects
6060
self.setIcon(get_icon("xrange.png"))
6161

6262
def __reduce__(self) -> tuple[type, tuple, tuple]:
@@ -97,7 +97,7 @@ def deserialize(
9797
self._max = reader.read("max")
9898
self.shapeparam = RangeShapeParam(_("Range"), icon="xrange.png")
9999
reader.read("shapeparam", instance=self.shapeparam)
100-
self.shapeparam.update_range(self)
100+
self.shapeparam.update_item(self)
101101

102102
def get_handles_pos(self) -> tuple[float, float, float]:
103103
"""Return the handles position
@@ -285,7 +285,7 @@ def set_item_parameters(self, itemparams: ItemParameters) -> None:
285285
itemparams: Item parameters
286286
"""
287287
update_dataset(self.shapeparam, itemparams.get("ShapeParam"), visible_only=True)
288-
self.shapeparam.update_range(self)
288+
self.shapeparam.update_item(self)
289289
self.sel_brush = QG.QBrush(self.brush)
290290

291291
def boundingRect(self) -> QC.QRectF:

0 commit comments

Comments
 (0)