[ocrfeeder] Show error dialogs when not able to open messages
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Show error dialogs when not able to open messages
- Date: Fri, 5 Mar 2010 14:18:59 +0000 (UTC)
commit c09a53575f28c9df331d44b5077761bd99fe3ba2
Author: Joaquim Rocha <jrocha igalia com>
Date: Fri Mar 5 15:05:38 2010 +0100
Show error dialogs when not able to open messages
feeder/imageManipulation.py | 19 +++++++++++++++----
studio/widgetModeler.py | 11 +++++++++--
studio/widgetPresenter.py | 7 +++++++
3 files changed, 31 insertions(+), 6 deletions(-)
---
diff --git a/feeder/imageManipulation.py b/feeder/imageManipulation.py
index 2eeab95..e50777c 100644
--- a/feeder/imageManipulation.py
+++ b/feeder/imageManipulation.py
@@ -21,14 +21,20 @@
import tempfile
from util.lib import debug
+import gettext
import Image, ImageDraw
import os.path
from util import graphics
+import sys
+
+_ = gettext.gettext
class ImageProcessor:
def __init__(self, path_to_image, window_size = None):
self.window_size = window_size
+ error_message = _("A problem occurred while trying to open the image:\n %s\n"
+ "Ensure the image exists or try converting it to another format.") % path_to_image
if os.path.isfile(path_to_image):
try:
self.original_image = Image.open(path_to_image)
@@ -37,9 +43,11 @@ class ImageProcessor:
self.window_size = self.original_image.size[1] / 60.
debug('Window Size: ', self.window_size)
except:
- raise ImageManipulationError
+ debug(sys.exc_info())
+ raise ImageManipulationError(error_message)
else:
- raise IOError
+ debug(sys.exc_info())
+ raise ImageManipulationError(error_message)
def __windowContrast(self, bgcolor, x, y, constrast_tolerance = 120):
image = self.black_n_white_image
@@ -123,8 +131,11 @@ class ContentAnalyser:
class ImageManipulationError(Exception):
- def __init__(self):
- pass
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return self.value
class InsuficientPointsForPolygon(Exception):
diff --git a/studio/widgetModeler.py b/studio/widgetModeler.py
index 5c076fc..da111ce 100644
--- a/studio/widgetModeler.py
+++ b/studio/widgetModeler.py
@@ -29,7 +29,7 @@ from util import graphics, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_FILL, \
PAPER_SIZES
from util.lib import debug
from widgetPresenter import BoxEditor, PagesToExportDialog, FileDialog, \
- PageSizeDialog, getPopupMenu, QuestionDialog, UnpaperDialog
+ PageSizeDialog, getPopupMenu, WarningDialog, UnpaperDialog
import gettext
import gobject
import gtk
@@ -381,7 +381,14 @@ class ImageReviewer_Controler:
window_size = None
else:
window_size = float(window_size)
- image_processor = ImageProcessor(image_reviewer.path_to_image, window_size)
+ try:
+ image_processor = ImageProcessor(image_reviewer.path_to_image, window_size)
+ except Exception as e:
+ message = '<b>%s</b>\n%s' % (_('Warning:'), str(e))
+ warning_dialog = WarningDialog(message)
+ warning_dialog.run()
+ warning_dialog.destroy()
+ return
while gtk.events_pending():
gtk.main_iteration()
block_retriever = BlockRetriever(image_processor.imageToBinary())
diff --git a/studio/widgetPresenter.py b/studio/widgetPresenter.py
index 2f942b2..bacaa19 100644
--- a/studio/widgetPresenter.py
+++ b/studio/widgetPresenter.py
@@ -665,6 +665,13 @@ class QuestionDialog(gtk.MessageDialog):
self.set_icon_from_file(WINDOW_ICON)
self.set_markup(message)
+class WarningDialog(gtk.MessageDialog):
+
+ def __init__(self, message, buttons = gtk.BUTTONS_OK):
+ super(WarningDialog, self).__init__(type = gtk.MESSAGE_WARNING, buttons = buttons)
+ self.set_icon_from_file(WINDOW_ICON)
+ self.set_markup(message)
+
class UnpaperDialog(gtk.Dialog):
def __init__(self, reviewer , unpaper, temp_dir = '/tmp'):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]