Skip to content

Commit 77f7281

Browse files
committed
small bug corrections on colormap selection
1 parent 6a1cb99 commit 77f7281

4 files changed

Lines changed: 10 additions & 25 deletions

File tree

plotpy/external/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
from .sliders import (
42
QDoubleRangeSlider,
53
QDoubleSlider,
@@ -18,4 +16,4 @@
1816
"QLabeledRangeSlider",
1917
"QLabeledSlider",
2018
"QRangeSlider",
21-
]
19+
]

plotpy/items/image/base.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,6 @@ def get_color_map_name(self) -> str | None:
480480
return None
481481
return self.cmap_table.name
482482

483-
def get_color_map_key_name(self) -> str | None:
484-
"""Same as get_color_map_name, but returns the colormap name in lowercase. This
485-
is because the colormap string keys of the global colormap dictionaries are all
486-
lowercase.
487-
488-
Returns:
489-
Colormap name
490-
"""
491-
if self.cmap_table is None:
492-
return None
493-
return self.cmap_table.name.lower()
494-
495483
def set_interpolation(self, interp_mode: int, size: int | None = None) -> None:
496484
"""Set interpolation mode
497485

plotpy/mathutils/colormaps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ def get_cmap(cmap_name: str) -> CustomQwtLinearColormap:
111111
If the colormap is not found, returns the DEFAULT colormap.
112112
113113
Args:
114-
cmap_name: colormap name to search in ALL_COLORMAPS
114+
cmap_name: colormap name to search in ALL_COLORMAPS. All keys in ALL_COLORMAPS
115+
are lower case, so the given name is also lowered.
115116
116117
Returns:
117-
A CustomQwtLinearColormap instance corresponding to the given name
118+
A CustomQwtLinearColormap instance corresponding to the given name, if no
119+
colormap is found, returns the DEFAULT colormap.
118120
"""
119-
return ALL_COLORMAPS.get(cmap_name, DEFAULT)
121+
return ALL_COLORMAPS.get(cmap_name.lower(), DEFAULT)
120122

121123

122124
def get_cmap_path(config_path: str):

plotpy/tools/image.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DEFAULT_COLORMAPS,
3737
build_icon_from_cmap,
3838
build_icon_from_cmap_name,
39+
get_cmap,
3940
)
4041
from plotpy.tools.base import (
4142
CommandTool,
@@ -530,12 +531,10 @@ def activate_cmap(
530531
if isinstance(cmap, QAction):
531532
self._active_colormap = cmap.data() # type: ignore
532533
elif isinstance(cmap, str):
533-
cmap = cmap.lower()
534-
assert cmap in ALL_COLORMAPS
535-
self._active_colormap = ALL_COLORMAPS[cmap]
534+
self._active_colormap = get_cmap(cmap)
536535
elif isinstance(cmap, CustomQwtLinearColormap):
537536
self._active_colormap = cmap
538-
537+
*
539538
plot = self.get_active_plot()
540539
if self._active_colormap is not None and plot is not None:
541540
items = self.get_selected_images(plot)
@@ -560,9 +559,7 @@ def update_status(self, plot: BasePlot):
560559
cmap_name = item.get_color_map_name()
561560
if cmap_name:
562561
icon = build_icon_from_cmap_name(cmap_name)
563-
self._active_colormap = ALL_COLORMAPS.get(
564-
cmap_name.lower(), DEFAULT
565-
)
562+
self._active_colormap = get_cmap(cmap_name)
566563
else:
567564
self.action.setEnabled(False)
568565
self._active_colormap = ALL_COLORMAPS.get("jet", DEFAULT)

0 commit comments

Comments
 (0)