Skip to content

Commit 20ca009

Browse files
committed
Renamed CustomQwtLinearColorMap to EditableColormap
1 parent be5a516 commit 20ca009

9 files changed

Lines changed: 43 additions & 49 deletions

File tree

plotpy/colormaps/colormap.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
DEFAULT_COLORMAPS_PATH,
4949
save_colormaps,
5050
)
51-
from plotpy.widgets.colormap.widget import (
52-
CustomQwtLinearColormap, # Reuse matplotlib data
53-
)
51+
from plotpy.widgets.colormap.widget import EditableColormap # Reuse matplotlib data
5452

5553
# usefull to obtain a full color map
5654
FULLRANGE = QwtInterval(0.0, 1.0)
@@ -68,7 +66,7 @@ def _interpolate(val, vmin, vmax):
6866
return (1 - interp) * vmin[1] + interp * vmax[2]
6967

7068

71-
def _setup_colormap(cmap: CustomQwtLinearColormap, cmdata):
69+
def _setup_colormap(cmap: EditableColormap, cmdata):
7270
"""Setup a CustomQwtLinearColorMap according to
7371
matplotlib's data
7472
"""
@@ -93,7 +91,7 @@ def _setup_colormap(cmap: CustomQwtLinearColormap, cmdata):
9391
cmap.addColorStop(i, col)
9492

9593

96-
def get_cmap(name: str) -> CustomQwtLinearColormap:
94+
def get_cmap(name: str) -> EditableColormap:
9795
"""Get a colormap from its name
9896
9997
Args:
@@ -106,15 +104,15 @@ def get_cmap(name: str) -> CustomQwtLinearColormap:
106104
if name in COLORMAPS:
107105
return COLORMAPS[name]
108106

109-
colormap = CustomQwtLinearColormap()
107+
colormap = EditableColormap()
110108
COLORMAPS[name] = colormap
111109
COLORMAPS[colormap] = name
112110
data = getattr(_cm, "_" + name + "_data")
113111
_setup_colormap(colormap, data)
114112
return colormap
115113

116114

117-
def get_cmap_name(cmap: CustomQwtLinearColormap) -> str:
115+
def get_cmap_name(cmap: EditableColormap) -> str:
118116
"""Return colormap's name
119117
120118
Args:
@@ -143,7 +141,7 @@ def get_colormap_list() -> list[str]:
143141

144142

145143
def build_icon_from_cmap(
146-
cmap: CustomQwtLinearColormap, width: int = 24, height: int = 24
144+
cmap: EditableColormap, width: int = 24, height: int = 24
147145
) -> QG.QIcon:
148146
"""Builds an icon representing the colormap
149147
@@ -176,7 +174,7 @@ def build_icon_from_cmap_name(cmap_name: str) -> QG.QIcon:
176174
return icon
177175

178176

179-
def register_extra_colormap(name: str, colormap: CustomQwtLinearColormap) -> None:
177+
def register_extra_colormap(name: str, colormap: EditableColormap) -> None:
180178
"""Add a custom colormap to the list of known colormaps
181179
must be done early in the import process because
182180
datasets will use get_color_map list at import time

plotpy/items/image/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
from plotpy.interfaces import IItemType
6060
from plotpy.styles.base import ItemParameters
61-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
61+
from plotpy.widgets.colormap.widget import EditableColormap
6262

6363

6464
class BaseImageItem(QwtPlotItem):
@@ -416,7 +416,7 @@ def set_background_color(self, qcolor: QColor | str) -> None:
416416
else:
417417
self.lut = (a, b, np.uint32(QG.QColor(qcolor).rgb() & 0xFFFFFF), cmap)
418418

419-
def set_color_map(self, name_or_table: str | CustomQwtLinearColormap) -> None:
419+
def set_color_map(self, name_or_table: str | EditableColormap) -> None:
420420
"""Set colormap
421421
422422
Args:
@@ -459,7 +459,7 @@ def set_color_map(self, name_or_table: str | CustomQwtLinearColormap) -> None:
459459
if plot:
460460
plot.update_colormap_axis(self)
461461

462-
def get_color_map(self) -> CustomQwtLinearColormap | None:
462+
def get_color_map(self) -> EditableColormap | None:
463463
"""Get colormap
464464
465465
Returns:

plotpy/mathutils/colormaps.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from qwt import QwtInterval, toQImage
1919

2020
from plotpy.config import CONF
21-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
21+
from plotpy.widgets.colormap.widget import EditableColormap
2222

