[dots] Saner table checking
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots] Saner table checking
- Date: Tue, 14 Sep 2010 02:15:42 +0000 (UTC)
commit 0121f14784bd66658e968fca59b23535df64dde3
Author: Fernando Herrera <fherrera onirica com>
Date: Tue Sep 14 03:09:42 2010 +0200
Saner table checking
Run lou_checktable to check for table integrity, copying
needed files (include opcode) into the destination dir for the
table.
New edited table is automatically selected.
dots/app_window.py | 69 ++++++++++++++++++++-------------------------
dots/table_editor.py | 76 ++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 99 insertions(+), 46 deletions(-)
---
diff --git a/dots/app_window.py b/dots/app_window.py
index 9edf5c1..b7ec1c9 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -20,6 +20,7 @@
import pygtk
import gtk, glib
import os, tempfile
+import subprocess
from config_builder import ConfigBuilder
import host_settings
import gettext
@@ -139,23 +140,13 @@ class AppWindow(object):
while True:
res = te.run()
if res == gtk.RESPONSE_OK:
- tmpfile = tempfile.NamedTemporaryFile (delete=False)
- te.save(tmpfile.name)
- table_ok = self._testTable(tmpfile.name)
- if not table_ok:
- dialog = self.main_xml.get_object("table_error_dialog")
- dialog.set_transient_for(te)
- dialog.run()
- dialog.hide()
- else:
- te.save_as()
- new_table = te.get_filename()
- path, file = os.path.split (new_table)
- os.chdir (path)
- eitem = self._addTable (self.submenu, file, True)
- eitem.activate()
- eitem.show()
- break
+ new_table = te.get_filename()
+ path, file = os.path.split (new_table)
+ os.chdir(path)
+ eitem = self._addTable (self.submenu, file, True)
+ eitem.activate()
+ eitem.show()
+ break
else:
break
te.destroy()
@@ -173,19 +164,6 @@ class AppWindow(object):
self.table_group = tableitem
return tableitem
- def _testTable(self,filename):
- path, file = os.path.split (filename)
- os.chdir (path)
- old_table = self.config_builder['translation']['literaryTextTable']
- self.config_builder['translation']['literaryTextTable'] = file
- test_translator = Translator(self.config_builder)
- if test_translator.translate_string("Test") == "":
- self.config_builder['translation']['literaryTextTable'] = old_table
- return False
- else:
- return True, ""
-
-
def _onTableOtherActivate(self, item):
chooser = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
@@ -193,20 +171,34 @@ class AppWindow(object):
filename = chooser.get_filename()
chooser.destroy()
if response == gtk.RESPONSE_OK:
- table_ok = self._testTable(filename)
- if not table_ok:
- dialog = self.main_xml.get_object("table_error_dialog")
- dialog.set_transient_for(self.window)
- dialog.run()
- dialog.hide()
- return
+ path, file = os.path.split (filename)
+ os.chdir (path)
+ #table_ok = self._testTable(filename)
+ #if not table_ok:
+ # dialog = self.main_xml.get_object("table_error_dialog")
+ # dialog.set_transient_for(self.window)
+ # dialog.run()
+ # dialog.hide()
+ # return
eitem = self._addTable (self.submenu, file, True)
eitem.activate()
eitem.show()
def _onTableActivate(self, item, table):
+ old_table = self.config_builder['translation']['literaryTextTable']
self.config_builder['translation']['literaryTextTable'] = table
+ p = subprocess.Popen(args=["lou_checktable",table], stderr=subprocess.PIPE)
+ p.wait()
+ if p.returncode != 0:
+ dialog = self.main_xml.get_object("table_error_dialog")
+ dialog.set_transient_for(self.window)
+ dialog.run()
+ dialog.hide()
+ self.config_builder['translation']['literaryTextTable'] = old_table
+ return
+
+
if self.document is not None:
self.translate (self.document, self.config_builder)
@@ -239,7 +231,8 @@ class AppWindow(object):
eitem = self._addTable (self.submenu, self.config_builder['translation']['literaryTextTable'], True)
eitem.activate()
else:
- self.submenu.set_active(1)
+ item = self.submenu.get_active()
+ item.activate()
diff --git a/dots/table_editor.py b/dots/table_editor.py
index 5c9d28f..7860f04 100755
--- a/dots/table_editor.py
+++ b/dots/table_editor.py
@@ -31,6 +31,9 @@ from dots import host_settings
import pygtk
import gtk
import re
+import tempfile
+import shutil
+import subprocess
import gettext
_ = gettext.gettext
@@ -335,33 +338,33 @@ class TableEditor(gtk.Dialog):
self.set_title("Liblouis Table Editor")
self.set_size_request(600, 600)
self.liststore = gtk.ListStore(str, str)
- treeview = gtk.TreeView(self.liststore)
+ self.treeview = gtk.TreeView(self.liststore)
tvcolumn = gtk.TreeViewColumn('opcode')
- treeview.append_column(tvcolumn)
+ self.treeview.append_column(tvcolumn)
cell = gtk.CellRendererText()
tvcolumn.pack_start(cell, True)
tvcolumn.add_attribute(cell, 'text', 0)
tvcolumn = gtk.TreeViewColumn('operands')
- treeview.append_column(tvcolumn)
+ self.treeview.append_column(tvcolumn)
cell = gtk.CellRendererText()
tvcolumn.pack_start(cell, True)
tvcolumn.add_attribute(cell, 'text', 1)
- treeview.connect("button-press-event", self.row_clicked)
+ self.treeview.connect("button-press-event", self.row_clicked)
scrolledwindow = gtk.ScrolledWindow ()
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- scrolledwindow.add(treeview)
+ scrolledwindow.add(self.treeview)
vbox = self.get_content_area()
buttonbox = gtk.HButtonBox()
buttonbox.set_layout(gtk.BUTTONBOX_START)
button = gtk.Button(_("Add"))
- button.connect("clicked", self.add_clicked, treeview)
+ button.connect("clicked", self.add_clicked, self.treeview)
buttonbox.pack_start(button, False, False, 6)
button = gtk.Button(_("Remove"))
- button.connect("clicked", self.remove_clicked, treeview)
+ button.connect("clicked", self.remove_clicked, self.treeview)
buttonbox.pack_start(button, False, False, 6)
vbox.pack_start(scrolledwindow, True, True, 6)
@@ -394,10 +397,15 @@ class TableEditor(gtk.Dialog):
if response == gtk.RESPONSE_OK:
self.filename = chooser.get_filename()
self.save(self.filename)
+ path, file = os.path.split (self.filename)
+ includes = self.get_includes()
+ for i in includes:
+ shutil.copy(host_settings.tablesdir + "/" + i, path)
+
chooser.destroy()
- return
+ return response
def add_clicked(self,button, view):
dialog = EditDialog (None, None)
@@ -439,6 +447,58 @@ class TableEditor(gtk.Dialog):
def get_filename(self):
return self.filename
+ def _get_include(self, model, path, iter, includes):
+ if model.get_value(iter, 0) == "include":
+ includes.append(model.get_value(iter, 1).partition(" ")[0])
+
+ def get_includes(self):
+ includes = []
+ self.liststore.foreach(self._get_include, includes)
+ return includes
+
+
+ def test_table(self):
+ tmpfile = tempfile.NamedTemporaryFile (delete=False)
+ self.save(tmpfile.name)
+ path, file = os.path.split (tmpfile.name)
+ includes = self.get_includes()
+ for i in includes:
+ shutil.copy(host_settings.tablesdir + "/" + i, path)
+ p = subprocess.Popen(args=["lou_checktable",tmpfile.name], stderr=subprocess.PIPE)
+ p.wait()
+ if p.returncode == 0:
+ return "ok"
+ else:
+ return p.stderr.readline()
+
+ def run(self):
+ res = gtk.Dialog.run(self)
+ if res != gtk.RESPONSE_OK:
+ return res
+ res = self.test_table()
+ if res == "ok":
+ res = self.save_as()
+ if res == gtk.RESPONSE_OK:
+ return gtk.RESPONSE_OK
+ else:
+ self.run()
+ else:
+ error = res.split(":", )
+ dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
+ _("Error in table at line ") + error[1] + ": " + error[2])
+ dialog.run()
+ dialog.destroy()
+ path = str(int(error[1]) - 1)
+ self.treeview.get_selection().select_path(path)
+ self.treeview.scroll_to_cell(path)
+ self.run()
+
+
+
+
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]