[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
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, 
        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)

    # close the window and quit
    def delete_event(self, widget, event, data=None):
        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
        # 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

    # close the window and quit
    def delete_event(self, widget, event, data=None):
    def editado(self, cell, path, new_text, modelo):
        modelo[path][0] = new_text

def main():

if __name__ == "__main__":
    tvexample = BasicTreeViewExample()
    valores = ['a', "4222"]
    tvexample.add_result("columna", valores)

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. 

More information about the pygtk mailing list