Skip to content

Commit f7e53d2

Browse files
committed
Colormap manager: prevent active color map removal
1 parent 335af02 commit f7e53d2

4 files changed

Lines changed: 83 additions & 88 deletions

File tree

173 Bytes
Binary file not shown.

plotpy/locale/fr/LC_MESSAGES/plotpy.po

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
9-
"POT-Creation-Date: 2024-03-01 09:20+0100\n"
9+
"POT-Creation-Date: 2024-03-01 09:45+0100\n"
1010
"PO-Revision-Date: 2019-02-20 14:42+0100\n"
1111
"Last-Translator: \n"
1212
"Language-Team: \n"
@@ -401,9 +401,9 @@ msgstr "Déplacer vers le premier plan"
401401

402402
#: plotpy\panels\itemlist.py:94 plotpy\panels\itemlist.py:236
403403
#: plotpy\tools\item.py:154 plotpy\tools\item.py:179
404-
#: plotpy\widgets\colormap\manager.py:155
405-
#: plotpy\widgets\colormap\manager.py:320
406-
#: plotpy\widgets\colormap\manager.py:329
404+
#: plotpy\widgets\colormap\manager.py:166
405+
#: plotpy\widgets\colormap\manager.py:338
406+
#: plotpy\widgets\colormap\manager.py:346
407407
msgid "Remove"
408408
msgstr "Supprimer"
409409

@@ -2044,62 +2044,68 @@ msgstr ""
20442044
"Un nom de colormap ne peut pas contenir de caractères spéciauxexcepté les "
20452045
"tirets bas (_)."
20462046

2047-
#: plotpy\widgets\colormap\manager.py:134
2047+
#: plotpy\widgets\colormap\manager.py:143
20482048
msgid "Colormap manager"
20492049
msgstr "Gestionnaire de palettes de couleurs"
20502050

2051-
#: plotpy\widgets\colormap\manager.py:153
2051+
#: plotpy\widgets\colormap\manager.py:164
20522052
msgid "Add"
20532053
msgstr "Ajouter"
20542054

2055-
#: plotpy\widgets\colormap\manager.py:160
2055+
#: plotpy\widgets\colormap\manager.py:171
20562056
msgid "Select or create a colormap"
20572057
msgstr "Sélectionner ou créer une palette de couleurs"
20582058

2059-
#: plotpy\widgets\colormap\manager.py:161
2059+
#: plotpy\widgets\colormap\manager.py:172
20602060
msgid "Colormap presets:"
20612061
msgstr "Palettes de couleurs prédéfinies :"
20622062

2063-
#: plotpy\widgets\colormap\manager.py:174
2063+
#: plotpy\widgets\colormap\manager.py:185
20642064
msgid "Edit the selected colormap"
20652065
msgstr "Modifier la palette de couleurs sélectionnée"
20662066

2067-
#: plotpy\widgets\colormap\manager.py:281
2067+
#: plotpy\widgets\colormap\manager.py:291
20682068
msgid ""
2069-
"Name <b>%s</b> is already used by a default colormap, and cannot be used for "
2070-
"a custom colormap.<br><br>Please choose another name."
2069+
"Name <b>%s</b> is already used by a predefined colormap, and cannot be used "
2070+
"for a custom colormap.<br><br>Please choose another name."
20712071
msgstr ""
2072-
"Le nom <b>%s</b> est déjà utilisé par une palette de couleurs par défaut, et "
2073-
"ne peut pas être utilisé pour une palette de couleurs personnalisée."
2074-
"<br><br>Veuillez choisir un autre nom."
2072+
"Le nom <b>%s</b> est déjà utilisé par une palette de couleurs prédéfinie, et "
2073+
"ne peut pas être utilisé pour une palette personnalisée.<br><br>Veuillez "
2074+
"choisir un autre nom."
20752075

2076-
#: plotpy\widgets\colormap\manager.py:293
2076+
#: plotpy\widgets\colormap\manager.py:303
20772077
msgid ""
20782078
"Name <b>%s</b> is already used by a custom colormap.<br><br>Do you want to "
20792079
"overwrite it?"
20802080
msgstr ""
20812081
"Le nom <b>%s</b> est déjà utilisé par une palette de couleurs personnalisée."
20822082
"<br><br>Voulez-vous l'écraser ?"
20832083

