[dots/remove-assistant: 26/38] talbe_editor: Add a menu for opening and saving. Fix validation regs
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots/remove-assistant: 26/38] talbe_editor: Add a menu for opening and saving. Fix validation regs
- Date: Thu, 15 Jul 2010 21:09:10 +0000 (UTC)
commit aecca3f7928350fe14f36f7f4c6bb304710ebff7
Author: Fernando Herrera <fherrera onirica com>
Date: Wed Jul 14 19:14:53 2010 +0200
talbe_editor: Add a menu for opening and saving. Fix validation regs
dots/table_editor.py | 101 ++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 82 insertions(+), 19 deletions(-)
---
diff --git a/dots/table_editor.py b/dots/table_editor.py
index acc9857..54820d5 100755
--- a/dots/table_editor.py
+++ b/dots/table_editor.py
@@ -26,7 +26,6 @@
import os
-from sys import exit
from sys import argv
import host_settings
import gtk
@@ -181,8 +180,8 @@ class Parser():
class EditDialog(gtk.Dialog):
def __init__(self, opcode=None, operands=None):
self.opcode_valid_regexs = {
- "character" : re.compile(r".|\\|\\f|\\n|\\r|\\s|\\t|\\v|\\e|\\(a|b|c|d|e|f|A|B|C|D|E|F){1,8}"),
- "characters" : re.compile(r"(.|\\|\\f|\\n|\\r|\\s|\\t|\\v|\\e|\\(a|b|c|d|e|f|A|B|C|D|E|F){1,8})+"),
+ "character" : re.compile(r"^.$|(^\\(f?|n?|r?|s?|t?v?|e?)$)|^\\x(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,4}$|^\\y(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,5}$|^\\z(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,8}$"),
+ "characters" : re.compile(r"(.|(\\(f?|n?|r?|s?|t?v?|e?))|\\x(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,4}|\\y(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,5}|\\z(a|b|c|d|e|f|A|B|C|D|E|F|[0-9]){0,8})+"),
"filename" : re.compile(r".*"),
"dots" : re.compile(r"(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+"),
"name" : re.compile(r"([a-z]*[A-Z]*)*"),
@@ -317,7 +316,7 @@ class EditDialog(gtk.Dialog):
return
else:
m = self.opcode_valid_regexs[opcode].match(text)
- if m and m.group() == text:
+ if m:
return
entry.emit_stop_by_name("insert-text")
@@ -358,17 +357,13 @@ def remove_clicked(button, view):
class TableEditor(gtk.Window):
- def __init__(self, table, type=gtk.WINDOW_TOPLEVEL):
+ def __init__(self, type=gtk.WINDOW_TOPLEVEL):
+ self.filename = None
gtk.Window.__init__(self, type)
self.set_title("Liblouis Table Editor")
self.set_size_request(600, 600)
- liststore = gtk.ListStore(str, str)
- parser = Parser (table)
- entries = parser.get_entries()
- for e in entries:
- iter = liststore.append ([e['opcode'], e['operands']])
-
- treeview = gtk.TreeView(liststore)
+ self.liststore = gtk.ListStore(str, str)
+ treeview = gtk.TreeView(self.liststore)
tvcolumn = gtk.TreeViewColumn('opcode')
treeview.append_column(tvcolumn)
cell = gtk.CellRendererText()
@@ -396,21 +391,89 @@ class TableEditor(gtk.Window):
button = gtk.Button("Remove")
button.connect("clicked", 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)
-if __name__ == "__main__":
+ def _write_line(self, model, path, iter, f):
+ line = model.get_value(iter, 0) + " " + model.get_value(iter, 1) + "\n"
+ f.write(line)
+
+ def save(self, file):
+ f = open(file, 'w')
+ self.liststore.foreach(self._write_line, f)
+ f.close()
+
+ def open(self, file):
+ self.liststore.clear()
+ parser = Parser (file)
+ entries = parser.get_entries()
+ for e in entries:
+ iter = self.liststore.append ([e['opcode'], e['operands']])
- if argv[1]:
- file = argv[1]
- else:
- file = "/opt/gnome/share/liblouis/tables/Es-Es-g1.utb"
- te = TableEditor(file)
+
+ 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,
+ buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
+ response = chooser.run()
+ if response == gtk.RESPONSE_OK:
+ self.filename = chooser.get_filename()
+ self.save(self.filename)
+ chooser.destroy()
+
+
+ return
+ def quit_cb(self, item):
+ gtk.main_quit()
+
+
+
+if __name__ == "__main__":
+
+ te = TableEditor()
te.show_all()
+ if len(argv) > 1:
+ te.open(argv[1])
+
gtk.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]