[dots] dots: Add a warning dialog when text extraction fails.



commit 543225c2a1612b5a347822e9cdfd5021387a8926
Author: Fernando Herrera <fherrera onirica com>
Date:   Fri Jul 16 02:00:35 2010 +0200

    dots: Add a warning dialog when text extraction fails.
    
    	* Add warning dialog
    	* Set Documents filter as default
    	* Do not regiter newline signal twice

 data/app_window.xml  |  107 +++++++++++++++++++++++++++++++------------------
 dots/app_window.py   |   28 +++++++++----
 dots/dots_project.py |   11 ++++-
 3 files changed, 97 insertions(+), 49 deletions(-)
---
diff --git a/data/app_window.xml b/data/app_window.xml
index 433d500..0ea9b2a 100644
--- a/data/app_window.xml
+++ b/data/app_window.xml
@@ -2,6 +2,71 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
+  <object class="GtkMessageDialog" id="notext-dialog">
+    <property name="border_width">5</property>
+    <property name="type_hint">normal</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="message_type">warning</property>
+    <property name="buttons">ok</property>
+    <property name="text" translatable="yes">Cannot extract text from the document.</property>
+    <property name="secondary_text" translatable="yes">Make sure that the document is valid and does contain text</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkAction" id="action_help">
+    <property name="stock_id">gtk-help</property>
+    <signal name="activate" handler="_onHelp" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_about">
+    <property name="stock_id">gtk-about</property>
+    <signal name="activate" handler="_onAbout" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_print">
+    <property name="stock_id">gtk-print</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onPrint" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_quit">
+    <property name="stock_id">gtk-quit</property>
+    <signal name="activate" handler="_onQuit" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_save_as">
+    <property name="stock_id">gtk-save-as</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onSaveAs" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_save">
+    <property name="stock_id">gtk-save</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onSave" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_open">
+    <property name="tooltip">Open a file</property>
+    <property name="stock_id">gtk-open</property>
+    <signal name="activate" handler="_onOpen" swapped="no"/>
+  </object>
+  <object class="GtkActionGroup" id="file_actions"/>
   <object class="GtkWindow" id="window1">
     <property name="default_width">480</property>
     <property name="default_height">360</property>
@@ -190,16 +255,16 @@
                     <property name="visible">True</property>
                     <child>
                       <object class="GtkImageMenuItem" id="imagemenuitem10">
-                      	<property name="related_action">action_about</property>
                         <property name="visible">True</property>
+                        <property name="related_action">action_about</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     </child>
-    		    <child>
+                    <child>
                       <object class="GtkImageMenuItem" id="imagemenuitem12">
-                      	<property name="related_action">action_help</property>
                         <property name="visible">True</property>
+                        <property name="related_action">action_help</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
@@ -294,40 +359,4 @@
       </object>
     </child>
   </object>
-  <object class="GtkActionGroup" id="file_actions"/>
-  <object class="GtkAction" id="action_open">
-    <property name="tooltip">Open a file</property>
-    <property name="stock_id">gtk-open</property>
-    <signal name="activate" handler="_onOpen" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_save">
-    <property name="stock_id">gtk-save</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onSave" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_save_as">
-    <property name="stock_id">gtk-save-as</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onSaveAs" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_quit">
-    <property name="stock_id">gtk-quit</property>
-    <signal name="activate" handler="_onQuit" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_print">
-    <property name="stock_id">gtk-print</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onPrint" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_about">
-    <property name="stock_id">gtk-about</property>
-    <signal name="activate" handler="_onAbout" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_help">
-    <property name="stock_id">gtk-help</property>
-    <signal name="activate" handler="_onHelp" swapped="no"/>
-  </object>
-
-
-
 </interface>
diff --git a/dots/app_window.py b/dots/app_window.py
index ed89536..00fdab8 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -208,6 +208,7 @@ class AppWindow(object):
 	filter.add_pattern("*.xhtml")
 	filter.add_pattern("*.xml")
 	chooser.add_filter(filter)
