Skip to content

Commit

Permalink
Create ImageBox thumbnail when initializing self.image
Browse files Browse the repository at this point in the history
  • Loading branch information
cydanil committed Jul 4, 2021
1 parent bc5b546 commit 387d313
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/gourmet/reccard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,7 @@ def __init__(self, rec_card):
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."""
Expand Down Expand Up @@ -1513,7 +1514,7 @@ def commit(self) -> Union[Tuple[bytes, bytes], Tuple[None, None]]:
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
Expand All @@ -1533,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):
Expand All @@ -1552,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
Expand Down

0 comments on commit 387d313

Please sign in to comment.