2084-
#: plotpy\widgets\colormap\manager.py:309
2084+
#: plotpy\widgets\colormap\manager.py:319
20852085
msgid "New"
20862086
msgstr "Nouveau"
20872087

2088-
#: plotpy\widgets\colormap\manager.py:321
2089-
msgid "Colormap <b>%s</b> is a default colormap and cannot be deleted."
2090-
msgstr ""
2091-
"La palette de couleurs <b>%s</b> est une palette par défaut et ne peut pas "
2092-
"être supprimée."
2088+
#: plotpy\widgets\colormap\manager.py:333
2089+
msgid "Colormap <b>%s</b> is the active colormap."
2090+
msgstr "La palette de couleurs <b>%s</b> est la palette active."
2091+
2092+
#: plotpy\widgets\colormap\manager.py:335
2093+
msgid "Colormap <b>%s</b> is a predefined colormap."
2094+
msgstr "La palette de couleurs <b>%s</b> est une palette prédéfinie."
20932095

2094-
#: plotpy\widgets\colormap\manager.py:330
2096+
#: plotpy\widgets\colormap\manager.py:339
2097+
msgid "Thus, this colormap cannot be removed."
2098+
msgstr "Cette palette de couleurs ne peut donc pas être supprimée."
2099+
2100+
#: plotpy\widgets\colormap\manager.py:347
20952101
msgid "Do you want to delete colormap <b>%s</b>?"
20962102
msgstr "Souhaitez-vous supprimer la palette de couleurs <b>%s</b> ?"
20972103

2098-
#: plotpy\widgets\colormap\manager.py:356
2104+
#: plotpy\widgets\colormap\manager.py:373
20992105
msgid "Save colormap"
21002106
msgstr "Enregistrer la palette de couleurs"
21012107

2102-
#: plotpy\widgets\colormap\manager.py:358
2108+
#: plotpy\widgets\colormap\manager.py:375
21032109
msgid "Add colormap"
21042110
msgstr "Ajouter une palette de couleurs"
21052111

@@ -2264,37 +2270,3 @@ msgstr "Rotation et rognage"
22642270
#: plotpy\widgets\rotatecrop.py:219
22652271
msgid "Show cropping rectangle"
22662272
msgstr "Afficher le rectangle de rognage"
2267-
2268-
#~ msgid "Save"
2269-
#~ msgstr "Enregistrer"
2270-
2271-
#~ msgid "Delete colormap"
2272-
#~ msgstr "Supprimer la palette de couleurs"
2273-
2274-
#~ msgid "Create new colormap"
2275-
#~ msgstr "Créer une nouvelle palette de couleurs"
2276-
2277-
#~ msgid "Custom colormap %s already exists, do you want to overwrite it?"
2278-
#~ msgstr ""
2279-
#~ "La palette de couleurs personnalisée %s existe déjà, voulez-vous "
2280-
#~ "l'écraser ?"
2281-
2282-
#~ msgid ""
2283-
#~ "New colormap \"%s\" is a default colormap and cannot be overwritten. "
2284-
#~ "Change its name to save it as a custom colormap."
2285-
#~ msgstr ""
2286-
#~ "La nouvelle table des couleurs \"%s\" est une table des couleurs par "
2287-
#~ "défaut et ne peut pas être remplacée. Modifiez son nom pour l'enregistrer "
2288-
#~ "en tant que carte de couleurs personnalisée."
2289-
2290-
#~ msgid "Close"
2291-
#~ msgstr "Fermer"
2292-
2293-
#~ msgid ""
2294-
#~ "Current changes not saved. The current colormap will be discarded when "
2295-
#~ "the editor is closed.\n"
2296-
#~ "Do you want to save the changes?"
2297-
#~ msgstr ""
2298-
#~ "Les modifications actuelles ne sont pas sauvegardées. La palette de "
2299-
#~ "couleurs actuelle sera supprimée lorsque l'éditeur éditeur sera fermé.\n"
2300-
#~ "Voulez-vous enregistrer les modifications ?"

plotpy/locale/plotpy.pot

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
msgid ""
66
msgstr ""
77
"Project-Id-Version: PACKAGE VERSION\n"
8-
"POT-Creation-Date: 2024-03-01 09:20+0100\n"
8+
"POT-Creation-Date: 2024-03-01 09:45+0100\n"
99
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1010
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1111
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -378,9 +378,9 @@ msgstr ""
378378