+	chooser.set_filter(filter)
  	response = chooser.run()
 	filename = chooser.get_filename()
 	chooser.destroy()
@@ -215,12 +216,6 @@ class AppWindow(object):
 		self.document = document_new (filename)
 		self.addDocument (self.document)
 		self.translate (self.document, self.config_builder)
-		action = self.main_xml.get_object('action_save_as')
-		action.set_sensitive(True)
-		action = self.main_xml.get_object('action_save')
-		action.set_sensitive(True)
-		action = self.main_xml.get_object('action_print')
-		action.set_sensitive(True)
 
     def _OnRevisionLine(self, item):
 	reviewentry = self.main_xml.get_object('reviewentry')
@@ -303,7 +298,7 @@ class AppWindow(object):
 	about.set_comments(_("A Braille translator for GNOME"))
 	about.set_license("GPLv3")
 	about.set_authors(["Eitan Isaacson", "Fernando Herrera  <fherrera onirica com>"])
-	about.set_copyright("(C) 2009 Eitan Isaacson\n(C) 2010 Consorcio Fernando de los Ríos")
+	about.set_copyright("(C) 2009 Eitan Isaacson\n(C) 2010 Consorcio Fernando de los Rios")
 	about.set_website("http://live.gnome.org/Dots";)
 	about.set_website_label("Dots website")
 	about.set_documenters(["Fernando Herrera"])
@@ -316,6 +311,7 @@ class AppWindow(object):
 	container = self.main_xml.get_object('main_alignment')
 	if self.project is not None:
 		container.remove (self.project)
+		self.project.destroy()
 
         self.project = DotsProject(document, _("Unsaved Document"))
 	container.add(self.project)
@@ -323,7 +319,23 @@ class AppWindow(object):
 	self.project.connect("line-changed", self._onLineChanged)
 
     def translate(self, document, config):
-        self.project.transcribeBraille(config)
+        res = self.project.transcribeBraille(config)
+	if not res:
+		dialog = self.main_xml.get_object('notext-dialog')
+		dialog.run()
+		dialog.destroy()
+
+	action = self.main_xml.get_object('action_save_as')
+	action.set_sensitive(res)
+	action = self.main_xml.get_object('action_save')
+	action.set_sensitive(res)
+	action = self.main_xml.get_object('action_print')
+	action.set_sensitive(res)
+
+	return res
+
+
+
 
     def run(self):
         self.window.show_all()
diff --git a/dots/dots_project.py b/dots/dots_project.py
index a91fd2d..08d0f14 100644
--- a/dots/dots_project.py
+++ b/dots/dots_project.py
@@ -41,7 +41,10 @@ class DotsProject(gtk.ScrolledWindow):
         self.out_file = None
         self.config = None
 	self.current_line = None
-	gobject.signal_new("line-changed", self, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gtk.ScrolledWindow, gobject.TYPE_STRING))
+	try:
+		gobject.signal_new("line-changed", self, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gtk.ScrolledWindow, gobject.TYPE_STRING))
+	except:
+		pass
 
     def set_name(self, name):
         gtk.ScrolledWindow.set_name(self, name)
@@ -70,7 +73,7 @@ class DotsProject(gtk.ScrolledWindow):
 
     def transcribeBraille(self, config):
         self.config = config
-        self._transcribeBraille()
+        return self._transcribeBraille()
 
     def view_ascii(self):
         self.view.set_buffer(self.buffer)
@@ -82,9 +85,13 @@ class DotsProject(gtk.ScrolledWindow):
 	self.document.translate (self.config)
 	
         braille_text = self.document.get_braille_text() 
+	if braille_text == "":
+		return False
+
         self.buffer.set_text(braille_text)
 
         self.braille_buffer.set_text(
             ''.join([ascii_braille.ascii_to_braille.get(
                         x, '') for x in braille_text]))
+	return True
         



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