[dots] Add support for new text files (editable)



commit 93ccf4b11dd32bc7cdb9ca8a486d4be10a36ee38
Author: Fernando Herrera <fherrera onirica com>
Date:   Thu Dec 2 00:53:32 2010 +0100

    Add support for new text files (editable)

 data/app_window.xml      |   51 ++++++++++++++++++++++++++++++++++++++++++++++
 dots/Makefile.am         |    1 +
 dots/app_window.py       |   30 ++++++++++++++++++++++++++-
 dots/document_builder.py |    5 ++++
 dots/textdocument.py     |   34 ++++++++++++++++++++++++++++++
 5 files changed, 120 insertions(+), 1 deletions(-)
---
diff --git a/data/app_window.xml b/data/app_window.xml
index 201b5fd..74cae9f 100644
--- a/data/app_window.xml
+++ b/data/app_window.xml
@@ -66,6 +66,17 @@
     <property name="stock_id">gtk-open</property>
     <signal name="activate" handler="_onOpen" swapped="no"/>
   </object>
+  <object class="GtkAction" id="action_new">
+    <property name="tooltip">New text</property>
+    <property name="stock_id">gtk-new</property>
+    <signal name="activate" handler="_onNew" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_translate">
+    <property name="tooltip">Translate</property>
+    <property name="stock_id">gtk-convert</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onTranslate" swapped="no"/>
+  </object>
   <object class="GtkActionGroup" id="file_actions"/>
   <object class="GtkWindow" id="window1">
     <property name="default_width">480</property>
@@ -86,6 +97,14 @@
                 <child type="submenu">
                   <object class="GtkMenu" id="menu1">
                     <property name="visible">True</property>
+ 		    <child>
+                      <object class="GtkImageMenuItem" id="menu_new">
+                        <property name="visible">True</property>
+                        <property name="related_action">action_new</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
                     <child>
                       <object class="GtkImageMenuItem" id="menu_open">
                         <property name="visible">True</property>
@@ -183,6 +202,14 @@
                   <object class="GtkMenu" id="menu5">
                     <property name="visible">True</property>
                     <child>
+                      <object class="GtkMenuItem" id="translate">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Translate</property>
+                        <property name="related_action">action_translate</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
                       <object class="GtkMenuItem" id="select_table_menuitem">
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">_Select Table</property>
@@ -247,6 +274,18 @@
           <object class="GtkToolbar" id="toolbar1">
             <property name="visible">True</property>
             <child>
+              <object class="GtkToolButton" id="toolbutton4">
+                <property name="visible">True</property>
+                <property name="related_action">action_new</property>
+                <property name="label">toolbutton4</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkToolButton" id="toolbutton1">
                 <property name="visible">True</property>
                 <property name="related_action">action_open</property>
@@ -271,6 +310,18 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToolButton" id="toolbutton5">
+                <property name="visible">True</property>
+                <property name="related_action">action_translate</property>
+                <property name="label">toolbutton5</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkToolButton" id="toolbutton3">
                 <property name="visible">True</property>
                 <property name="related_action">action_print</property>
diff --git a/dots/Makefile.am b/dots/Makefile.am
index 03709d3..78e514d 100644
--- a/dots/Makefile.am
+++ b/dots/Makefile.am
@@ -12,6 +12,7 @@ dots_PYTHON = \
 	pdfdocument_pypoppler.py \
 	odtdocument.py \
 	xmldocument.py \
+	textdocument.py \
 	document_builder.py \
 	translator.py \
 	table_editor.py
diff --git a/dots/app_window.py b/dots/app_window.py
index 30e36bc..ef57993 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -268,6 +268,33 @@ class AppWindow(object):
 		self.addDocument (self.document)
 		self.translate (self.document, self.config_builder)
 
+    def _onNew(self, action):
+	view = self.main_xml.get_object('textview1')
+	view.set_sensitive(True)
+	view.set_editable(True)
+	self.document = document_new (None)
+	self.addDocument (self.document)
+	action = self.main_xml.get_object('action_translate')
+	action.set_sensitive(True)
+	self.statusbar = self.main_xml.get_object('statusbar1')
+	context_id = self.statusbar.get_context_id("text file")
+	self.statusbar.push(context_id, _("Text editable"))
+
+    def _onTranslate(self, action):
+	# We are translating the text buffer, so set it to the document
+	action = self.main_xml.get_object('action_translate')
+	action.set_sensitive(False)
+	context_id = self.statusbar.get_context_id("text file")
+	self.statusbar.pop(context_id)
+	view = self.main_xml.get_object('textview1')
+	view.set_editable(False)
+	buffer = view.get_buffer()
+	self.document.set_text (buffer.get_text(
+                                self.project.buffer.get_start_iter(),
+                                self.project.buffer.get_end_iter()))
+	self.translate(self.document, self.config_builder)
+	
+	
     def _OnRevisionLine(self, item):
 	reviewentry = self.main_xml.get_object('reviewentry')
 	if item.get_active():
@@ -366,7 +393,8 @@ class AppWindow(object):
             self.project.view_ascii()
         else:
             self.project.view_braille()
-	self.window.set_title("Dots - " + os.path.basename(document.input_file))
+	if document.input_file is not None:
+		self.window.set_title("Dots - " + os.path.basename(document.input_file))
 	self.project.connect("line-changed", self._onLineChanged)
 
     def translate(self, document, config):
diff --git a/dots/document_builder.py b/dots/document_builder.py
index 1f4144b..fc2d0dc 100644
--- a/dots/document_builder.py
+++ b/dots/document_builder.py
@@ -20,6 +20,7 @@ import mimetypes
 from document import Document
 from odtdocument import OdtDocument
 from xmldocument import XmlDocument
+from textdocument import TextDocument
 try:
 	from pdfdocument_gi import PdfDocument
 except:
@@ -27,6 +28,10 @@ except:
 	pass
 
 def document_new(filename):
+	if filename is None:
+		doc = TextDocument(None)
+		return doc
+
 	mime_type, encoding = mimetypes.guess_type (filename)
 	if mime_type == "application/pdf":
 		doc = PdfDocument(filename)
diff --git a/dots/textdocument.py b/dots/textdocument.py
new file mode 100644
index 0000000..624873b
--- /dev/null
+++ b/dots/textdocument.py
@@ -0,0 +1,34 @@
+# Dots - A braille translation program.
+#
+# Copyright (C) 2010 Consorcio Fernando de los Rios
+#		Author: Fernando Herrera <fherrera onirica com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from document import Document
+from translator import Translator
+
+class TextDocument(Document):
+
+    def set_text(self, text):
+	self.text = text;
+
+    def translate(self, config):
+	self.translator = Translator(config)
+	if self.input_file is not None:
+		self.braille_text = self.translator.translate_file (self.input_file)
+	else:
+		self.braille_text = self.translator.translate_string (self.text)
+
+



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