From d8edb273c9323490388865271107afd6dda7cc49 Mon Sep 17 00:00:00 2001 From: RomainFT Date: Thu, 23 Feb 2023 23:21:18 +0100 Subject: [PATCH] explicit the distinction between "not ALLOWING" & "not SUPPORTING" alpha --- debian/changelog | 1 + src/preferences.py | 10 ++-------- src/saving_manager.py | 30 ++++++++++++++++++++---------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7da603fa..fc0505ce 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ drawing (1.0.2) unstable; urgency=low * fix the default value of the text background option (as reported by #521 and #559) * fix a scenario where saving without transparency would consistenly fail + * automatically reload the picture after saving * mitigate initial state of the "filters" tool if "blur" is selected (#577) * change the keyboard shortcuts to switch tabs * remove from the highlighter the (ineffective) UI to change the active cairo operator diff --git a/src/preferences.py b/src/preferences.py index 4d9a8db1..1cefe58c 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -100,21 +100,15 @@ def page_builder_images(self): " " + _("If you save your images in these formats, what " + \ "do want to use to replace transparent pixels?")) alpha_dict = { - # Context: this is the label that describes the initial color of an - # image (as set in the preferences or in the "new image with custom - # size" dialog). This is displayed in the context of editing or - # saving the image, but not when creating it. 'initial': _("Default color"), 'white': _("White"), 'black': _("Black"), - # Context: replace transparent pixels with [checkboard]. This is a - # pattern of dark and light greys. 'checkboard': _("Checkboard"), - # Context: replace transparent pixels with [nothing]. In practice it - # means the alpha channel is just removed. 'nothing': _("Nothing"), 'ask': _("Ask before saving") } + # 'nothing' is intentionally removed from this dict, because it would + # make the 'save_alphaless' action ineffective on PNG files. self.add_radio_flowbox('replace-alpha', alpha_dict) self.add_section_separator() diff --git a/src/saving_manager.py b/src/saving_manager.py index 8e8974df..368a123f 100644 --- a/src/saving_manager.py +++ b/src/saving_manager.py @@ -31,7 +31,9 @@ def __init__(self, window): self._window = window def save_current_image(self, is_export, to_new, selection_only, allow_alpha): - """All parameters are booleans. Returns a boolean (true if success).""" + """All parameters are booleans. The value of `allow_alpha` reflects the + user's intention (action they activated), not a technical capability. + It returns a boolean (true if success).""" if not selection_only and not self._confirm_despite_ongoing_operation(): return False @@ -65,14 +67,12 @@ def save_current_image(self, is_export, to_new, selection_only, allow_alpha): # the file chooser dialog allows any format can_save_as = not is_export - if file_format not in ['png']: - allow_alpha = False - - if not allow_alpha: + supports_alpha = file_format in ['png'] + if not allow_alpha or not supports_alpha: try: replacement = self._window.gsettings.get_string('replace-alpha') if replacement == 'ask': - replacement = self._ask_overwrite_alpha(allow_alpha, can_save_as) + replacement = self._ask_overwrite_alpha(supports_alpha, can_save_as) pixbuf = self._replace_alpha(pixbuf, replacement, image) except WantAnotherFormatException as e: # the user wants to save the file under an other format @@ -260,10 +260,10 @@ def _get_format(self, file_path): file_format = 'png' return file_format - def _ask_overwrite_alpha(self, allow_alpha, can_save_as): + def _ask_overwrite_alpha(self, supports_alpha, can_save_as): """Warn the user about the replacement of the alpha channel for JPG or BMP files, but it may quickly annoy users to see a dialog so it's an - option. Can be used on PNG files if 'allow_alpha' is false.""" + option. Can be used on PNG files (if 'supports_alpha' is true).""" dialog = DrMessageDialog(self._window) cancel_id = dialog.set_action(_("Cancel"), None) if can_save_as: @@ -273,7 +273,7 @@ def _ask_overwrite_alpha(self, allow_alpha, can_save_as): # Context: confirm replacing transparent pixels with the selected color replace_id = dialog.set_action(_("Replace"), None, True) - if allow_alpha: + if not supports_alpha: dialog.add_string(_("This file format doesn't support transparent colors.")) if can_save_as: dialog.add_string(_("You can save the image as a PNG file, or " \ @@ -282,11 +282,20 @@ def _ask_overwrite_alpha(self, allow_alpha, can_save_as): dialog.add_string(_("Replace transparency with:")) alpha_combobox = Gtk.ComboBoxText(halign=Gtk.Align.CENTER) + # Context: this is the label that describes the initial color of an + # image (as set in the preferences or in the "new image with custom + # size" dialog). This is displayed in the context of editing or saving + # the image, but not when creating it. alpha_combobox.append('initial', _("Default color")) alpha_combobox.append('white', _("White")) alpha_combobox.append('black', _("Black")) + # Context: replace transparent pixels with [checkboard]. This is a + # pattern of dark and light greys. alpha_combobox.append('checkboard', _("Checkboard")) - alpha_combobox.append('nothing', _("Nothing")) + if not supports_alpha: + # Context: replace transparent pixels with [nothing]. In practice it + # means the alpha channel is just removed. + alpha_combobox.append('nothing', _("Nothing")) alpha_combobox.set_active_id('initial') # If we run the dialog, it often # means the active preference is 'ask', so there is no way we can set # the default value to something more pertinent. @@ -303,6 +312,7 @@ def _ask_overwrite_alpha(self, allow_alpha, can_save_as): def _replace_alpha(self, pixbuf, replacement, image): if replacement == 'nothing': + # wouldn't work with a PNG file return pixbuf width = pixbuf.get_width() height = pixbuf.get_height()