[ocrfeeder] Make recognize selected areas action dependent on the existence of selected areas



commit b637a1e99c1ee29ddd5e34dc663e0229e6dcd856
Author: Joaquim Rocha <jrocha cookiemonster local igalia com>
Date:   Wed Mar 24 10:18:50 2010 +0100

    Make recognize selected areas action dependent on the existence of selected areas

 studio/customWidgets.py   |   15 ++++++++++-----
 studio/studioBuilder.py   |    7 ++++++-
 studio/widgetModeler.py   |   25 ++++++++++++++++++++-----
 studio/widgetPresenter.py |    8 ++++++++
 4 files changed, 44 insertions(+), 11 deletions(-)
---
diff --git a/studio/customWidgets.py b/studio/customWidgets.py
index 86b34d9..a295329 100644
--- a/studio/customWidgets.py
+++ b/studio/customWidgets.py
@@ -44,6 +44,9 @@ class SelectableBoxesArea(goocanvas.Canvas):
         'updated_box' : (gobject.SIGNAL_RUN_LAST,
                      gobject.TYPE_NONE,
                      (gobject.TYPE_PYOBJECT,)),
+        'deselected_box' : (gobject.SIGNAL_RUN_LAST,
+                            gobject.TYPE_NONE,
+                            (gobject.TYPE_PYOBJECT,)),
         'dragged_box' : (gobject.SIGNAL_RUN_LAST,
                      gobject.TYPE_NONE,
                      (gobject.TYPE_PYOBJECT,)),
@@ -136,7 +139,9 @@ class SelectableBoxesArea(goocanvas.Canvas):
             if selected_area != None:
                 selected_area.set_property('stroke_color_rgba',
                                            self.__rgbaToInteger(self.area_stroke_rgba))
-        self.selected_areas = []
+        while self.selected_areas:
+            selected_area = self.selected_areas.pop(0)
+            self.emit('deselected_box', selected_area)
         self.grab_focus(self.image)
     
     def zoom(self, zoom_value, add_zoom = True):
@@ -237,10 +242,10 @@ class SelectableBoxesArea(goocanvas.Canvas):
             self.emit('updated_box', item)
             return True
         if key_name == 'delete':
-            for area in self.selected_areas:
-                area.remove()
-                self.emit('removed_box', area)
-            self.selected_areas = []
+            while self.selected_areas:
+                selected_area = self.selected_areas.pop(0)
+                selected_area.remove()
+                self.emit('removed_box', selected_area)
     
     def pressedKeyOnImage(self, item, rect, event):
         key_name = gtk.gdk.keyval_name(event.keyval).lower()
diff --git a/studio/studioBuilder.py b/studio/studioBuilder.py
index 85a68d4..625e6ac 100644
--- a/studio/studioBuilder.py
+++ b/studio/studioBuilder.py
@@ -73,7 +73,11 @@ class Studio:
         self.main_window.main_area_left.add_with_viewport(self.source_images_icon_view)
         self.images_selectable_area = {}
         self.images_dict = create_images_dict_from_liststore(self.source_images_selector.list_store)
