[dots] Model/View separation and use python bindings Create Document and Translator classes handling the lo



commit 82df8540909d438c22ddf9881b625d4ab273e8b2
Author: Fernando Herrera <fherrera onirica com>
Date:   Sat May 15 19:39:31 2010 +0000

    Model/View separation and use python bindings
    Create Document and Translator classes handling the logic for
    translating files. Make the UI to use these classes. Also use
    python bindings for liblouisxml instead of exec the tools.
    Configuration is not yet passed to the translation

 data/dots_assist.xml     |   10 +++++-----
 dots/Makefile.am         |    4 +++-
 dots/app_window.py       |    6 +++---
 dots/document.py         |   10 +++++++---
 dots/dots_project.py     |   39 ++++++++-------------------------------
 dots/import_assistant.py |   12 +++++-------
 dots/translator.py       |    7 ++++++-
 7 files changed, 37 insertions(+), 51 deletions(-)
---
diff --git a/data/dots_assist.xml b/data/dots_assist.xml
index c71c14e..82cd50f 100644
--- a/data/dots_assist.xml
+++ b/data/dots_assist.xml
@@ -52,7 +52,7 @@
         <property name="wrap">True</property>
         <property name="selectable">True</property>
         <child internal-child="accessible">
-          <object class="AtkObject" id="dummy">
+          <object class="AtkObject" id="dummy1">
             <property name="AtkObject::accessible-name" translatable="yes">Braille Import Assistant</property>
           </object>
         </child>
@@ -68,7 +68,7 @@
         <property name="border_width">12</property>
         <property name="spacing">6</property>
         <child internal-child="accessible">
-          <object class="AtkObject" id="dummy">
+          <object class="AtkObject" id="dummy2">
             <property name="AtkObject::accessible-name" translatable="yes">Input File</property>
           </object>
         </child>
@@ -151,7 +151,7 @@
         <property name="visible">True</property>
         <property name="border_width">12</property>
         <child internal-child="accessible">
-          <object class="AtkObject" id="dummy">
+          <object class="AtkObject" id="dummy3">
             <property name="AtkObject::accessible-name" translatable="yes">Translation</property>
           </object>
         </child>
@@ -242,7 +242,7 @@
         <property name="border_width">12</property>
         <property name="spacing">6</property>
         <child internal-child="accessible">
-          <object class="AtkObject" id="dummy">
+          <object class="AtkObject" id="dummy4">
             <property name="AtkObject::accessible-name" translatable="yes">Output Format</property>
           </object>
         </child>
@@ -463,7 +463,7 @@
         <property name="border_width">12</property>
         <property name="spacing">6</property>
         <child internal-child="accessible">
-          <object class="AtkObject" id="dummy">
+          <object class="AtkObject" id="dummy5">
             <property name="AtkObject::accessible-name" translatable="yes">Configuration Summary</property>
           </object>
         </child>
diff --git a/dots/Makefile.am b/dots/Makefile.am
index 1d9747d..a02b83f 100644
--- a/dots/Makefile.am
+++ b/dots/Makefile.am
@@ -7,7 +7,9 @@ dots_PYTHON = \
 	dots_project.py \
 	import_assistant.py \
 	host_settings.py \
-	config_builder.py
+	config_builder.py \
+	document.py \
+	translator.py
 
 DISTCLEANFILES = host_settings.py
 
diff --git a/dots/app_window.py b/dots/app_window.py
index 20abdf6..14a75e8 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -95,10 +95,10 @@ class AppWindow(object):
                 count += 1
         return count + 1
 
-    def newProject(self, input_file, config_text):
+    def translate(self, document, config):
         dotsproj = DotsProject(
-            input_file, "Unsaved Document %d" % self._getUnsavedNum())
-        dotsproj.transcribeBraille(config_text)
+            document, "Unsaved Document %d" % self._getUnsavedNum())
+        dotsproj.transcribeBraille(config)
         self.main_notebook.append_page(dotsproj, dotsproj.tab_label)
         dotsproj.show_all()
 
diff --git a/dots/document.py b/dots/document.py
index 345b793..7ec8715 100644
--- a/dots/document.py
+++ b/dots/document.py
@@ -16,18 +16,22 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import translator
+from translator import Translator
 
 class Document():
     def __init__(self, input_file):
         self.input_file = input_file
+	self.braille_text = None
 	self.output_file = None
 
     def set_output_file (self, output_file):
 	self.output_file = output_file
 
     def translate(self, config):