2323
# from guidata.dataset.datatypes import NoDefault
2424
FULLRANGE = QwtInterval(0.0, 1.0)
25-
DEFAULT = CustomQwtLinearColormap(name="default")
25+
DEFAULT = EditableColormap(name="default")
2626

2727

2828
def load_raw_colormaps_from_json(
@@ -48,7 +48,7 @@ def load_raw_colormaps_from_json(
4848
return {}
4949

5050

51-
def load_qwt_colormaps_from_json(json_path: str) -> dict[str, CustomQwtLinearColormap]:
51+
def load_qwt_colormaps_from_json(json_path: str) -> dict[str, EditableColormap]:
5252
"""Same as function load_raw_colormaps_from_json but transforms the raw colormaps
5353
into CustomQwtLinearColormap objects that are used by plotpy.
5454
@@ -60,12 +60,12 @@ def load_qwt_colormaps_from_json(json_path: str) -> dict[str, CustomQwtLinearCol
6060
Dictionnary of colormpas names -> CustomQwtLinearColormap
6161
"""
6262
return {
63-
name.lower(): CustomQwtLinearColormap.from_iterable(iterable, name=name)
63+
name.lower(): EditableColormap.from_iterable(iterable, name=name)
6464
for name, iterable in load_raw_colormaps_from_json(json_path).items()
6565
}
6666

6767

68-
def save_colormaps(json_filename: str, colormaps: dict[str, CustomQwtLinearColormap]):
68+
def save_colormaps(json_filename: str, colormaps: dict[str, EditableColormap]):
6969
"""Saves colormaps into the given json file. Refer ton function get_cmap_path to
7070
know what json_filename can be used.
7171
@@ -80,7 +80,7 @@ def save_colormaps(json_filename: str, colormaps: dict[str, CustomQwtLinearColor
8080

8181

8282
def build_icon_from_cmap(
83-
cmap: CustomQwtLinearColormap, width: int = 16, height: int = 16
83+
cmap: EditableColormap, width: int = 16, height: int = 16
8484
) -> QG.QIcon:
8585
"""Builds an icon representing the colormap
8686
@@ -110,7 +110,7 @@ def build_icon_from_cmap_name(cmap_name: str) -> QG.QIcon:
110110
return build_icon_from_cmap(get_cmap(cmap_name.lower()))
111111

112112

113-
def get_cmap(cmap_name: str) -> CustomQwtLinearColormap:
113+
def get_cmap(cmap_name: str) -> EditableColormap:
114114
"""Returns the colormap with the given name from the ALL_COLORMAPS global variable.
115115
If the colormap is not found, returns the DEFAULT colormap.
116116

plotpy/tests/features/test_colormap_editor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from guidata.qthelpers import qt_app_context
2020

2121
from plotpy.widgets.colormap.editor import ColorMapEditor
22-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
22+
from plotpy.widgets.colormap.widget import EditableColormap
2323

2424

2525
def test_colormap_manager() -> None:
@@ -39,7 +39,7 @@ def test_colormap_manager() -> None:
3939
"Initialization of a new colormap editor with the previous colormap: ",
4040
cmap_tuples,
4141
)
42-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
42+
new_cmap = EditableColormap.from_iterable(cmap_tuples)
4343
print(f"{new_cmap.to_tuples()}")
4444
editor = ColorMapEditor(None, colormap=new_cmap)
4545
editor.show()
@@ -50,7 +50,7 @@ def test_colormap_manager() -> None:
5050
"modified post-initialization with the previous colormap: ",
5151
cmap_tuples,
5252
)
53-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
53+
new_cmap = EditableColormap.from_iterable(cmap_tuples)
5454
editor = ColorMapEditor(None)
5555
editor.set_colormap(new_cmap)
5656
editor.show()
@@ -63,7 +63,7 @@ def test_colormap_manager() -> None:
6363
"255 + 1: ",
6464
cmap_tuples,
6565
)
66-
new_cmap = CustomQwtLinearColormap.from_iterable(cmap_tuples)
66+
new_cmap = EditableColormap.from_iterable(cmap_tuples)
6767
editor = ColorMapEditor(None)
6868
editor.set_colormap(new_cmap)
6969
editor.show()

plotpy/tests/features/test_colormap_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from plotpy.mathutils.colormaps import ALL_COLORMAPS
2020
from plotpy.widgets.colormap.manager import ColorMapManager
21-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
21+
from plotpy.widgets.colormap.widget import EditableColormap
2222

2323

2424
def test_colormap_manager() -> None:
@@ -27,7 +27,7 @@ def test_colormap_manager() -> None:
2727
red = QG.QColor(QC.Qt.GlobalColor.red)
2828
blue = QG.QColor(QC.Qt.GlobalColor.blue)
2929
yellow = QG.QColor(QC.Qt.GlobalColor.yellow)
30-
cmap = CustomQwtLinearColormap(blue, yellow, name="kinda_viridis")
30+
cmap = EditableColormap(blue, yellow, name="kinda_viridis")
3131
ALL_COLORMAPS["kinda_viridis"] = cmap
3232
dlg = ColorMapManager(None, active_colormap="YlGn")
3333
dlg.colormap_editor.colormap_widget.add_handle_at_relative_pos(0.5, red)

plotpy/tools/image.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from plotpy.tools.misc import OpenFileTool
5353
from plotpy.tools.shape import CircleTool, RectangleTool, RectangularShapeTool
5454
from plotpy.widgets.colormap.manager import ColorMapManager
55-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
55+
from plotpy.widgets.colormap.widget import EditableColormap
5656
from plotpy.widgets.imagefile import exec_image_save_dialog
5757

5858
if TYPE_CHECKING: # pragma: no cover
@@ -454,9 +454,7 @@ def __init__(
454454
tip=_("Select colormap for active image"),
455455
toolbar_id=toolbar_id,
456456
)
457-
self._active_colormap: CustomQwtLinearColormap = ALL_COLORMAPS.get(
458-
"jet", DEFAULT
459-
)
457+
self._active_colormap: EditableColormap = ALL_COLORMAPS.get("jet", DEFAULT)
460458
self.default_icon = build_icon_from_cmap_name(self._active_colormap.name)
461459
if self.action is not None:
462460
self.action.setEnabled(False)
@@ -498,13 +496,13 @@ def get_selected_images(self, plot: BasePlot) -> list[IBasePlotItem]:
498496
items = [active_image]
499497
return items
500498

501-
def activate_cmap(self, cmap: str | CustomQwtLinearColormap) -> None:
499+
def activate_cmap(self, cmap: str | EditableColormap) -> None:
502500
"""Activate the given colormap. Supports mutliple input types.
503501
504502
Args:
505503
cmap: Cmap to apply for currently selected images.
506504
"""
507-
assert isinstance(cmap, (str, CustomQwtLinearColormap))
505+
assert isinstance(cmap, (str, EditableColormap))
508506
if isinstance(cmap, str):
509507
self._active_colormap = get_cmap(cmap)
510508
else:

plotpy/widgets/colormap/editor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from guidata.dataset.qtwidgets import DataSetEditGroupBox
2020

2121
from plotpy.config import _
22-
from plotpy.widgets.colormap.widget import ColorMapWidget, CustomQwtLinearColormap
22+
from plotpy.widgets.colormap.widget import ColorMapWidget, EditableColormap
2323

2424

2525
class ColorPickDataSet(DataSet):
@@ -116,7 +116,7 @@ def __init__(
116116
cmap_height: int = 50,
117117
color1: QG.QColor | None = None,
118118
color2: QG.QColor | None = None,
119-
colormap: CustomQwtLinearColormap | None = None,
119+
colormap: EditableColormap | None = None,
120120
) -> None:
121121
super().__init__(parent)
122122

@@ -148,7 +148,7 @@ def __init__(
148148
self.update_current_dataset
149149
)
150150

151-
def set_colormap(self, colormap: CustomQwtLinearColormap) -> None:
151+
def set_colormap(self, colormap: EditableColormap) -> None:
152152
"""Replaces the current colormap.
153153
154154
Args:
@@ -159,7 +159,7 @@ def set_colormap(self, colormap: CustomQwtLinearColormap) -> None:
159159
self.colormap_widget.blockSignals(False)
160160
self.setup_tabs()
161161

162-
def get_colormap(self) -> CustomQwtLinearColormap:
162+
def get_colormap(self) -> EditableColormap:
163163
"""Get the current colormap being edited.
164164
165165
Returns:

plotpy/widgets/colormap/manager.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
save_colormaps,
2929
)
3030
from plotpy.widgets.colormap.editor import ColorMapEditor
31-
from plotpy.widgets.colormap.widget import CustomQwtLinearColormap
31+
from plotpy.widgets.colormap.widget import EditableColormap
3232

3333

3434
class ColorMapNameEdit(QW.QDialog):
@@ -109,7 +109,7 @@ def __init__(
109109
self.setWindowIcon(get_icon("cmap_edit.png"))
110110
self.setWindowTitle(_("Colormap manager"))
111111

112-
self.__returned_colormap: CustomQwtLinearColormap | None = None
112+
self.__returned_colormap: EditableColormap | None = None
113113

114114
if active_colormap is None or active_colormap.lower() not in ALL_COLORMAPS:
115115
active_colormap = next(iter(ALL_COLORMAPS))
@@ -200,13 +200,13 @@ def set_colormap(self, index: int) -> None:
200200
Args:
201201
index: index of the colormap in the QComboBox.
202202
"""
203-
cmap_copy: CustomQwtLinearColormap = deepcopy(self._cmap_choice.itemData(index))
203+
cmap_copy: EditableColormap = deepcopy(self._cmap_choice.itemData(index))
204204
self.colormap_editor.set_colormap(cmap_copy)
205205
is_new_colormap = cmap_copy.name.lower() not in ALL_COLORMAPS
206206
self._changes_saved = True
207207
self._save_btn.setEnabled(is_new_colormap)
208208

209-
def get_colormap(self) -> CustomQwtLinearColormap:
209+
def get_colormap(self) -> EditableColormap:
210210
"""Return the selected colormap object.
211211
212212
Returns:
@@ -263,12 +263,10 @@ def __get_new_colormap_name(self, title: str, name: str) -> str | None:
263263

264264
def new_colormap(self) -> None:
265265
"""Create a new colormap and set it as the current colormap."""
266-
cmap = CustomQwtLinearColormap(
267-
QG.QColor(0), QG.QColor(4294967295), name=_("New")
268-
)
266+
cmap = EditableColormap(QG.QColor(0), QG.QColor(4294967295), name=_("New"))
269267
self.save_colormap(cmap)
270268

271-
def save_colormap(self, cmap: CustomQwtLinearColormap | None = None) -> bool:
269+
def save_colormap(self, cmap: EditableColormap | None = None) -> bool:
272270
"""Saves the current colormap and handles the validation process. The saved
273271
colormaps can only be saved in the custom colormaps.
274272

plotpy/widgets/colormap/widget.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
]
3030

3131

32-
class CustomQwtLinearColormap(QwtLinearColorMap):
32+
class EditableColormap(QwtLinearColorMap):
3333
"""Overload of the QwtLinearColorMap class to add some features. This class is
3434
temporary and should be removed when its features are added to QwtPython.
3535
@@ -106,7 +106,7 @@ def update_stops_steps(self, stop_index: int) -> None:
106106
@classmethod
107107
def from_iterable(
108108
cls, iterable: Sequence[tuple[float, str]], name=None
109-
) -> "CustomQwtLinearColormap":
109+
) -> "EditableColormap":
110110
"""Converts the given iterable of tuples to a colormap (instance of Self).
111111
The iterable must be at least of length 2. If the iterable is of length 1,
112112
the colormap will be composed of two identical colors. If the iterable is
@@ -243,7 +243,7 @@ def __init__(
243243
cmap_height: int = 50,
244244
color1: QG.QColor | None = None,
245245
color2: QG.QColor | None = None,
246-
colormap: CustomQwtLinearColormap | None = None,
246+
colormap: EditableColormap | None = None,
247247
) -> None:
248248
super().__init__(parent)
249249

@@ -274,7 +274,7 @@ def __init__(
274274
if colormap is None:
275275
color1 = QG.QColor(QC.Qt.GlobalColor.blue) if color1 is None else color1
276276
color2 = QG.QColor(QC.Qt.GlobalColor.yellow) if color2 is None else color2
277-
self._colormap = CustomQwtLinearColormap(color1, color2)
277+
self._colormap = EditableColormap(color1, color2)
278278
else:
279279
self._colormap = colormap
280280
self.set_handles_values(colormap.colorStops())
@@ -302,7 +302,7 @@ def __init__(
302302
self.multi_range_hslider.sliderReleased.connect(self.release_handle)
303303
self.customContextMenuRequested.connect(self.open_slider_menu)
304304

305-
def set_colormap(self, colormap: CustomQwtLinearColormap) -> None:
305+
def set_colormap(self, colormap: EditableColormap) -> None:
306306
"""Replaces the current colormap.
307307
308308
Args:
@@ -313,7 +313,7 @@ def set_colormap(self, colormap: CustomQwtLinearColormap) -> None:
313313
self.set_handles_values(new_values)
314314
self.COLORMAP_CHANGED.emit()
315315

316-
def get_colormap(self) -> CustomQwtLinearColormap:
316+
def get_colormap(self) -> EditableColormap:
317317
"""Get the current colormap being edited.
318318
319319
Returns:

0 commit comments

Comments
 (0)