379379
#: plotpy\panels\itemlist.py:94 plotpy\panels\itemlist.py:236
380380
#: plotpy\tools\item.py:154 plotpy\tools\item.py:179
381-
#: plotpy\widgets\colormap\manager.py:155
382-
#: plotpy\widgets\colormap\manager.py:320
383-
#: plotpy\widgets\colormap\manager.py:329
381+
#: plotpy\widgets\colormap\manager.py:166
382+
#: plotpy\widgets\colormap\manager.py:338
383+
#: plotpy\widgets\colormap\manager.py:346
384384
msgid "Remove"
385385
msgstr ""
386386

@@ -1981,51 +1981,59 @@ msgstr ""
19811981
msgid "New colormap name cannot contain special characters except underscores (_)."
19821982
msgstr ""
19831983

1984-
#: plotpy\widgets\colormap\manager.py:134
1984+
#: plotpy\widgets\colormap\manager.py:143
19851985
msgid "Colormap manager"
19861986
msgstr ""
19871987

1988-
#: plotpy\widgets\colormap\manager.py:153
1988+
#: plotpy\widgets\colormap\manager.py:164
19891989
msgid "Add"
19901990
msgstr ""
19911991

1992-
#: plotpy\widgets\colormap\manager.py:160
1992+
#: plotpy\widgets\colormap\manager.py:171
19931993
msgid "Select or create a colormap"
19941994
msgstr ""
19951995

1996-
#: plotpy\widgets\colormap\manager.py:161
1996+
#: plotpy\widgets\colormap\manager.py:172
19971997
msgid "Colormap presets:"
19981998
msgstr ""
19991999

2000-
#: plotpy\widgets\colormap\manager.py:174
2000+
#: plotpy\widgets\colormap\manager.py:185
20012001
msgid "Edit the selected colormap"
20022002
msgstr ""
20032003

2004-
#: plotpy\widgets\colormap\manager.py:281
2005-
msgid "Name <b>%s</b> is already used by a default colormap, and cannot be used for a custom colormap.<br><br>Please choose another name."
2004+
#: plotpy\widgets\colormap\manager.py:291
2005+
msgid "Name <b>%s</b> is already used by a predefined colormap, and cannot be used for a custom colormap.<br><br>Please choose another name."
20062006
msgstr ""
20072007

2008-
#: plotpy\widgets\colormap\manager.py:293
2008+
#: plotpy\widgets\colormap\manager.py:303
20092009
msgid "Name <b>%s</b> is already used by a custom colormap.<br><br>Do you want to overwrite it?"
20102010
msgstr ""
20112011

2012-
#: plotpy\widgets\colormap\manager.py:309
2012+
#: plotpy\widgets\colormap\manager.py:319
20132013
msgid "New"
20142014
msgstr ""
20152015

2016-
#: plotpy\widgets\colormap\manager.py:321
2017-
msgid "Colormap <b>%s</b> is a default colormap and cannot be deleted."
2016+
#: plotpy\widgets\colormap\manager.py:333
2017+
msgid "Colormap <b>%s</b> is the active colormap."
20182018
msgstr ""
20192019

2020-
#: plotpy\widgets\colormap\manager.py:330
2020+
#: plotpy\widgets\colormap\manager.py:335
2021+
msgid "Colormap <b>%s</b> is a predefined colormap."
2022+
msgstr ""
2023+
2024+
#: plotpy\widgets\colormap\manager.py:339
2025+
msgid "Thus, this colormap cannot be removed."
2026+
msgstr ""
2027+
2028+
#: plotpy\widgets\colormap\manager.py:347
20212029
msgid "Do you want to delete colormap <b>%s</b>?"
20222030
msgstr ""
20232031

2024-
#: plotpy\widgets\colormap\manager.py:356
2032+
#: plotpy\widgets\colormap\manager.py:373
20252033
msgid "Save colormap"
20262034
msgstr ""
20272035

2028-
#: plotpy\widgets\colormap\manager.py:358
2036+
#: plotpy\widgets\colormap\manager.py:375
20292037
msgid "Add colormap"
20302038
msgstr ""
20312039

