Ticket #4418: 0001-Allow-to-open-multiple-mimetype-SL-4418.patch

File 0001-Allow-to-open-multiple-mimetype-SL-4418.patch, 2.1 KB (added by humitos, 11 years ago)
  • Area.py

    From add84fc698e82154bd3939efc06d2ac3c46abb20 Mon Sep 17 00:00:00 2001
    From: Manuel Kaufmann <humitos@gmail.com>
    Date: Fri, 15 Feb 2013 09:43:17 -0300
    Subject: [PATCH Paint] Allow to open multiple mimetype SL #4418
    
    Use 'GdkPixbuf.Pixbuf.new_from_file' when the image file is not
    PNG. This allows the user to open many different kinds of file with
    Pain Activity, including clipping images from the Clipboard.
    
    Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
    ---
     Area.py | 16 +++++++++++++---
     1 file changed, 13 insertions(+), 3 deletions(-)
    
    diff --git a/Area.py b/Area.py
    index e42be83..2ec5946 100644
    a b class Area(Gtk.DrawingArea): 
    241241        return style.zoom(44)
    242242
    243243    def load_from_file(self, file_path):
    244         self.drawing_canvas_data = \
     244        try:
     245            self.drawing_canvas_data = \
    245246                cairo.ImageSurface.create_from_png(file_path)
     247        except MemoryError:
     248            logging.warning('It was imposible to load the file_path as '
     249                            'image/png file type. Trying to use GdkPixbuf')
     250            self.drawing_canvas_data = \
     251                GdkPixbuf.Pixbuf.new_from_file(file_path)
    246252
    247253    def setup(self, width, height):
    248254        """Configure the Area object."""
    class Area(Gtk.DrawingArea): 
    348354            if self.drawing_canvas_data is None:
    349355                self.drawing_ctx.set_source_rgb(1.0, 1.0, 1.0)
    350356                self.drawing_ctx.fill()
    351             else:
     357            elif isinstance(self.drawing_canvas_data, cairo.ImageSurface):
    352358                self.drawing_ctx.set_source_surface(self.drawing_canvas_data)
    353359                self.drawing_ctx.paint()
    354                 self.drawing_canvas_data = None
     360            else:
     361                Gdk.cairo_set_source_pixbuf(
     362                    self.drawing_ctx, self.drawing_canvas_data, 0, 0)
     363                self.drawing_ctx.paint()
     364            self.drawing_canvas_data = None
    355365
    356366            ##canvas showed when we need display something and not draw it
    357367            self.temp_canvas = context.get_target().create_similar(