Skip to content

Commit

Permalink
PythonQwt 0.12.7 compat.: add __deepcopy__ method to EditableColormap…
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
PierreRaybaut committed Jul 26, 2024
1 parent 11f936a commit 68eae7b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plotpy/widgets/colormap/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ def __init__(self, *args, name: str | None = None) -> None:
self.name = name or "temporary"
self.invert = False

def __deepcopy__(self, memo: dict[int, object]) -> EditableColormap:
"""Deepcopy method to copy the colormap object.
Args:
memo: dict to store the copied objects
Returns:
New EditableColormap instance.
"""
new_instance = EditableColormap(self.color1(), self.color2(), name=self.name)
for stop in self.colorStops():
stop: ColorStop
new_instance.addColorStop(stop.pos, stop.rgb)
return new_instance

def rgb(self, interval: QwtInterval, value: float) -> int:
"""Returns the color of the colormap at the given value.
This overriden method is used to add the possibility to invert the colormap
Expand Down

0 comments on commit 68eae7b

Please sign in to comment.