[ocrfeeder] studioBuilder: Make page detection paralel
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] studioBuilder: Make page detection paralel
- Date: Mon, 5 Jul 2010 15:10:30 +0000 (UTC)
commit fd9f73ed43df05ffe434f26c4846453a7d048999
Author: Joaquim Rocha <jrocha igalia com>
Date: Mon Jul 5 12:52:35 2010 +0200
studioBuilder: Make page detection paralel
Use a different thread to perform the
OCRFeeder detection so the GUI will not be blocked.
studio/widgetModeler.py | 78 ++++++++++++++++++++++++++++-----------------
studio/widgetPresenter.py | 6 ++-
2 files changed, 53 insertions(+), 31 deletions(-)
---
diff --git a/studio/widgetModeler.py b/studio/widgetModeler.py
index 77ce7d4..70e5c61 100644
--- a/studio/widgetModeler.py
+++ b/studio/widgetModeler.py
@@ -28,8 +28,10 @@ from studio.configuration import ProjectSaver, ProjectLoader
from util import graphics, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_FILL, \
PAPER_SIZES
from util.lib import debug
+from util.asyncworker import AsyncItem
from widgetPresenter import BoxEditor, PagesToExportDialog, FileDialog, \
- PageSizeDialog, getPopupMenu, WarningDialog, UnpaperDialog
+ PageSizeDialog, getPopupMenu, WarningDialog, UnpaperDialog, \
+ QueuedEventsProgressDialog
import gettext
import gobject
import gtk
@@ -417,13 +419,28 @@ class ImageReviewer_Controler:
def performBoxDetection(self, widget):
image_reviewer = self.__getCurrentReviewer()
- self.performBoxDetectionForReviewer(image_reviewer)
- while gtk.events_pending():
- gtk.main_iteration()
+ image_reviewer.selectable_boxes_area.clearAreas()
+ image_reviewer.applyTextColors()
+ dialog = QueuedEventsProgressDialog(self.main_window.window)
+ item = AsyncItem(self.performBoxDetectionForReviewer,
+ (image_reviewer,),
+ self.__performBoxDetectionForReviewerFinishedCb,
+ (dialog, image_reviewer,))
+ info = (_('Recognizing Document'), _('Please waitâ?¦'))
+ dialog.setItemsList([(info, item)])
+ dialog.run()
+
+ def __performBoxDetectionForReviewerFinishedCb(self, dialog, image_reviewer,
+ box_dimensions, error):
+ if error:
+ dialog.cancel()
+ return
+ for dimensions in (box_dimensions or []):
+ image_reviewer.selectable_boxes_area.addArea(dimensions)
image_reviewer.addNewEditorsToAllBoxes()
- image_reviewer.performOcrForAllEditors(self.configuration_manager.favorite_engine)
- while gtk.events_pending():
- gtk.main_iteration()
+ favorite_engine = self.configuration_manager.favorite_engine
+ image_reviewer.performOcrForAllEditors(favorite_engine)
+ dialog.cancel()
def performBoxDetectionForReviewer(self, image_reviewer):
window_size = self.configuration_manager.window_size
@@ -431,31 +448,34 @@ class ImageReviewer_Controler:
window_size = None
else:
window_size = float(window_size)
- try:
- image_processor = ImageProcessor(image_reviewer.path_to_image, window_size)
- except:
- warning_dialog = WarningDialog(str(sys.exc_info()[1]))
- warning_dialog.run()
- warning_dialog.destroy()
- return
- while gtk.events_pending():
- gtk.main_iteration()
+
+ image_processor = ImageProcessor(image_reviewer.path_to_image,
+ window_size)
+
+ max_width = image_reviewer.image_pixbuf.get_width()
+ max_height = image_reviewer.image_pixbuf.get_height()
+ window_size = image_processor.window_size
block_retriever = BlockRetriever(image_processor.imageToBinary())
- while gtk.events_pending():
- gtk.main_iteration()
+ dimensions_list = self.__getDimensionsFromBlockRetriever(block_retriever,
+ max_width,
+ max_height,
+ window_size)
+ return dimensions_list
+
+ def __getDimensionsFromBlockRetriever(self, block_retriever,
+ max_width, max_height, window_size):
blocks = block_retriever.getAllBlocks()
- while gtk.events_pending():
- gtk.main_iteration()
- image_reviewer.selectable_boxes_area.clearAreas()
- image_reviewer.applyTextColors()
+ dimensions_list = []
for block in blocks:
- leftmost_x, highest_y, rightmost_x, lowest_y = (block.translateToUnits(image_processor.window_size))
- rightmost_x = min(rightmost_x, image_reviewer.image_pixbuf.get_width())
- lowest_y = min(lowest_y, image_reviewer.image_pixbuf.get_height())
- dimensions = graphics.getBoundsFromStartEndPoints((leftmost_x, highest_y), (rightmost_x, lowest_y))
- image_reviewer.selectable_boxes_area.addArea(dimensions)
- while gtk.events_pending():
- gtk.main_iteration()
+ leftmost_x, highest_y, rightmost_x, lowest_y = \
+ block.translateToUnits(window_size)
+ rightmost_x = min(rightmost_x, max_width)
+ lowest_y = min(lowest_y, max_height)
+ dimensions = graphics.getBoundsFromStartEndPoints(
+ (leftmost_x, highest_y),
+ (rightmost_x, lowest_y))
+ dimensions_list.append(dimensions)
+ return dimensions_list
def setDataBox(self, widget):
image_reviewer = self.__getCurrentReviewer()
diff --git a/studio/widgetPresenter.py b/studio/widgetPresenter.py
index 64b7b0a..1fd6a5b 100644
--- a/studio/widgetPresenter.py
+++ b/studio/widgetPresenter.py
@@ -783,8 +783,10 @@ class QuestionDialog(gtk.MessageDialog):
class WarningDialog(gtk.MessageDialog):
- def __init__(self, message, buttons = gtk.BUTTONS_OK):
- super(WarningDialog, self).__init__(type = gtk.MESSAGE_WARNING, buttons = buttons)
+ def __init__(self, message, buttons = gtk.BUTTONS_OK, parent = None):
+ super(WarningDialog, self).__init__(type = gtk.MESSAGE_WARNING,
+ buttons = buttons,
+ parent = parent)
self.set_icon_from_file(WINDOW_ICON)
self.set_markup(message)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]