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): |
241 | 241 | return style.zoom(44) |
242 | 242 | |
243 | 243 | def load_from_file(self, file_path): |
244 | | self.drawing_canvas_data = \ |
| 244 | try: |
| 245 | self.drawing_canvas_data = \ |
245 | 246 | 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) |
246 | 252 | |
247 | 253 | def setup(self, width, height): |
248 | 254 | """Configure the Area object.""" |
… |
… |
class Area(Gtk.DrawingArea): |
348 | 354 | if self.drawing_canvas_data is None: |
349 | 355 | self.drawing_ctx.set_source_rgb(1.0, 1.0, 1.0) |
350 | 356 | self.drawing_ctx.fill() |
351 | | else: |
| 357 | elif isinstance(self.drawing_canvas_data, cairo.ImageSurface): |
352 | 358 | self.drawing_ctx.set_source_surface(self.drawing_canvas_data) |
353 | 359 | 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 |
355 | 365 | |
356 | 366 | ##canvas showed when we need display something and not draw it |
357 | 367 | self.temp_canvas = context.get_target().create_similar( |