mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 22:31:43 +03:00
Refactor format disabling
- confirm_information_loss and encode_to_format no longer need syncing - other formats can be disabled easily
This commit is contained in:
parent
d886e31930
commit
6c51b8fba0
@ -46,6 +46,11 @@ from .__init__ import __version__
|
||||
MAX_FILE_SIZE = 500000 # 500 KB
|
||||
DEBUG_SVG_LOADING = False # writes debug.svg when flexible character grid loader is used
|
||||
|
||||
# JPEG is disabled because of low quality.
|
||||
# On the scale of images you're able to (performantly) edit in this app (currently),
|
||||
# JPEG is not a good choice.
|
||||
SAVE_DISABLED_FORMATS = ["JPEG"]
|
||||
|
||||
# These can go away now that args are parsed up top
|
||||
ascii_only_icons = False
|
||||
inspect_layout = False
|
||||
@ -787,13 +792,7 @@ class AnsiArtDocument:
|
||||
return self.get_plain().encode("utf-8")
|
||||
elif format_id == "RICH_CONSOLE_MARKUP":
|
||||
return self.get_rich_console_markup().encode("utf-8")
|
||||
elif format_id == "JPEG":
|
||||
# Disabled because of low quality.
|
||||
# On the scale of images you're able to (performantly) edit in this app (currently),
|
||||
# JPEG is not a good choice.
|
||||
# Note: if ever re-enabling this, make sure to re-enable warning in confirm_information_loss.
|
||||
raise FormatWriteNotSupported(localized_message=_("Cannot write files in %1 format.", format_id) + "\n\n" + _("To save your changes, use a different filename."))
|
||||
elif format_id in Image.SAVE:
|
||||
elif format_id in Image.SAVE and format_id not in SAVE_DISABLED_FORMATS:
|
||||
return self.encode_image_format(format_id)
|
||||
elif format_id is None:
|
||||
raise FormatWriteNotSupported(localized_message=_("Unknown file extension.") + "\n\n" + _("To save your changes, use a different filename."))
|
||||
@ -2866,9 +2865,8 @@ class PaintApp(App[None]):
|
||||
supports_text_and_color = format_id in ("ANSI", "SVG", "HTML", "RICH_CONSOLE_MARKUP")
|
||||
if format_id == "PLAINTEXT":
|
||||
self.confirm_lose_color_information(lambda: callback(True))
|
||||
elif format_id == "JPEG":
|
||||
# JPEG is disabled for saving because it's lossy.
|
||||
# We don't need to warn about that here, because we will show an error when attempting to encode.
|
||||
elif format_id in SAVE_DISABLED_FORMATS:
|
||||
# We will show an error when attempting to encode.
|
||||
# Any warning here would just be annoying preamble to the error.
|
||||
callback(False)
|
||||
elif supports_text_and_color:
|
||||
|
Loading…
Reference in New Issue
Block a user