-        self.source_images_controler = ImageReviewer_Controler(self.main_window.notebook, self.images_dict, self.source_images_icon_view, self.ocr_engines, self.configuration_manager, self.main_window.tripple_statusbar)
+        self.source_images_controler = ImageReviewer_Controler(self.main_window,
+                                                               self.images_dict,
+                                                               self.source_images_icon_view,
+                                                               self.ocr_engines,
+                                                               self.configuration_manager)
         self.project_name = None
         
         toolbar_callback_dict = {'detection': self.source_images_controler.performBoxDetection,
@@ -95,6 +99,7 @@ class Studio:
         if dirs:
             self.__addImagesToReviewer(lib.getImagesFromFolder(dirs[0]))
         
+        self.main_window.setHasSelectedBoxes(False)
         self.main_window.setHasImages(not self.source_images_selector.isEmpty())
 
         # Show dialog to choose system-wide OCR engines when no engine was found
diff --git a/studio/widgetModeler.py b/studio/widgetModeler.py
index c2cb721..0a708c4 100644
--- a/studio/widgetModeler.py
+++ b/studio/widgetModeler.py
@@ -158,7 +158,8 @@ class SourceImagesSelectorIconView(gtk.IconView):
     
 class ImageReviewer:
     
-    def __init__(self, path_to_image, ocr_engines):
+    def __init__(self, main_window, path_to_image, ocr_engines):
+        self.main_window = main_window
         self.path_to_image = path_to_image
         self.text_box_fill_color = (94, 156, 235, 150)
         self.text_box_stroke_color = (94, 156, 235, 250)
@@ -169,6 +170,8 @@ class ImageReviewer:
         self.selectable_boxes_area.connect('removed_box', self.removedBox)
         self.selectable_boxes_area.connect('updated_box', self.updatedBox)
         self.selectable_boxes_area.connect('dragged_box', self.updatedBoxBounds)
+        self.selectable_boxes_area.connect('deselected_box',
+                                           self.deselectedBoxCb)
         self.image_pixbuf = gtk.gdk.pixbuf_new_from_file(self.path_to_image)
         self.reviewer_area = gtk.HPaned()
         self.reviewer_area.set_position(500)
@@ -220,6 +223,10 @@ class ImageReviewer:
             num_boxes = self.boxeditor_notebook.get_n_pages()
             self.addBoxEditor(box)
             self.boxeditor_notebook.set_current_page(num_boxes)
+        self.updateMainWindow()
+
+    def deselectedBoxCb(self, widget, box):
+        self.updateMainWindow()
     
     def updatedBox(self, widget, box):
         for editor in self.editor_list:
@@ -232,6 +239,7 @@ class ImageReviewer:
                 editor.updateBounds(box)
     
     def removedBox(self, widget, box):
+        self.updateMainWindow()
         for i in xrange(len(self.editor_list)):
             editor = self.editor_list[i]
             if editor.box == box:
@@ -340,22 +348,29 @@ class ImageReviewer:
             changed = True
         if changed:
             self.selectable_boxes_area.zoom(min(image_height, image_width), False)
+
+    def updateMainWindow(self):
+        has_selected_areas = self.selectable_boxes_area.getSelectedAreas()
+        self.main_window.setHasSelectedBoxes(bool(has_selected_areas))
     
 class ImageReviewer_Controler:
     
-    def __init__(self, notebook, images_dict, source_images_selector_widget, ocr_engines, configuration_manager, tripple_statusbar, selection_changed_signal = 'selection-changed'):
-        self.notebook = notebook
+    def __init__(self, main_window, images_dict, source_images_selector_widget,
+                 ocr_engines, configuration_manager,
+                 selection_changed_signal = 'selection-changed'):
+        self.main_window = main_window
+        self.notebook = self.main_window.notebook
         self.image_reviewer_dict = {}
         self.source_images_selector_widget = source_images_selector_widget
         self.ocr_engines = ocr_engines
         self.configuration_manager = configuration_manager
-        self.tripple_statusbar = tripple_statusbar
+        self.tripple_statusbar = self.main_window.tripple_statusbar
         for key, image in images_dict.items():
             self.addImage(key, image)
         self.source_images_selector_widget.connect(selection_changed_signal, self.selectImageReviewer)
     
     def addImage(self, pixbuf, image):
-        image_reviewer = ImageReviewer(image, self.ocr_engines)
+        image_reviewer = ImageReviewer(self.main_window, image, self.ocr_engines)
         image_reviewer.selectable_boxes_area.connect('changed_zoom', self.__setZoomStatus)
         image_reviewer.setTextFillColor(self.configuration_manager.getTextFill())
         image_reviewer.setTextStrokeColor(self.configuration_manager.getTextStroke())
diff --git a/studio/widgetPresenter.py b/studio/widgetPresenter.py
index 93e536d..1784752 100644
--- a/studio/widgetPresenter.py
+++ b/studio/widgetPresenter.py
@@ -198,6 +198,14 @@ class MainWindow:
                    'AppendProject', 'ZoomFit']
         for gtkaction in [self.action_group.get_action(action) for action in actions]:
             gtkaction.set_sensitive(has_images)
+
+    def setHasSelectedBoxes(self, has_selected_boxes = True):
+        if not self.action_group:
+            return
+        actions = ['RecognizeAreas']
+        for gtkaction in [self.action_group.get_action(action) \
+                          for action in actions]:
+            gtkaction.set_sensitive(has_selected_boxes)
         
 class BoxEditor(gtk.ScrolledWindow):
     



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