[dots/remove-assistant: 18/38] tableditor: Add ande remove buttons
- From: Fernando Herrera de las Heras <fherrera src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dots/remove-assistant: 18/38] tableditor: Add ande remove buttons
- Date: Thu, 15 Jul 2010 21:08:30 +0000 (UTC)
commit 61210f172e36623a89b06b263b0d5d553b4e4f5c
Author: Fernando Herrera <fherrera onirica com>
Date: Fri Jul 9 19:58:49 2010 +0200
tableditor: Add ande remove buttons
dots/table_editor.py | 113 ++++++++++++++++++++++++++++++++++----------------
1 files changed, 77 insertions(+), 36 deletions(-)
---
diff --git a/dots/table_editor.py b/dots/table_editor.py
index 6ab2ceb..c7b8e40 100755
--- a/dots/table_editor.py
+++ b/dots/table_editor.py
@@ -179,42 +179,45 @@ for e in entries:
import gtk
-def row_clicked(view, event):
- if event.type != gtk.gdk._2BUTTON_PRESS:
- return
+def create_edit_dialog (opcode, operands):
+ if opcode is None:
+ dialog = gtk.Dialog ("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)
+ for k in opcodes.keys():
+ iter = 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)
+ 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()
+
- selection = view.get_selection();
- model, iter = selection.get_selected()
- opcode = model.get_value (iter, 0)
- operands = model.get_value (iter, 1)
- operands_list = operands.split(" ")
- operands_list.reverse()
- print "Operands: " + operands
- if operands_list is None:
- operands_list = [ operands ]
- print "Operands list: "
- for l in operands_list: print "\t" + l
+
+
+
+ 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)
- hbox = gtk.HBox (False, 6)
- label = gtk.Label ("opcode:")
- combo = gtk.ComboBox()
- model = gtk.ListStore (str)
- for k in opcodes.keys():
- iter = model.append ([k])
- if k == opcode:
- thisiter = iter
-
- cell = gtk.CellRendererText()
- combo.pack_start(cell, True)
- combo.add_attribute(cell, 'text', 0)
- combo.set_model (model)
- combo.set_active_iter (thisiter)
-
- hbox.pack_start (label)
- hbox.pack_start (combo)
- vbox.pack_start (hbox)
+ label = gtk.Label ("opcode: " + opcode)
+ vbox.pack_start (label)
schema = opcodes[opcode]
for s in schema:
@@ -222,9 +225,10 @@ def row_clicked(view, event):
hbox = gtk.HBox (False, 6)
label = gtk.Label (s)
entry = gtk.Entry()
- operand = ""
- while operand == "": operand = operands_list.pop()
- entry.set_text (operand)
+ 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)
@@ -243,11 +247,35 @@ def row_clicked(view, event):
dialog.get_content_area().add (vbox)
+ return dialog
+
+
+def row_clicked(view, event):
+ if event.type != gtk.gdk._2BUTTON_PRESS:
+ return
+
+ selection = view.get_selection();
+ model, iter = selection.get_selected()
+ opcode = model.get_value (iter, 0)
+ operands = model.get_value (iter, 1)
+ dialog = create_edit_dialog (opcode, operands)
+
+ dialog.show_all()
+ response = dialog.run()
+ dialog.destroy()
+
+def add_clicked(button, view):
+ dialog = create_edit_dialog (None, None)
dialog.show_all()
response = dialog.run()
dialog.destroy()
+def remove_clicked(button, view):
+ selection = view.get_selection();
+ model, iter = selection.get_selected()
+ model.remove(iter)
+
@@ -275,7 +303,20 @@ treeview.connect("button-press-event", row_clicked)
scrolledwindow = gtk.ScrolledWindow ()
scrolledwindow.add(treeview)
-window.add(scrolledwindow)
+
+vbox = gtk.VBox ()
+buttonbox = gtk.HButtonBox()
+button = gtk.Button("Add")
+button.connect("clicked", add_clicked, treeview)
+buttonbox.pack_start(button, False, False, 6)
+button = gtk.Button("Remove")
+button.connect("clicked", remove_clicked, treeview)
+buttonbox.pack_start(button, False, False, 6)
+vbox.pack_start(scrolledwindow, True, True, 6)
+vbox.pack_start(buttonbox, False, False, 6)
+
+
+window.add(vbox)
window.show_all()
gtk.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]