[ocrfeeder] Add option to recognize current page or the whole document (gb#635306)



commit 4e314dbdb60ccbab74719c4047e727d39bcf2675
Author: Joaquim Rocha <jrocha igalia com>
Date:   Thu Mar 17 23:16:40 2011 +0100

    Add option to recognize current page or the whole document (gb#635306)

 src/ocrfeeder/studio/studioBuilder.py   |   10 +++++++---
 src/ocrfeeder/studio/widgetModeler.py   |   30 ++++++++++++++++++++++++++----
 src/ocrfeeder/studio/widgetPresenter.py |   21 +++++++++++++--------
 3 files changed, 46 insertions(+), 15 deletions(-)
---
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index 3850217..0c305ee 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -87,8 +87,9 @@ class Studio:
                                                                self.configuration_manager)
         self.project_name = None
 
-        toolbar_callback_dict = {'detection': self.__recognizeCurrentPageAction,
-                         'export_to_odt': self.exportToOdt}
+        toolbar_callback_dict = {'recognizePage': self.__recognizePageAction,
+                                 'recognizeDocument': self.__recognizeDocumentAction,
+                                 'export_to_odt': self.exportToOdt}
 
         menubar_callback_dict = {'exit': self.quit, 'add_image': self.addImage, 'export_to_odt': self.exportToOdt, 'edit_page': self.choosePageSize,
                                  'delete_page': self.deleteCurrentPage, 'export_dialog': self.exportDialog, 'add_folder': self.addFolder,
@@ -317,9 +318,12 @@ class Studio:
             return
         self.source_images_controler.addImages(images)
 
-    def __recognizeCurrentPageAction(self, widget):
+    def __recognizePageAction(self, widget):
         self.source_images_controler.recognizeCurrentPage()
 
+    def __recognizeDocumentAction(self, widget):
+        self.source_images_controler.recognizeDocument()
+
     def setProjectName(self, project_name):
         self.project_name = project_name
         project_title = os.path.splitext(os.path.basename(self.project_name))[0]
diff --git a/src/ocrfeeder/studio/widgetModeler.py b/src/ocrfeeder/studio/widgetModeler.py
index d847bc9..4c31456 100644
--- a/src/ocrfeeder/studio/widgetModeler.py
+++ b/src/ocrfeeder/studio/widgetModeler.py
@@ -561,11 +561,30 @@ class ImageReviewer_Controler:
         item = AsyncItem(self.__performRecognitionForReviewer,
                          (image_reviewer,),
                          self.__performRecognitionForReviewerFinishedCb,
-                         (dialog, image_reviewer,))
-        info = (_('Recognizing Document'), _(u'Please waitâ?¦'))
+                         (dialog, image_reviewer, [image_reviewer]))
+        info = (_('Recognizing Page'), _(u'Please waitâ?¦'))
         dialog.setItemsList([(info, item)])
         dialog.run()
 
+    def recognizeDocument(self):
+        reviewers = self.image_reviewer_dict.values()
+        dialog = QueuedEventsProgressDialog(self.main_window.window)
+        items = []
+        i = 1
+        total = len(reviewers)
+        for reviewer in reviewers:
+            item = AsyncItem(self.__performRecognitionForReviewer,
+                             (reviewer,),
+                             self.__performRecognitionForReviewerFinishedCb,
+                             (dialog, reviewer, reviewers))
+            info = (_('Recognizing Document'),
+                    _(u'Recognizing page %(page_number)s/%(total_pages)s. Please waitâ?¦') % {'page_number': i,
+                                                                                            'total_pages': total})
+            items.append((info, item))
+            i += 1
+        dialog.setItemsList(items)
+        dialog.run()
+
     def __performRecognitionForReviewer(self, image_reviewer):
         window_size = self.configuration_manager.window_size
         if window_size == 'auto':
@@ -601,13 +620,16 @@ class ImageReviewer_Controler:
         return None
 
     def __performRecognitionForReviewerFinishedCb(self, dialog, image_reviewer,
+                                                  reviewers_to_process,
                                                   data_boxes, error):
         image_reviewer.clear()
         image_reviewer.applyTextColors()
         for data_box in data_boxes:
             image_reviewer.addDataBox(data_box)
-        dialog.cancel()
-        image_reviewer.updateMainWindow()
+        if image_reviewer == reviewers_to_process[-1]:
+            dialog.cancel()
+            for reviewer in reviewers_to_process:
+                reviewer.updateMainWindow()
 
     def copyRecognizedTextToClipboard(self, widget):
         image_reviewer = self.__getCurrentReviewer()
diff --git a/src/ocrfeeder/studio/widgetPresenter.py b/src/ocrfeeder/studio/widgetPresenter.py
index b94351e..6856bd3 100644
--- a/src/ocrfeeder/studio/widgetPresenter.py
+++ b/src/ocrfeeder/studio/widgetPresenter.py
@@ -81,7 +81,8 @@ class MainWindow:
             <menuitem action="ZoomFit"/>
         </menu>
         <menu action="Document">
-            <menuitem action="OCRFeederDetection"/>
+            <menuitem action="OCRFeederReconDocument"/>
+            <menuitem action="OCRFeederReconPage"/>
             <menuitem action="RecognizeAreas"/>
             <menuitem action="SelectAllAreas"/>
             <menuitem action="SelectPreviousArea"/>
@@ -104,7 +105,7 @@ class MainWindow:
     <toolbar name="ToolBar">
         <toolitem action="AddImage"/>
         <separator/>
-        <toolitem action="OCRFeederDetection"/>
+        <toolitem action="OCRFeederReconDocument"/>
         <toolitem action="GenerateODT"/>
         <separator/>
         <toolitem action="ZoomOut"/>
@@ -181,10 +182,14 @@ class MainWindow:
                                   ('Help', None, _('_Help')),
                                   ('HelpContents', gtk.STOCK_HELP, _('_Help'), 'F1', _('Help contents'), menu_items['help_contents']),
                                   ('About', gtk.STOCK_ABOUT, _('_About'), None, _('About this application'), menu_items['about']),
-                                  ('OCRFeederDetection', None,
+                                  ('OCRFeederReconDocument', None,
                                    _('_Recognize Document'), '<control><shift>d',
-                                   _("Automatic Detection and Recognition"),
-                                   tool_items['detection']),
+                                   _("Automatically detect and recognize all pages"),
+                                   tool_items['recognizeDocument']),
+                                  ('OCRFeederReconPage', None,
+                                   _('_Recognize Page'), '<control><shift>g',
+                                   _("Automatically detect and recognize the current page"),
+                                   tool_items['recognizePage']),
                                   ('RecognizeAreas', None,
                                    _('Recognize Selected _Areas'), '<control><shift>r',
                                    _("Recognize Selected Areas"),
@@ -231,7 +236,7 @@ class MainWindow:
         self.main_box.pack_start(tool_bar, False, False)
         odt_export_button = ui_manager.get_widget('/ToolBar/GenerateODT')
         odt_export_button.set_icon_name('ooo-writer')
-        detection_button = ui_manager.get_widget('/ToolBar/OCRFeederDetection')
+        detection_button = ui_manager.get_widget('/ToolBar/OCRFeederReconDocument')
         detection_icon = gtk.image_new_from_file(DETECT_ICON)
         detection_icon.show()
         detection_button.set_icon_widget(detection_icon)
@@ -256,9 +261,9 @@ class MainWindow:
         if not self.action_group:
             return
         actions = ['ZoomIn', 'ZoomOut', 'ResetZoom',
-                   'Export', 'GenerateODT', 'Unpaper',
+                   'Export', 'GenerateODT', 'Unpaper', 'OCRFeederReconPage',
                    'DeletePage', 'SaveProject', 'SaveProjectAs',
-                   'OCRFeederDetection', 'EditPage', 'ClearProject',
+                   'OCRFeederReconDocument', 'EditPage', 'ClearProject',
                    'AppendProject', 'ZoomFit', 'ImageDeskewer']
         self.__setActionsSensitiveness(actions, has_images)
         if not has_images:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]