From e8ab614ef9412473e3fadff7b0ed80272f457682 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Fri, 17 Aug 2012 10:00:15 -0300
Subject: [PATCH] Use the gdk window to get the depth of the preview pixmap -
SL#3804
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
This prevents harcoding the depth, and uses the one from the gdk
window. For this, the preview has to be done after the window is
realized, so the code is wrapped in the expose-event callback.
Also add a white background to the preview, otherwise artifacts appear
for previews smaller than the preview box.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
src/jarabe/journal/expandedentry.py | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index e0c603f..d0c7166 100644
a
|
b
|
class ExpandedEntry(gtk.EventBox): |
194 | 194 | return date |
195 | 195 | |
196 | 196 | def _create_preview(self): |
197 | | width = style.zoom(320) |
198 | | height = style.zoom(240) |
199 | 197 | box = gtk.EventBox() |
200 | 198 | box.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) |
201 | 199 | |
| 200 | box.connect('expose-event', self.__expose_event_cb) |
| 201 | box.connect_after('button-release-event', |
| 202 | self._preview_box_button_release_event_cb) |
| 203 | return box |
| 204 | |
| 205 | def __expose_event_cb(self, box, event): |
| 206 | width = style.zoom(320) |
| 207 | height = style.zoom(240) |
| 208 | |
202 | 209 | if len(self._metadata.get('preview', '')) > 4: |
203 | 210 | if self._metadata['preview'][1:4] == 'PNG': |
204 | 211 | preview_data = self._metadata['preview'] |
… |
… |
class ExpandedEntry(gtk.EventBox): |
214 | 221 | surface = cairo.ImageSurface.create_from_png(png_file) |
215 | 222 | png_width = surface.get_width() |
216 | 223 | png_height = surface.get_height() |
217 | | pixmap = gtk.gdk.Pixmap(None, png_width, png_height, 24) |
| 224 | gdk_window = self.get_toplevel().window |
| 225 | pixmap = gtk.gdk.Pixmap(gdk_window, png_width, png_height, -1) |
218 | 226 | cr = pixmap.cairo_create() |
| 227 | cr.set_source_rgb(1, 1, 1) |
| 228 | cr.paint() |
219 | 229 | cr.set_source_surface(surface, 0, 0) |
220 | 230 | cr.scale(width / png_width, height / png_height) |
221 | 231 | cr.paint() |
… |
… |
class ExpandedEntry(gtk.EventBox): |
230 | 240 | |
231 | 241 | if has_preview: |
232 | 242 | box.add(im) |
| 243 | im.show() |
233 | 244 | else: |
234 | 245 | label = gtk.Label() |
235 | 246 | label.set_text(_('No preview')) |
236 | 247 | label.set_size_request(width, height) |
237 | 248 | box.add(label) |
238 | | |
239 | | box.connect_after('button-release-event', |
240 | | self._preview_box_button_release_event_cb) |
241 | | return box |
| 249 | label.show() |
242 | 250 | |
243 | 251 | def _create_technical(self): |
244 | 252 | vbox = gtk.VBox() |