treating the error generated when the user tries to use
authorLincoln de Sousa <lincoln@minaslivre.org>
Sun, 10 Aug 2008 01:14:26 +0000 (22:14 -0300)
committerLincoln de Sousa <lincoln@minaslivre.org>
Sun, 10 Aug 2008 01:14:26 +0000 (22:14 -0300)
a file which has an unknown format (commonly not an image)

gzv.py

diff --git a/gzv.py b/gzv.py
index e112cd8..6820f83 100644 (file)
--- a/gzv.py
+++ b/gzv.py
@@ -15,6 +15,7 @@
 import os
 import gtk
 import gtk.glade
+import gobject
 import math
 import cairo
 from ConfigParser import ConfigParser
@@ -198,6 +199,12 @@ class Gzv(GladeLoader):
         self.load_balls_to_treeview()
         self.draw.queue_draw()
 
+    def unload_project(self):
+        self.project = None
+        self.image = None
+        self.balls = BallManager()
+        self.draw.queue_draw()
+
     def load_balls_to_treeview(self):
         self.model.clear()
         for i in self.balls:
@@ -254,7 +261,21 @@ class Gzv(GladeLoader):
 
         # loading the picture image and getting some useful
         # information to draw it in the widget's background
-        img = gtk.gdk.pixbuf_new_from_file(self.image)
+        try:
+            img = gtk.gdk.pixbuf_new_from_file(self.image)
+        except gobject.GError:
+            msg = _("Couldn't recognize the image file format.")
+            dialog = gtk.MessageDialog(self.window,
+                                       gtk.DIALOG_MODAL,
+                                       gtk.MESSAGE_ERROR,
+                                       gtk.BUTTONS_CLOSE)
+            dialog.set_markup(msg)
+            dialog.run()
+            dialog.destroy()
+
+            self.draw.stop_emission('expose-event')
+            return self.unload_project()
+
         pixels = img.get_pixels()
         rowstride = img.get_rowstride()
         width = img.get_width()