[pygtk] realtime update of TreeView

John Stowers john.stowers.lists at gmail.com
Sat May 9 17:28:44 WST 2009


On Fri, 2009-05-08 at 17:24 +0200, Martin B. wrote:
> hi, i write some simple app where i need realtime update gtk.TreeView.
> but window shows and long time nothing happened and after whole
> liststore is filled treeview shown :(
> 
> need i use threads for this ?
> theres a little example.
> thanks a lot for your help
> 
> 
> import gtk, sys, gobject
> 
> class myapp(gtk.Window):
>     def __init__(self):
>         super(myapp, self).__init__()
>         self.set_size_request(300, 400)
>         self.connect('destroy', gtk.main_quit)
>         
>         render = gtk.CellRendererText()
>         self.lst = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING)
>         #self.lst.connect('row-inserted', self.row_inserted)
>         view = gtk.TreeView(self.lst)
>         view.insert_column_with_attributes( -1, "No.", render, markup=0)
>         view.insert_column_with_attributes( -1, "Name", render, text=1)
>         
>         scroll = gtk.ScrolledWindow()
>         scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
>         scroll.add_with_viewport(view)
>         
>         self.add(scroll)
>         self.show_all()
>         self.fill_list()

I think this is considered doing it wrong. 

You should either
a) Fill the model first and then add it to the view
b) Inhibit the row-inserted signal to improve perfomance, if you insert
many many rows at once.

I can't find a link ATM, but I think the PyGTK FAQ and treeview tutorial
covers both these ideas

John

>         
>     def fill_list(self):
>         """ fill up liststore """
>         # do some more complex not this
>         for data in xrange(1, 20000):
>             self.lst.append([data, "Name: %d" % data])
>         
>     def row_inserted(self, widget, value, treeiter):
>         """ if row is inserted into lst """
>         #gobject.idle_add(self.scroll_row)
>         pass
>         
>     def scroll_row(self):
>         pass
> 
>         
> APP = myapp()
> gtk.main()
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/



More information about the pygtk mailing list