[dots/remove-assistant: 22/38] Add combo for opcodes
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots/remove-assistant: 22/38] Add combo for opcodes
- Date: Thu, 15 Jul 2010 21:08:50 +0000 (UTC)
commit 104adace2ef4a9ea25688d836ae14fb75866d091
Author: Fernando Herrera <fherrera onirica com>
Date: Mon Jul 12 20:51:33 2010 +0200
Add combo for opcodes
dots/table_editor.py | 170 ++++++++++++++++++++++++++++++-------------------
1 files changed, 104 insertions(+), 66 deletions(-)
---
diff --git a/dots/table_editor.py b/dots/table_editor.py
index 868cb3c..8c87609 100755
--- a/dots/table_editor.py
+++ b/dots/table_editor.py
@@ -22,10 +22,12 @@
# * operands validation
# * saving
# * translate non UTF-8 entries
+# * check "=" in dots
import os
from sys import exit
+from sys import argv
import host_settings
import gtk
import re
@@ -173,30 +175,6 @@ class Parser():
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:")
- self.combo = gtk.ComboBox()
- self.model = gtk.ListStore (str)
- for k in opcodes.keys():
- iter = self.model.append ([k])
- cell = gtk.CellRendererText()
- 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 (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)
-
@@ -217,13 +195,13 @@ class EditDialog(gtk.Dialog):
"dots..." : re.compile(r"(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+(,(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+)*"),
"dotpattern..." : re.compile(r"(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+(,(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+)*"),
"dots[,dots]" : re.compile(r"(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+(,(0|1|2|3|4|5|6|7|8|9|-|a|b|c|d|e|f)+)?"),
+ #action
}
- self.opcode = opcode
self.entries = []
- if self.opcode is None:
+ if opcode is None:
d = OpDialog()
d.run()
- self.opcode = d.get_opcode()
+ opcode = d.get_opcode()
d.destroy()
operands_list = []
@@ -235,50 +213,105 @@ class EditDialog(gtk.Dialog):
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()
- entry.set_data("opcode", s)
- entry.connect("insert-text", self.validate_text)
- self.entries.append(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)
-
- if len(operands_list) > 0:
- hbox = gtk.HBox (False, 6)
- label = gtk.Label ("Comments")
- entry = gtk.Entry()
- entry.set_data("opcode", "comments")
- self.entries.append(entry)
- operands_list.reverse()
- entry.set_text (" ".join (operands_list).lstrip(" "))
- hbox.pack_start (label)
- hbox.pack_start (entry)
- vbox.pack_start (hbox)
-
+ self.add_opcode_combo(vbox, opcode)
+ comments = self.add_entries_for_opcode(vbox, opcode, operands_list)
+ self.add_comments (vbox, comments)
self.get_content_area().add (vbox)
self.show_all()
- def get_opcode(self):
- return self.opcode
+ def add_comments(self, vbox, comments):
+ hbox = gtk.HBox (False, 6)
+ label = gtk.Label ("Comments")
+ entry = gtk.Entry()
+ entry.set_data("opcode", "comments")
+ self.entries.append(entry)
+ hbox.pack_start (label)
+ hbox.pack_start (entry)
+ vbox.pack_start (hbox)
+ if len(comments) > 0:
+ comments.reverse()
+ entry.set_text (" ".join (comments).lstrip(" "))
+
+
+ def combo_changed(self, combo):
+ remove = False
+ for w in list(self.entries):
+ vbox = w.get_parent().get_parent()
+ hbox = w.get_parent()
+ if remove:
+ vbox.remove(hbox)
+ self.entries.remove(w)
+ if w == combo:
+ remove = True
+ opcode = combo.get_model().get_value(combo.get_active_iter(), 0)
+ vbox = combo.get_parent().get_parent()
+ self.add_entries_for_opcode (vbox, opcode, [])
+ self.add_comments (vbox, [])
+ vbox.show_all()
+
+ def add_opcode_combo(self, vbox, opcode):
+ label = gtk.Label ("opcode:")
+ combo = gtk.ComboBox()
+ model = gtk.ListStore (str)
+ cell = gtk.CellRendererText()
+ combo.pack_start(cell, True)
+ combo.add_attribute(cell, 'text', 0)
+ combo.set_model (model)
+ for k in opcodes.keys():
+ iter = model.append ([k])
+ if k == opcode: combo.set_active_iter (iter)
+ combo.connect("changed", self.combo_changed)
+ hbox = gtk.HBox (False, 6)
+ hbox.pack_start (label)
+ hbox.pack_start (combo)
+ vbox.add (hbox)
+ self.entries.append(combo)
- def get_operands(self):
+
+ def add_entries_for_opcode(self, vbox, opcode, operands_list):
+ print opcode
+ schema = opcodes[opcode]
+ for s in schema:
+ if s == "opcode":
+ self.add_opcode_combo(vbox, operands_list.pop())
+ self.add_entries_for_opcode(vbox, operands_list)
+ else:
+ hbox = gtk.HBox (False, 6)
+ label = gtk.Label (s)
+ entry = gtk.Entry()
+ entry.set_data("opcode", s)
+ entry.connect("insert-text", self.validate_text)
+ self.entries.append(entry)
+ print "Adding entry for " + s
+ 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)
+ vbox.show_all()
+ return operands_list
+
+
+
+
+ def get_contents(self):
operands = ""
+ c = self.entries.pop(0)
+ iter = c.get_active_iter()
+ opcode = c.get_model().get_value(iter, 0)
for e in self.entries:
- operands += e.get_text() + " "
- return operands
+ print e
+ if isinstance(e, gtk.Entry):
+ print e.get_text()
+ operands += e.get_text() + " "
+ elif isinstance(e, gtk.ComboBox):
+ iter = e.get_active_iter()
+ operands += e.get_model().get_value(iter, 0)
+ return opcode, operands
+
def validate_text(self, entry, string, len, position):
opcode = entry.get_data("opcode")
@@ -307,8 +340,9 @@ def row_clicked(view, event):
response = dialog.run()
if response == gtk.RESPONSE_ACCEPT:
- model.set_value (iter, 0, dialog.get_opcode())
- model.set_value (iter, 1, dialog.get_operands())
+ opcode, operands = dialog.get_contents()
+ model.set_value (iter, 0, opcode)
+ model.set_value (iter, 1, operands)
dialog.destroy()
def add_clicked(button, view):
@@ -335,7 +369,11 @@ 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")
+
+if argv[1]:
+ parser = Parser (argv[1])
+else:
+ 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]