diff --git a/src/gourmet/reccard.py b/src/gourmet/reccard.py index 18fb5c68..3ddf0010 100644 --- a/src/gourmet/reccard.py +++ b/src/gourmet/reccard.py @@ -3,7 +3,7 @@ import webbrowser import xml.sax.saxutils from pkgutil import get_data -from typing import Any, Callable, Dict, List, Optional, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple, Union from gi.repository import Gdk, GdkPixbuf, GLib, GObject, Gtk, Pango from PIL import Image @@ -1459,17 +1459,20 @@ def save(self, recdic): self.emit('saved') return recdic -class ImageBox: # used in DescriptionEditor for recipe image. - def __init__ (self, RecCard): + +class ImageBox: + """A widget for handling images in the DescriptionEditor.""" + def __init__(self, rec_card): debug("__init__ (self, RecCard):",5) self.edited = False - self.rg = RecCard.rg - self.rc = RecCard - self.ui = self.rc.ui + self.rc = rec_card + self.rg = rec_card.rg + self.ui = rec_card.ui self.imageW = self.ui.get_object('recImage') self.addW = self.ui.get_object('addImage') self.delW = self.ui.get_object('delImageButton') self.image: Image.Image = None + self.thumbnail: Image.Image = None def get_image(self, rec: Optional['RowProxy'] = None): """Set image based on current recipe.""" @@ -1506,12 +1509,12 @@ def hide (self): self.addW.show() return True - def commit(self) -> Optional[Tuple[bytes, bytes]]: + def commit(self) -> Union[Tuple[bytes, bytes], Tuple[None, None]]: """Return image and thumbnail data for storage in the database.""" debug("commit (self):", 5) if self.image: self.imageW.show() - return iu.image_to_bytes(self.image), iu.image_to_bytes(self.thumb) + return iu.image_to_bytes(self.image), iu.image_to_bytes(self.thumbnail) else: self.imageW.hide() return None, None @@ -1531,8 +1534,6 @@ def draw_image(self): size = (100, 100) self.image.thumbnail(size) - self.thumb = self.image.copy() - self.thumb.thumbnail((40, 40)) self.set_from_bytes(iu.image_to_bytes(self.image)) def show_image (self): @@ -1550,6 +1551,8 @@ def set_from_bytes(self, bytes_: bytes): self.orig_pixbuf = pb self.image = iu.bytes_to_image(bytes_) + self.thumbnail = self.image.copy() + self.thumbnail.thumbnail((40, 40)) self.show_image() self.edited = True