Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 433:aa204c813f07
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 01 Mar 2020 22:11:25 +0100 |
parents | 36c3f1c02d33 |
children | 53bb3886b408 |
comparison
equal
deleted
inserted
replaced
432:36c3f1c02d33 | 433:aa204c813f07 |
---|---|
126 | 126 |
127 class AttachmentImageItem(ButtonBehavior, BaseAttachmentItem): | 127 class AttachmentImageItem(ButtonBehavior, BaseAttachmentItem): |
128 image = properties.ObjectProperty() | 128 image = properties.ObjectProperty() |
129 | 129 |
130 def on_press(self): | 130 def on_press(self): |
131 gallery = ImagesGallery(sources=[self.image.source]) | 131 full_size_source = self.data.get('path', self.data.get('url')) |
132 gallery = ImagesGallery(sources=[full_size_source]) | |
132 G.host.showExtraUI(gallery) | 133 G.host.showExtraUI(gallery) |
133 | 134 |
134 | 135 |
135 class AttachmentImagesCollectionItem(ButtonBehavior, GridLayout): | 136 class AttachmentImagesCollectionItem(ButtonBehavior, GridLayout): |
136 attachments = properties.ListProperty([]) | 137 attachments = properties.ListProperty([]) |
137 chat = properties.ObjectProperty() | 138 chat = properties.ObjectProperty() |
138 mess_data = properties.ObjectProperty() | 139 mess_data = properties.ObjectProperty() |
139 | 140 |
141 def _setPreview(self, attachment, wid, preview_path): | |
142 attachment['preview'] = preview_path | |
143 wid.source = preview_path | |
144 | |
140 def _setDecryptedPath(self, attachment, wid, path): | 145 def _setDecryptedPath(self, attachment, wid, path): |
141 attachment['path'] = path | 146 attachment['path'] = path |
142 if wid is not None: | 147 if wid is not None: |
143 wid.source = path | 148 # we also need a preview for the widget |
149 if 'preview' in attachment: | |
150 wid.source = attachment['preview'] | |
151 else: | |
152 G.host.bridge.imageGeneratePreview( | |
153 path, | |
154 self.chat.profile, | |
155 callback=partial(self._setPreview, attachment, wid), | |
156 ) | |
144 | 157 |
145 def on_kv_post(self, __): | 158 def on_kv_post(self, __): |
146 attachments = self.attachments | 159 attachments = self.attachments |
147 self.clear_widgets() | 160 self.clear_widgets() |
148 for idx, attachment in enumerate(attachments): | 161 for idx, attachment in enumerate(attachments): |
185 self.add_widget(counter) | 198 self.add_widget(counter) |
186 | 199 |
187 def on_press(self): | 200 def on_press(self): |
188 sources = [] | 201 sources = [] |
189 for attachment in self.attachments: | 202 for attachment in self.attachments: |
190 source = attachment.get('url', attachment.get('path')) | 203 source = attachment.get('path', attachment.get('url')) |
191 if not source: | 204 if not source: |
192 log.warning(f"no source for {attachment}") | 205 log.warning(f"no source for {attachment}") |
193 else: | 206 else: |
194 sources.append(source) | 207 sources.append(source) |
195 gallery = ImagesGallery(sources=sources) | 208 gallery = ImagesGallery(sources=sources) |