-	translator = new Translator(config)
-	translator.translate (self.input_file, self.output_file)
+	translator = Translator(config)
+	self.braille_text = translator.translate (self.input_file)
+
+    def get_braille_text(self):
+	return self.braille_text
 
 	
diff --git a/dots/dots_project.py b/dots/dots_project.py
index a8a47dc..1758a83 100644
--- a/dots/dots_project.py
+++ b/dots/dots_project.py
@@ -20,7 +20,7 @@ import gtksourceview2, pango
 import mimetypes
 
 class DotsProject(gtk.ScrolledWindow):
-    def __init__(self, input_file, name):
+    def __init__(self, document, name):
         gtk.ScrolledWindow.__init__(self)
         self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
         self.view = gtksourceview2.View()
@@ -32,11 +32,11 @@ class DotsProject(gtk.ScrolledWindow):
         self.buffer = self.view.get_buffer()
         self.buffer.connect("modified-changed", self._onModified)
         self.braille_buffer = gtksourceview2.Buffer()
-        self.input_file = input_file
+        self.document = document
         self.tab_label = gtk.Label()
         self.set_name(name)
         self.out_file = None
-        self.config_text = None
+        self.config = None
 
     def set_name(self, name):
         gtk.ScrolledWindow.set_name(self, name)
@@ -48,8 +48,8 @@ class DotsProject(gtk.ScrolledWindow):
         else:
             self.tab_label.set_text(self.name)
 
-    def transcribeBraille(self, config_text):
-        self.config_text = config_text
+    def transcribeBraille(self, config):
+        self.config = config
         self._transcribeBraille()
 
     def view_ascii(self):
@@ -59,35 +59,12 @@ class DotsProject(gtk.ScrolledWindow):
         self.view.set_buffer(self.braille_buffer)
 
     def _transcribeBraille(self):
-        # Write config file.
-        fd, config_fn = tempfile.mkstemp('.config','dots_')
-        fconfig = os.fdopen(fd, 'w')
-        fconfig.write(self.config_text)
-        fconfig.close()
-
-        # Create a temporary out file.
-        outfile = tempfile.mktemp('.brl', 'dots_')
-
-        mimetype, ignore = mimetypes.guess_type(self.input_file)
-        if mimetype == 'application/msword':
-            argv = '%s -x db "%s" | %s -f %s > "%s"' % \
-                (host_settings.antiword, self.input_file, 
-                 host_settings.xml2brl, config_fn, outfile)
-        else:
-            argv = '%s -f %s < %s > "%s"' % \
-                (host_settings.xml2brl, config_fn, self.input_file, outfile)
-
-        os.system(argv)
-
-        # Write braille output to text buffer.
-        braille_file = open(outfile)
-        braille_text = braille_file.read()
+	self.document.translate (self.config)
+	
+        braille_text = self.document.get_braille_text() 
         self.buffer.set_text(braille_text)
-        braille_file.close()
 
         self.braille_buffer.set_text(
             ''.join([ascii_braille.ascii_to_braille.get(
                         x, '') for x in braille_text]))
         
-        os.remove(config_fn)
-        os.remove(outfile)
diff --git a/dots/import_assistant.py b/dots/import_assistant.py
index c7b0fa9..bd5a373 100644
--- a/dots/import_assistant.py
+++ b/dots/import_assistant.py
@@ -21,6 +21,7 @@ import gtk, glib
 import os, tempfile
 from config_builder import ConfigBuilder
 import host_settings
+from document import Document
 
 TABLES_DIR = host_settings.tablesdir
 
@@ -116,15 +117,12 @@ class ImportAssistant(object):
         text_buffer.set_text(str(self.config_builder))
 
     def _onAssistantApply(self, assistant):
-        input_file = \
-            self.main_xml.get_object('doc_file_choose_button').get_filename()
+	filename = self.main_xml.get_object('doc_file_choose_button').get_filename()
+	self.document = Document (filename)
+	
 
-        text_buffer = self.main_xml.get_object('config_textview').get_buffer()
-        config_text = text_buffer.get_text(text_buffer.get_start_iter(),
-                                           text_buffer.get_end_iter())
-        
         if self.main_app:
-            self.main_app.newProject(input_file, config_text)
+            self.main_app.translate(self.document, self.config_builder)
         else:
             print config_text
             print '-'*80
diff --git a/dots/translator.py b/dots/translator.py
index 9ddcb0d..8061644 100644
--- a/dots/translator.py
+++ b/dots/translator.py
@@ -16,9 +16,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import louisxml
+
 class Translator():
     def __init__(self, config):
         self.config = config
 
-    def translate(self, input_file, output_file):
+    def translate(self, input_file):
+	f = open (input_file)
+	return louisxml.translateString ("", f.read(),0)
+	
 



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