[dots] Move TableEditor as a subwindow of main app
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots] Move TableEditor as a subwindow of main app
- Date: Tue, 20 Jul 2010 05:11:44 +0000 (UTC)
commit 9cfdba22f757af4e386635f8006901dfd899eb8b
Author: Fernando Herrera <fherrera onirica com>
Date: Fri Jul 16 15:23:26 2010 +0200
Move TableEditor as a subwindow of main app
* Table validation on table editor
* Autoselect last edited table if it is valid
bin/Makefile.am | 2 +-
data/app_window.xml | 126 ++++++++++++++++++---------
dots/Makefile.am | 3 +-
dots/app_window.py | 82 +++++++++++++++---
bin/dotstableeditor => dots/table_editor.py | 70 +++++----------
dots/translator.py | 2 +-
6 files changed, 180 insertions(+), 105 deletions(-)
---
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 6425422..f896a53 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -1,4 +1,4 @@
-bin_SCRIPTS = dots dotscmd dotstableeditor
+bin_SCRIPTS = dots dotscmd
CLEANFILES = $(bin_SCRIPTS)
diff --git a/data/app_window.xml b/data/app_window.xml
index 0ea9b2a..358d150 100644
--- a/data/app_window.xml
+++ b/data/app_window.xml
@@ -2,20 +2,24 @@
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkMessageDialog" id="notext-dialog">
+ <object class="GtkMessageDialog" id="table_error_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="message_type">error</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>
+ <property name="text" translatable="yes">The selected table is not valid</property>
+ <property name="secondary_text" translatable="yes">The selected table cannot be used by
+liblouisxml. Please make sure that if you
+are using "include" directive, those files
+are placed in the same directory as the table</property>
+ <property name="secondary_use_markup">True</property>
<child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox1">
+ <object class="GtkVBox" id="dialog-vbox3">
<property name="visible">True</property>
<property name="spacing">2</property>
<child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
+ <object class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
@@ -34,39 +38,6 @@
</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>
@@ -227,13 +198,21 @@
<object class="GtkMenu" id="menu5">
<property name="visible">True</property>
<child>
- <object class="GtkMenuItem" id="tables_menuitem">
+ <object class="GtkMenuItem" id="select_table_menuitem">
<property name="visible">True</property>
- <property name="label" translatable="yes">_Table</property>
+ <property name="label" translatable="yes">_Select Table</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
+ <object class="GtkMenuItem" id="edit_table_menuitem">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit current Table...</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="_OnTranslationEditTableActivate" swapped="no"/>
+ </object>
+ </child>
+ <child>
<object class="GtkMenuItem" id="menuitem7">
<property name="visible">True</property>
<property name="label" translatable="yes">_Format...</property>
@@ -359,4 +338,69 @@
</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>
+ <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>
</interface>
diff --git a/dots/Makefile.am b/dots/Makefile.am
index 643d96c..03709d3 100644
--- a/dots/Makefile.am
+++ b/dots/Makefile.am
@@ -13,7 +13,8 @@ dots_PYTHON = \
odtdocument.py \
xmldocument.py \
document_builder.py \
- translator.py
+ translator.py \
+ table_editor.py
DISTCLEANFILES = host_settings.py
diff --git a/dots/app_window.py b/dots/app_window.py
index 00fdab8..b449d76 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -27,6 +27,8 @@ from dots_project import DotsProject
from document_builder import document_new
import gconf
import gtkunixprint
+from table_editor import TableEditor
+from translator import Translator
import gettext
gettext.bindtextdomain(host_settings.DOMAIN,host_settings.LOCALE_DIR)
@@ -37,6 +39,7 @@ class AppWindow(object):
def __init__(self):
self.project = None
self.document = None
+ self.table_group = None
self.main_xml = gtk.Builder()
self.main_xml.set_translation_domain(host_settings.DOMAIN)
self.main_xml.add_from_file (
@@ -124,26 +127,81 @@ class AppWindow(object):
dialog.hide()
+ def _OnTranslationEditTableActivate(self, item):
+ te = TableEditor (self.window)
+ table = self.config_builder['translation']['literaryTextTable']
+ if table.startswith('/'):
+ te.open(table)
+ else:
+ te.open(os.path.join(host_settings.tablesdir, table))
+ te.set_transient_for(self.window)
+ te.show_all()
+ 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
+ else:
+ break
+ te.destroy()
+
+
+
- def _addTable(self, submenu, group, table, prepend=False):
- tableitem = gtk.RadioMenuItem(group, table)
+ def _addTable(self, submenu, table, prepend=False):
+ tableitem = gtk.RadioMenuItem(self.table_group, table)
tableitem.connect("activate", self._onTableActivate, table)
if prepend:
submenu.prepend (tableitem)
else:
submenu.append (tableitem)
+ self.table_group = tableitem
return tableitem
- def _onTableOtherActivate(self, item, group):
+ 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))
response = chooser.run()
filename = chooser.get_filename()
chooser.destroy()
if response == gtk.RESPONSE_OK:
- path, file = os.path.split (filename)
- os.chdir (path)
- eitem = self._addTable (self.submenu, group, file, True)
+ 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()
@@ -157,7 +215,7 @@ class AppWindow(object):
def _populateTablesMenu(self):
def _sepatatorFunc(model, itr):
return model[itr][0] == None
- menuitem = self.main_xml.get_object('tables_menuitem')
+ menuitem = self.main_xml.get_object('select_table_menuitem')
#Fixme, dont make this global, use get_menu at _onTableOtherActivate
self.submenu = gtk.Menu()
menuitem.set_submenu(self.submenu)
@@ -167,18 +225,18 @@ class AppWindow(object):
group = None
found = False
for table in table_list:
- group = self._addTable (self.submenu, group, table)
+ item = self._addTable (self.submenu, table)
if table == self.config_builder['translation']['literaryTextTable']:
- group.activate()
+ item.activate()
found = True
othermenu = gtk.MenuItem("Other...")
- othermenu.connect_after("activate", self._onTableOtherActivate, group)
+ othermenu.connect_after("activate", self._onTableOtherActivate)
self.submenu.append(othermenu)
if not found:
if os.access (self.config_builder['translation']['literaryTextTable'], os.R_OK):
- eitem = self._addTable (self.submenu, group, self.config_builder['translation']['literaryTextTable'], True)
+ eitem = self._addTable (self.submenu, self.config_builder['translation']['literaryTextTable'], True)
eitem.activate()
else:
self.submenu.set_active(1)
@@ -323,7 +381,7 @@ class AppWindow(object):
if not res:
dialog = self.main_xml.get_object('notext-dialog')
dialog.run()
- dialog.destroy()
+ dialog.hide()
action = self.main_xml.get_object('action_save_as')
action.set_sensitive(res)
diff --git a/bin/dotstableeditor b/dots/table_editor.py
similarity index 87%
rename from bin/dotstableeditor
rename to dots/table_editor.py
index d7e0c51..5c9d28f 100755
--- a/bin/dotstableeditor
+++ b/dots/table_editor.py
@@ -32,6 +32,10 @@ import pygtk
import gtk
import re
+import gettext
+_ = gettext.gettext
+
+
opcodes = {
"include": ["filename"],
"locale": ["characters"],
@@ -324,10 +328,10 @@ class EditDialog(gtk.Dialog):
-class TableEditor(gtk.Window):
- def __init__(self, type=gtk.WINDOW_TOPLEVEL):
+class TableEditor(gtk.Dialog):
+ def __init__(self, parent=None):
self.filename = None
- gtk.Window.__init__(self, type)
+ gtk.Dialog.__init__(self, "Edit op", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
self.set_title("Liblouis Table Editor")
self.set_size_request(600, 600)
self.liststore = gtk.ListStore(str, str)
@@ -350,44 +354,21 @@ class TableEditor(gtk.Window):
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolledwindow.add(treeview)
- vbox = gtk.VBox ()
+ vbox = self.get_content_area()
buttonbox = gtk.HButtonBox()
buttonbox.set_layout(gtk.BUTTONBOX_START)
- button = gtk.Button("Add")
+ button = gtk.Button(_("Add"))
button.connect("clicked", self.add_clicked, treeview)
buttonbox.pack_start(button, False, False, 6)
- button = gtk.Button("Remove")
+ button = gtk.Button(_("Remove"))
button.connect("clicked", self.remove_clicked, treeview)
buttonbox.pack_start(button, False, False, 6)
- uimanager = gtk.UIManager()
- accelgroup = uimanager.get_accel_group()
- self.add_accel_group(accelgroup)
- ui = '''<ui><menubar name="MenuBar">
- <menu action="File">
- <menuitem action="open"/>
- <menuitem action="save"/>
- <menuitem action="save_as"/>
- <menuitem action="quit"/>
- </menu>
- </menubar> </ui>'''
- actiongroup = gtk.ActionGroup('TableEditor')
- actiongroup = actiongroup
- actiongroup.add_actions([('File', None, '_File', None, 'File', None),
- ('open', gtk.STOCK_OPEN, '_Open', None, 'Open File', self.open_cb),
- ('save', gtk.STOCK_SAVE, '_Save', None, 'Save File', self.save_cb),
- ('save_as', gtk.STOCK_SAVE_AS, 'Save _as', None, 'Save File as', self.save_as_cb),
- ('quit', gtk.STOCK_QUIT, '_Quit', None, 'Quit the Program', self.quit_cb)])
-
- uimanager.insert_action_group(actiongroup, 0)
- uimanager.add_ui_from_string(ui)
- menubar = uimanager.get_widget('/MenuBar')
- vbox.pack_start(menubar, False)
-
vbox.pack_start(scrolledwindow, True, True, 6)
vbox.pack_start(buttonbox, False, False, 6)
- self.add(vbox)
+ self.add_button(_("Finish editing"), gtk.RESPONSE_OK)
+
def _write_line(self, model, path, iter, f):
line = model.get_value(iter, 0) + " " + model.get_value(iter, 1) + "\n"
@@ -406,21 +387,8 @@ class TableEditor(gtk.Window):
iter = self.liststore.append ([e['opcode'], e['operands']])
-
- def open_cb(self, item):
- chooser = gtk.FileChooserDialog(title="Choose a table file", action=gtk.FILE_CHOOSER_ACTION_OPEN,
- buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
- chooser.set_current_folder(host_settings.tablesdir)
- response = chooser.run()
- if response == gtk.RESPONSE_OK:
- self.filename = chooser.get_filename()
- self.open(self.filename)
- chooser.destroy()
-
- def save_cb(self, item):
- self.save(self.filename)
- def save_as_cb(self, item):
- chooser = gtk.FileChooserDialog(title="Choose a table file", action=gtk.FILE_CHOOSER_ACTION_SAVE,
+ def save_as(self):
+ chooser = gtk.FileChooserDialog(title="Save the table", action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
response = chooser.run()
if response == gtk.RESPONSE_OK:
@@ -430,8 +398,6 @@ class TableEditor(gtk.Window):
return
- def quit_cb(self, item):
- gtk.main_quit()
def add_clicked(self,button, view):
dialog = EditDialog (None, None)
@@ -439,7 +405,8 @@ class TableEditor(gtk.Window):
response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
model = view.get_model()
- iter = model.append((dialog.get_opcode(), dialog.get_operands()))
+ opcode, operands = dialog.get_contents()
+ iter = model.append((opcode, operands))
selection = view.get_selection()
selection.select_iter(iter)
view.scroll_to_cell(model.get_path(iter))
@@ -469,6 +436,9 @@ class TableEditor(gtk.Window):
model.set_value (iter, 1, operands)
dialog.destroy()
+ def get_filename(self):
+ return self.filename
+
@@ -476,6 +446,8 @@ class TableEditor(gtk.Window):
if __name__ == "__main__":
+ gettext.bindtextdomain(host_settings.DOMAIN,host_settings.LOCALE_DIR)
+ gettext.textdomain(host_settings.DOMAIN)
te = TableEditor()
te.show_all()
if len(argv) > 1:
diff --git a/dots/translator.py b/dots/translator.py
index 4e6b94d..49ef2e5 100644
--- a/dots/translator.py
+++ b/dots/translator.py
@@ -20,6 +20,7 @@ import louisxml
import tempfile
import os
+
class Translator():
def __init__(self, config):
self.config = config
@@ -37,5 +38,4 @@ class Translator():
res = louisxml.translateString (cfgfile.name, buffer, 0)
os.unlink(cfgfile.name)
return res
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]