[dots/remove-assistant: 19/38] table_editor: refactor
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots/remove-assistant: 19/38] table_editor: refactor
- Date: Thu, 15 Jul 2010 21:08:35 +0000 (UTC)
commit dea44d0035912b64beb85af73cb3e5dfa8822f1f
Author: Fernando Herrera <fherrera onirica com>
Date: Fri Jul 9 20:30:55 2010 +0200
table_editor: refactor
dots/table_editor.py | 174 ++++++++++++++++++++++++--------------------------
1 files changed, 83 insertions(+), 91 deletions(-)
---
diff --git a/dots/table_editor.py b/dots/table_editor.py
index c7b8e40..4115c3c 100755
--- a/dots/table_editor.py
+++ b/dots/table_editor.py
@@ -20,19 +20,7 @@
import os
from sys import exit
import host_settings
-
-def cell_started_editing (cell, editable, path, model, col):
- iter = model.get_iter(path)
- op = model.get_value (iter, 0)
- if op == "include" and col > 1 and col < 3:
- editable.set_property("editable", False)
- else:
- editable.set_property("editable", True)
-
-
-def cell_edited (cell, path, text, model, col):
- iter = model.get_iter(path)
- model.set_value (iter, col, text)
+import gtk
opcodes = {
"include": ["filename"],
@@ -157,97 +145,101 @@ opcodes = {
"nobreak": [] }
-filename = "/opt/gnome/share/liblouis/tables/Es-Es-g1.utb"
-lines = open(filename, 'r').readlines()
-
-entries = []
-for line in lines:
- line = line.lstrip(" ")
- line = line.replace("\t", " ")
- if line == '' or line[0] == '#' or line[0] == '<' or line[0] == '\n':
- continue
- sep = line.find(" ")
- entry = {}
- entry['opcode'] = line[:sep]
- entry['operands'] = line[sep+1:].rstrip(" \t\n")
- entries.append (entry)
-
-for e in entries:
- print "op=" + e['opcode']
- print "\toperands=" + e['operands']
-
-
-import gtk
-
-def create_edit_dialog (opcode, operands):
- if opcode is None:
- dialog = gtk.Dialog ("Select opcode", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+class Parser():
+ def __init__ (self, filename):
+ self.filename = filename
+
+ def get_entries (self):
+ lines = open(self.filename, 'r').readlines()
+
+ entries = []
+ for line in lines:
+ line = line.lstrip(" ")
+ line = line.replace("\t", " ")
+ if line == '' or line[0] == '#' or line[0] == '<' or line[0] == '\n':
+ continue
+ sep = line.find(" ")
+ entry = {}
+ entry['opcode'] = line[:sep]
+ entry['operands'] = line[sep+1:].rstrip(" \t\n")
+ entries.append (entry)
+ return entries
+
+class OpDialog(gtk.Dialog):
+ def __init__(self):
+ gtk.Dialog.__init__ (self, "Select opcode", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
hbox = gtk.HBox (False, 6)
label = gtk.Label ("opcode:")
- combo = gtk.ComboBox()
- model = gtk.ListStore (str)
+ self.combo = gtk.ComboBox()
+ self.model = gtk.ListStore (str)
for k in opcodes.keys():
- iter = model.append ([k])
+ iter = self.model.append ([k])
cell = gtk.CellRendererText()
- combo.pack_start(cell, True)
- combo.add_attribute(cell, 'text', 0)
- combo.set_model (model)
- combo.set_active(0)
+ self.combo.pack_start(cell, True)
+ self.combo.add_attribute(cell, 'text', 0)
+ self.combo.set_model (self.model)
+ self.combo.set_active(0)
hbox.pack_start (label)
- hbox.pack_start (combo)
- dialog.get_content_area().add (hbox)
- dialog.show_all()
- response = dialog.run ()
- iter = combo.get_active_iter()
- opcode = model.get_value (iter, 0)
- dialog.destroy()
+ hbox.pack_start (self.combo)
+ self.get_content_area().add (hbox)
+ self.show_all()
+
+ def get_opcode(self):
+ iter = self.combo.get_active_iter()
+ return self.model.get_value (iter, 0)
-
+
+class EditDialog(gtk.Dialog):
+ def __init__(self, opcode=None, operands=None):
+ self.opcode = opcode
+ if self.opcode is None:
+ d = OpDialog()
+ d.run()
+ self.opcode = d.get_opcode()
+ d.destroy()
- operands_list = []
- if operands is not None:
- operands_list = operands.split(" ")
- operands_list.reverse()
- if operands_list is None:
- operands_list = [ operands ]
- dialog = gtk.Dialog ("Edit op", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
- (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
- vbox = gtk.VBox (False, 6)
- label = gtk.Label ("opcode: " + opcode)
- vbox.pack_start (label)
+ operands_list = []
+ if operands is not None:
+ operands_list = operands.split(" ")
+ operands_list.reverse()
+ if operands_list is None:
+ operands_list = [ operands ]
+ gtk.Dialog.__init__(self, "Edit op", None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
+ vbox = gtk.VBox (False, 6)
+ label = gtk.Label ("opcode: " + self.opcode)
+ vbox.pack_start (label)
+
+ schema = opcodes[self.opcode]
+ for s in schema:
+ print s
+ hbox = gtk.HBox (False, 6)
+ label = gtk.Label (s)
+ entry = gtk.Entry()
+ if len(operands_list) > 0:
+ operand = ""
+ while operand == "": operand = operands_list.pop()
+ entry.set_text (operand)
+ hbox.pack_start (label)
+ hbox.pack_start (entry)
+ vbox.pack_start (hbox)
- schema = opcodes[opcode]
- for s in schema:
- print s
- hbox = gtk.HBox (False, 6)
- label = gtk.Label (s)
- entry = gtk.Entry()
if len(operands_list) > 0:
- operand = ""
- while operand == "": operand = operands_list.pop()
- entry.set_text (operand)
- hbox.pack_start (label)
- hbox.pack_start (entry)
- vbox.pack_start (hbox)
+ hbox = gtk.HBox (False, 6)
+ label = gtk.Label ("Comments")
+ entry = gtk.Entry()
+ operands_list.reverse()
+ entry.set_text (" ".join (operands_list).lstrip(" "))
+ hbox.pack_start (label)
+ hbox.pack_start (entry)
+ vbox.pack_start (hbox)
- if len(operands_list) > 0:
- hbox = gtk.HBox (False, 6)
- label = gtk.Label ("Comments")
- entry = gtk.Entry()
- operands_list.reverse()
- entry.set_text (" ".join (operands_list).lstrip(" "))
- hbox.pack_start (label)
- hbox.pack_start (entry)
- vbox.pack_start (hbox)
-
-
-
- dialog.get_content_area().add (vbox)
- return dialog
+ self.get_content_area().add (vbox)
+ self.show_all()
def row_clicked(view, event):
@@ -258,15 +250,13 @@ def row_clicked(view, event):
model, iter = selection.get_selected()
opcode = model.get_value (iter, 0)
operands = model.get_value (iter, 1)
- dialog = create_edit_dialog (opcode, operands)
+ dialog = EditDialog (opcode, operands)
- dialog.show_all()
response = dialog.run()
dialog.destroy()
def add_clicked(button, view):
- dialog = create_edit_dialog (None, None)
- dialog.show_all()
+ dialog = EditDialog (None, None)
response = dialog.run()
dialog.destroy()
@@ -283,6 +273,8 @@ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("Basic TreeView Example")
window.set_size_request(600, 600)
liststore = gtk.ListStore(str, str)
+parser = Parser ("/opt/gnome/share/liblouis/tables/Es-Es-g1.utb")
+entries = parser.get_entries()
for e in entries:
iter = liststore.append ([e['opcode'], e['operands']])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]