from gi.repository import Gtk, GObject
import time

class CellRendererToggleWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(200, 200)
        self.liststore = Gtk.ListStore(object)
        treeview = Gtk.TreeView(model=self.liststore)

        render = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn("foo", render)

        def cell_data(column, cell, model, iter_, data):
            value = model.get_value(iter_, 0)
            cell.set_property('text', str(value))

        column.set_cell_data_func(render, cell_data)
        treeview.append_column(column)

        def fill_model(*args):
            t = time.time()
            treeview.set_model(None)

            self.liststore.clear()
            obj = object()
            insert = self.liststore.insert_with_valuesv
            columns = [0]
            for i in range(20000):
                insert(-1, columns, [obj])

            treeview.set_model(self.liststore)
            print("time need to fill the model: %f" % (time.time() - t))

        button = Gtk.Button("Fill")
        button.connect("clicked", fill_model)

        box = Gtk.VBox()
        sw = Gtk.ScrolledWindow()
        sw.add(treeview)
        box.pack_start(sw, True, True, 0)
        box.pack_start(button, False, True, 0)

        self.add(box)

win = CellRendererToggleWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
