[pygtk] ListStore question
euoar
euoar at yahoo.es
Tue Oct 24 17:18:28 WST 2006
I'm learning the use of liststores and treeviews. I have wrotten this
litle class as exercice:
#!/usr/bin/env python
#-*- coding: iso-8859-15 -*-
import pygtk
pygtk.require('2.0')
import gtk
class BasicTreeViewExample:
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.scrolled_window = gtk.ScrolledWindow(hadjustment=None,
vadjustment=None)
self.window.set_title("ejemplo")
self.window.set_size_request(600, 400)
self.window.connect("delete_event", self.delete_event)
# create a TreeStore with one string column to use as the model
self.liststore = gtk.ListStore(str)
# create the TreeView using liststore
self.treeview = gtk.TreeView(self.liststore)
self.scrolled_window.add(self.treeview)
self.window.add(self.scrolled_window)
self.window.show_all()
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
# name is the name of the new column to add, values is a tuple with
the values to add
def add_result (self, name, values):
self.iter = self.liststore.append(values[0])
for value in values:
self.liststore.insert_after(self.iter, value)
self.tvcolumn = gtk.TreeViewColumn(name)
# add tvcolumn to treeview
self.treeview.append_column(self.tvcolumn)
# create a CellRendererText to render the data
self.cell = gtk.CellRendererText()
# hacerlo editable y conectarlo al evento de edición
self.cell.set_property('editable', True)
self.cell.connect('edited', self.editado, self.liststore)
# add the cell to the tvcolumn and allow it to expand
self.tvcolumn.pack_start(self.cell, True)
# set the cell "text" attribute to column 0 - retrieve text
# from that column in treestore
self.tvcolumn.add_attribute(self.cell, 'text', 0)
# Allow sorting on the column
self.tvcolumn.set_sort_column_id(0)
self.window.show_all()
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
def editado(self, cell, path, new_text, modelo):
modelo[path][0] = new_text
def main():
gtk.main()
if __name__ == "__main__":
tvexample = BasicTreeViewExample()
valores = ['a', "4222"]
tvexample.add_result("columna", valores)
main()
The problm with is in the list with values that I pass to the method
add_result(). It admits only values with one char (example: "1", "4").
For any other value ("11", "44") it throws this exception: ValueError:
row sequence has wrong length.
I'm trying to understand where is my mistake, but unsucessfull. Any help
would be very apreciated.
In advance, thank you very much for your answers.
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
More information about the pygtk
mailing list