Skip to content

Commit ae0cd87

Browse files
committed
Colormap manager dialog: added "Apply" button
1 parent 412bf0a commit ae0cd87

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

plotpy/tools/image.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def activate_command(self, plot: BasePlot, checked: bool) -> None:
484484
manager = ColorMapManager(
485485
plot.parent(), active_colormap=self._active_colormap.name
486486
)
487+
manager.SIG_APPLY_COLORMAP.connect(self.update_plot)
487488
if exec_dialog(manager) and (cmap := manager.get_colormap()) is not None:
488489
self.activate_cmap(cmap)
489490

@@ -500,15 +501,24 @@ def activate_cmap(self, cmap: str | EditableColormap) -> None:
500501
self._active_colormap = cmap
501502
plot: BasePlot = self.get_active_plot()
502503
if self._active_colormap is not None and plot is not None:
503-
items = get_selected_images(plot, IColormapImageItemType)
504-
for item in items:
505-
param: BaseImageParam = item.param
506-
param.colormap = self._active_colormap.name
507-
param.update_item(item)
508-
plot.SIG_ITEM_PARAMETERS_CHANGED.emit(item)
509-
plot.invalidate()
504+
self.update_plot(self._active_colormap.name)
510505
self.update_status(plot)
511506

507+
def update_plot(self, cmap: str) -> None:
508+
"""Update the plot with the given colormap.
509+
510+
Args:
511+
cmap: Colormap name
512+
"""
513+
plot: BasePlot = self.get_active_plot()
514+
items = get_selected_images(plot, IColormapImageItemType)
515+
for item in items:
516+
param: BaseImageParam = item.param
517+
param.colormap = cmap
518+
param.update_item(item)
519+
plot.SIG_ITEM_PARAMETERS_CHANGED.emit(item)
520+
plot.invalidate()
521+
512522
def update_status(self, plot: BasePlot) -> None:
513523
"""Update tool status if the plot type is not PlotType.CURVE.
514524

plotpy/widgets/colormap/manager.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class ColorMapManager(QW.QDialog):
133133
that the colormap cannot be removed.
134134
"""
135135

136+
SIG_APPLY_COLORMAP = QC.Signal(str)
137+
136138
def __init__(
137139
self,
138140
parent: QW.QWidget | None = None,
@@ -196,13 +198,16 @@ def __init__(
196198
self._cmap_choice.currentIndexChanged.connect(self.set_colormap)
197199

198200
self.bbox = QW.QDialogButtonBox(
199-
QW.QDialogButtonBox.Save
201+
QW.QDialogButtonBox.Apply
202+
| QW.QDialogButtonBox.Save
200203
| QW.QDialogButtonBox.Ok
201204
| QW.QDialogButtonBox.Cancel
202205
)
203206
self._changes_saved = True
204207
self._save_btn = self.bbox.button(QW.QDialogButtonBox.Save)
205208
self._save_btn.setEnabled(False) # type: ignore
209+
self._apply_btn = self.bbox.button(QW.QDialogButtonBox.Apply)
210+
self._apply_btn.setEnabled(False) # type: ignore
206211
self.bbox.clicked.connect(self.button_clicked)
207212

208213
dialog_layout = QW.QVBoxLayout()
@@ -220,7 +225,12 @@ def button_clicked(self, button: QW.QAbstractButton) -> None:
220225
Args:
221226
button: button clicked
222227
"""
223-
if button is self._save_btn:
228+
if button is self._apply_btn:
229+
if not self.current_changes_saved and not self.save_colormap():
230+
return
231+
self._apply_btn.setEnabled(False)
232+
self.SIG_APPLY_COLORMAP.emit(self.colormap_editor.get_colormap().name)
233+
elif button is self._save_btn:
224234
self.save_colormap()
225235
elif self.bbox.buttonRole(button) == QW.QDialogButtonBox.AcceptRole:
226236
self.accept()
@@ -231,6 +241,7 @@ def _changes_not_saved(self) -> None:
231241
"""Callback function to be called when the colormap is modified. Enables the
232242
save button and sets the current_changes_saved attribute to False."""
233243
self._save_btn.setEnabled(True) # type: ignore
244+
self._apply_btn.setEnabled(True) # type: ignore
234245
self._changes_saved = False
235246

236247
@property

0 commit comments

Comments
 (0)