Ticket #3804: 0001-Use-the-gdk-window-to-get-the-depth-of-the-preview-p.patch

File 0001-Use-the-gdk-window-to-get-the-depth-of-the-preview-p.patch, 3.0 KB (added by manuq, 12 years ago)

New version that fixes artifacts painting the background white.

  • src/jarabe/journal/expandedentry.py

    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): 
    194194        return date
    195195
    196196    def _create_preview(self):
    197         width = style.zoom(320)
    198         height = style.zoom(240)
    199197        box = gtk.EventBox()
    200198        box.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color())
    201199
     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
    202209        if len(self._metadata.get('preview', '')) > 4:
    203210            if self._metadata['preview'][1:4] == 'PNG':
    204211                preview_data = self._metadata['preview']
    class ExpandedEntry(gtk.EventBox): 
    214221                surface = cairo.ImageSurface.create_from_png(png_file)
    215222                png_width = surface.get_width()
    216223                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)
    218226                cr = pixmap.cairo_create()
     227                cr.set_source_rgb(1, 1, 1)
     228                cr.paint()
    219229                cr.set_source_surface(surface, 0, 0)
    220230                cr.scale(width / png_width, height / png_height)
    221231                cr.paint()
    class ExpandedEntry(gtk.EventBox): 
    230240
    231241        if has_preview:
    232242            box.add(im)
     243            im.show()
    233244        else:
    234245            label = gtk.Label()
    235246            label.set_text(_('No preview'))
    236247            label.set_size_request(width, height)
    237248            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()
    242250
    243251    def _create_technical(self):
    244252        vbox = gtk.VBox()