Skip to content

Commit 738af55

Browse files
committed
Removed unnecessary BaseImageItem.get_color_map_name method
1 parent 217fca2 commit 738af55

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Changes:
1414
* `ImageIOHandler`: removed `add_change_path` and `adapt_path` methods
1515
* Fix typo in `tests.features.test_colormap_editor` module: renamed function
1616
`test_colormap_manager` to `test_colormap_editor`
17+
* Removed unnecessary `BaseImageItem.get_color_map_name` method
1718

1819
## Version 2.2.0 ##
1920

plotpy/items/image/base.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -473,19 +473,6 @@ def get_color_map(self) -> EditableColormap | None:
473473
"""
474474
return self.cmap_table
475475

476-
def get_color_map_name(self) -> str | None:
477-
"""Get the current colormap name if set. The output value should not directly
478-
be used to retrieve a colormap object from one of the global colormap
479-
dictionaries, as the colormap name may contain capital letters whereas the
480-
colormap string keys of the dictionaries are all lowercase.
481-
482-
Returns:
483-
Colormap name
484-
"""
485-
if self.cmap_table is None:
486-
return None
487-
return self.cmap_table.name
488-
489476
def set_interpolation(self, interp_mode: int, size: int | None = None) -> None:
490477
"""Set interpolation mode
491478

plotpy/styles/image.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
if TYPE_CHECKING:
3636
from guidata.dataset import DataSet
3737

38+
from plotpy.items import BaseImageItem
39+
from plotpy.plot import BasePlot
40+
3841

3942
def _create_choices(
4043
dataset: DataSet, item: ImageChoiceItem, value: Any
@@ -102,13 +105,16 @@ class BaseImageParam(DataSet):
102105
zformat = StringItem(_("Z-Axis"), default=r"%.1f")
103106
_end_formats = EndGroup(_("Statistics string formatting"))
104107

105-
def update_param(self, image):
106-
"""
108+
def update_param(self, image: BaseImageItem) -> None:
109+
"""Update the parameters from the given image item.
107110
108-
:param image:
111+
Args:
112+
image: The image item to update the parameters from.
109113
"""
110114
self.label = str(image.title().text())
111-
self.colormap = image.get_color_map_name()
115+
cmap = image.get_color_map()
116+
if cmap is not None:
117+
self.colormap = cmap.name
112118
interpolation = image.get_interpolation()
113119
mode = interpolation[0]
114120

@@ -120,14 +126,15 @@ def update_param(self, image):
120126
size = interpolation[1].shape[0]
121127
self.interpolation = size
122128

123-
def update_item(self, image):
124-
"""
129+
def update_item(self, image: BaseImageItem) -> None:
130+
"""Update the given image item from the parameters.
125131
126-
:param image:
132+
Args:
133+
image: The image item to update.
127134
"""
128135
if isinstance(self.alpha_function, LUTAlpha):
129136
self.alpha_function = self.alpha_function.value
130-
plot = image.plot()
137+
plot: BasePlot = image.plot()
131138
if plot is not None:
132139
plot.blockSignals(True) # Avoid unwanted calls of update_param
133140
# triggered by the setter methods below
@@ -192,23 +199,27 @@ class QuadGridParam(DataSet):
192199
grid = BoolItem(_("Show grid"), default=False)
193200
gridcolor = ColorItem(_("Grid lines color"), default="black")
194201

195-
def update_param(self, image):
196-
"""
202+
def update_param(self, image: BaseImageItem) -> None:
203+
"""Update the parameters from the given image item.
197204
198-
:param image:
205+
Args:
206+
image: The image item to update the parameters from.
199207
"""
200208
self.label = str(image.title().text())
201-
self.colormap = image.get_color_map_name()
209+
cmap = image.get_color_map()
210+
if cmap is not None:
211+
self.colormap = cmap.name
202212
interp, uflat, vflat = image.interpolate
203213
self.interpolation = interp
204214
self.uflat = uflat
205215
self.vflat = vflat
206216
self.grid = image.grid
207217

208-
def update_item(self, image):
209-
"""
218+
def update_item(self, image: BaseImageItem) -> None:
219+
"""Update the given image item from the parameters.
210220
211-
:param image:
221+
Args:
222+
image: The image item to update.
212223
"""
213224
if isinstance(self.alpha_function, LUTAlpha):
214225
self.alpha_function = self.alpha_function.value

plotpy/tests/unit/test_plot_image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ def test_colormap_tool():
132132

133133
# default color map should be "jet"
134134
color_map_tool = win.manager.get_tool(ColormapTool)
135-
assert item.get_color_map_name() == "jet"
135+
cmap = item.get_color_map()
136+
assert cmap.name == "jet"
136137
jet_img = plot.grab().toImage()
137138

138139
# change the colormap
139140
plot.select_item(item)
140141
cmap_name = "accent"
141142
color_map_tool.activate_cmap(cmap_name)
142-
assert item.get_color_map_name() == cmap_name
143+
cmap = item.get_color_map()
144+
assert cmap.name == cmap_name
143145
accent_img = plot.grab().toImage()
144146
assert jet_img != accent_img
145147

plotpy/tools/image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,14 @@ def update_status(self, plot: BasePlot) -> None:
517517
plot: Plot Instance
518518
"""
519519
if update_image_tool_status(self, plot):
520-
item = plot.get_last_active_item(IColormapImageItemType)
520+
item: BaseImageItem = plot.get_last_active_item(IColormapImageItemType)
521521
icon = self.default_icon
522522
if item:
523523
self.action.setEnabled(True)
524-
cmap_name = item.get_color_map_name()
525-
if cmap_name:
526-
icon = build_icon_from_cmap_name(cmap_name)
527-
self._active_colormap = get_cmap(cmap_name)
524+
cmap = item.get_color_map()
525+
if cmap is not None:
526+
icon = build_icon_from_cmap_name(cmap.name)
527+
self._active_colormap = get_cmap(cmap.name)
528528
else:
529529
self.action.setEnabled(False)
530530
self._active_colormap = ALL_COLORMAPS["jet"]

0 commit comments

Comments
 (0)