[ocrfeeder] Resets the favorite engine when it does not exist



commit 17566027ab193bd4ecf6e4fc00e18e00baef1753
Author: Joaquim Rocha <jrocha igalia com>
Date:   Wed May 11 17:38:34 2011 +0200

    Resets the favorite engine when it does not exist
    
    When the favorite engine does not exist then the OCR is not performed
    in the automatic recognition. These changes check if the favorite engine
    exists and if not, set it to the first engine of the configured list.

 src/ocrfeeder/feeder/ocrEngines.py    |    9 ++++++++-
 src/ocrfeeder/studio/studioBuilder.py |    2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/ocrfeeder/feeder/ocrEngines.py b/src/ocrfeeder/feeder/ocrEngines.py
index 0a7941c..a26e423 100644
--- a/src/ocrfeeder/feeder/ocrEngines.py
+++ b/src/ocrfeeder/feeder/ocrEngines.py
@@ -143,13 +143,20 @@ class OcrEnginesManager:
 
     def makeEnginesFromFolder(self, folder):
         self.ocr_engines = []
+        favorite_engine_exists = False
         for xml_file in self.getXmlFilesInFolder(folder):
             try:
-                self.ocr_engines.append((self.getEngineFromXml(xml_file), xml_file))
+                engine = self.getEngineFromXml(xml_file)
+                self.ocr_engines.append((engine, xml_file))
             except WrongSettingsForEngine, we:
                 lib.debug("Cannot load engine at %s: %s" %( xml_file, str(we)))
+            else:
+                favorite_engine_exists = favorite_engine_exists or \
+                    self.configuration_manager.favorite_engine == engine.name
         if not len(self.ocr_engines):
             lib.debug("Warning: no engines found!")
+        elif not favorite_engine_exists:
+            self.configuration_manager.favorite_engine = self.ocr_engines[0][0].name
 
     def getEngineFromXml(self, xml_file_name):
         document = ET.parse(xml_file_name)
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index 9893a33..d11d853 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -67,9 +67,9 @@ class Studio:
         self.main_window.setTitle(self.title)
         self.configuration_manager = ConfigurationManager()
         self.ocr_engines_manager = OcrEnginesManager(self.configuration_manager)
+        self.configuration_manager.loadConfiguration()
         self.ocr_engines_manager.makeEnginesFromFolder(self.configuration_manager.user_engines_folder)
         self.ocr_engines = self.ocr_engines_manager.ocr_engines
-        self.configuration_manager.loadConfiguration()
         self.source_images_selector = SourceImagesSelector()
         self.source_images_selector.connect('selection_changed', self.selectionChanged)
         self.source_images_icon_view = SourceImagesSelectorIconView(self.source_images_selector)



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