plotpy/widgets/colormap/manager.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,17 @@ class ColorMapManager(QW.QDialog):
120120
121121
Args:
122122
parent: parent QWidget. Defaults to None.
123-
active_colormap: name of the default colormap selected. If None or does not
124-
*exists, will defaults to the first colormap in the list. Defaults to None
123+
active_colormap: name of the active colormap.
124+
125+
.. note::
126+
127+
The active colormap is the colormap that will be selected by default when the
128+
dialog box is opened. If the colormap does not exist (or if None is provided),
129+
the first colormap in the list will be selected by default.
130+
131+
The active colormap cannot be removed. If the active colormap is a custom
132+
colormap, the remove button will be enabled but a dialog box will warn the user
133+
that the colormap cannot be removed.
125134
"""
126135

127136
def __init__(
@@ -133,10 +142,12 @@ def __init__(
133142
self.setWindowIcon(get_icon("cmap_edit.png"))
134143
self.setWindowTitle(_("Colormap manager"))
135144

145+
self.active_cmap_name = default_colormap = active_colormap
146+
136147
self.__returned_colormap: EditableColormap | None = None
137148

138-
if active_colormap is None or not cmap_exists(active_colormap, ALL_COLORMAPS):
139-
active_colormap = next(iter(ALL_COLORMAPS))
149+
if default_colormap is None or not cmap_exists(default_colormap, ALL_COLORMAPS):
150+
default_colormap = next(iter(ALL_COLORMAPS))
140151

141152
# Select the active colormap
142153
self._cmap_choice = QW.QComboBox()
@@ -148,12 +159,12 @@ def __init__(
148159
self._cmap_choice.addItem(icon, cmap.name, cmap)
149160

150161
self._cmap_choice.setIconSize(QC.QSize(LARGE_ICON_WIDTH, LARGE_ICON_HEIGHT))
151-
self._cmap_choice.setCurrentText(active_colormap)
162+
self._cmap_choice.setCurrentText(default_colormap)
152163

153164
add_btn = QW.QPushButton(get_icon("edit_add.png"), _("Add") + "...")
154165
add_btn.clicked.connect(self.add_colormap)
155166
self._remove_btn = QW.QPushButton(get_icon("delete.png"), _("Remove") + "...")
156-
is_custom_cmap = cmap_exists(active_colormap, CUSTOM_COLORMAPS)
167+
is_custom_cmap = cmap_exists(default_colormap, CUSTOM_COLORMAPS)
157168
self._remove_btn.setEnabled(is_custom_cmap)
158169
self._remove_btn.clicked.connect(self.remove_colormap)
159170

@@ -278,7 +289,7 @@ def __get_new_colormap_name(self, title: str, name: str) -> str | None:
278289
self,
279290
title,
280291
_(
281-
"Name <b>%s</b> is already used by a default colormap, and "
292+
"Name <b>%s</b> is already used by a predefined colormap, and "
282293
"cannot be used for a custom colormap.<br><br>"
283294
"Please choose another name."
284295
)
@@ -317,20 +328,24 @@ def remove_colormap(self) -> None:
317328
cmap = self.colormap_editor.get_colormap()
318329
if cmap is None:
319330
return
320-
if cmap_exists(cmap.name, DEFAULT_COLORMAPS):
331+
name = cmap.name
332+
if name == self.active_cmap_name or cmap_exists(name, DEFAULT_COLORMAPS):
333+
if name == self.active_cmap_name:
334+
msg = _("Colormap <b>%s</b> is the active colormap.")
335+
else:
336+
msg = _("Colormap <b>%s</b> is a predefined colormap.")
321337
QW.QMessageBox.warning(
322338
self,
323339
_("Remove"),
324-
_("Colormap <b>%s</b> is a default colormap and cannot be deleted.")
325-
% cmap.name,
340+
msg % name + "<br>" + _("Thus, this colormap cannot be removed."),
326341
QW.QMessageBox.Ok,
327342
)
328343
return
329344
if (
330345
QW.QMessageBox.question(
331346
self,
332347
_("Remove"),
333-
_("Do you want to delete colormap <b>%s</b>?") % cmap.name,
348+
_("Do you want to delete colormap <b>%s</b>?") % name,
334349
QW.QMessageBox.Yes | QW.QMessageBox.No,
335350
QW.QMessageBox.No,
336351
)

0 commit comments

Comments
 (0)