From 8226bae6510d5b7b792ed32e783330b94564d855 Mon Sep 17 00:00:00 2001 From: "John E. Malmberg" Date: Thu, 26 Oct 2023 08:23:39 -0500 Subject: [PATCH] Fix the send image resize dialog The GTK project removed support for older code. changes/265.bugfix: Description of this fix. d_rats/image.py: Use currently documented GTK api. --- changes/265.bugfix | 1 + d_rats/image.py | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 changes/265.bugfix diff --git a/changes/265.bugfix b/changes/265.bugfix new file mode 100644 index 0000000..7416ef5 --- /dev/null +++ b/changes/265.bugfix @@ -0,0 +1 @@ +Fix sending image resize dialog. diff --git a/d_rats/image.py b/d_rats/image.py index 82a7f0a..484212c 100755 --- a/d_rats/image.py +++ b/d_rats/image.py @@ -5,6 +5,17 @@ import logging import tempfile import os +if __name__ == "__main__": + import sys + +HAVE_PIL = False +try: + from PIL import Image + from PIL import UnidentifiedImageError + HAVE_PIL = True +except ImportError: + # This needs to be moved out of main_common + from .ui.main_common import ask_for_confirmation import gi gi.require_version("Gtk", "3.0") @@ -118,8 +129,11 @@ def update(): dialog.size = miscwidgets.make_choice(SIZES, False, SIZES[1]) dialog.size.connect("changed", lambda x: update()) dialog.add_field(_("Resize to"), dialog.size) - - quality = Gtk.HScale(Gtk.Adjustment.new(50, 1, 100, 10, 10, 0)) + adjustment = Gtk.Adjustment.new(value=50, lower=1, upper=100, + step_increment=10, page_increment=10, + page_size=0) + quality = Gtk.Scale.new(orientation=Gtk.Orientation.HORIZONTAL, + adjustment=adjustment) quality.connect("format-value", lambda s, v: "%i" % v) quality.connect("change-value", set_quality, dialog) @@ -153,12 +167,11 @@ def send_image(filename, dialog_parent=None): :returns: Path to temporary image file :rtype: str ''' - try: - from PIL import Image, UnidentifiedImageError - except ImportError: + logger = logging.getLogger("update_image") + if not HAVE_PIL: + logger.info("Python pillow library is not installed.") msg = _("No support for resizing images. Send unaltered?") - from .ui import main_common - if main_common.ask_for_confirmation(msg, dialog_parent): + if ask_for_confirmation(msg, dialog_parent): return filename return None try: @@ -185,8 +198,6 @@ def send_image(filename, dialog_parent=None): def main(): '''Main for Unit testing.''' - import sys - logging.basicConfig(format="%(asctime)s:%(levelname)s:%(name)s:%(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO)