Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the send image resize dialog #270

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/265.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sending image resize dialog.
29 changes: 20 additions & 9 deletions d_rats/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down