# HG changeset patch # User Goffi # Date 1583097085 -3600 # Node ID aa204c813f071d0909921621d74529a08da82aba # Parent 36c3f1c02d334d20cbba255f8bc88644489dadca chat: attachment preview: - if there is not already one, a preview is generated for images collection thumbnails, instead of using the full size image. - for images attachment, local path is now used if present, before URL. diff -r 36c3f1c02d33 -r aa204c813f07 cagou/core/image.py --- a/cagou/core/image.py Sun Mar 01 22:11:25 2020 +0100 +++ b/cagou/core/image.py Sun Mar 01 22:11:25 2020 +0100 @@ -47,7 +47,7 @@ anim_delay=self.anim_delay, keep_data=self.keep_data, nocache=self.nocache) - except Exception as e: + except Exception: # loading failed probably because of unmanaged extention, # we try our luck with with PIL try: diff -r 36c3f1c02d33 -r aa204c813f07 cagou/plugins/plugin_wid_chat.kv --- a/cagou/plugins/plugin_wid_chat.kv Sun Mar 01 22:11:25 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.kv Sun Mar 01 22:11:25 2020 +0100 @@ -63,7 +63,7 @@ orientation: "vertical" SizedImage: id: image - source: root.data.get('url', root.data.get('path')) + source: root.data.get('preview') or root.data.get('path') or root.data.get('url') anim_delay: -1 diff -r 36c3f1c02d33 -r aa204c813f07 cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Sun Mar 01 22:11:25 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Sun Mar 01 22:11:25 2020 +0100 @@ -128,7 +128,8 @@ image = properties.ObjectProperty() def on_press(self): - gallery = ImagesGallery(sources=[self.image.source]) + full_size_source = self.data.get('path', self.data.get('url')) + gallery = ImagesGallery(sources=[full_size_source]) G.host.showExtraUI(gallery) @@ -137,10 +138,22 @@ chat = properties.ObjectProperty() mess_data = properties.ObjectProperty() + def _setPreview(self, attachment, wid, preview_path): + attachment['preview'] = preview_path + wid.source = preview_path + def _setDecryptedPath(self, attachment, wid, path): attachment['path'] = path if wid is not None: - wid.source = path + # we also need a preview for the widget + if 'preview' in attachment: + wid.source = attachment['preview'] + else: + G.host.bridge.imageGeneratePreview( + path, + self.chat.profile, + callback=partial(self._setPreview, attachment, wid), + ) def on_kv_post(self, __): attachments = self.attachments @@ -187,7 +200,7 @@ def on_press(self): sources = [] for attachment in self.attachments: - source = attachment.get('url', attachment.get('path')) + source = attachment.get('path', attachment.get('url')) if not source: log.warning(f"no source for {attachment}") else: