Reputation: 4917
i am having a issue with treeview liststore trying to get a real-time update, and I created a example to simulate what I'd like to do. I want liststore1 updated each loop.
http://img204.imageshack.us/i/capturadetela5.png/
it should update the treeview column 'speed' and give to it a different number every second, something like a download manager.
import gtk
import gtk.glade
import random
builder = gtk.Builder()
builder.add_from_file('ttt.glade')
window = builder.get_object('window1')
treeview = builder.get_object('treeview1')
store = builder.get_object('liststore1')
column_n = ['File','Size','Speed']
rendererText = gtk.CellRendererText()
for i in range(10):
foo = random.randint(100,256)
list_ = [('arquivo1.tar.gz', '10MB', '%s k/s' % foo)]
for x,y in zip(column_n,range(3)):
column = gtk.TreeViewColumn(x, rendererText, text=y)
column.set_sort_column_id(0)
treeview.append_column(column)
for list_index in list_:
store.append([list_index[0],list_index[1],list_index[2]])
window.show_all()
Upvotes: 1
Views: 2780
Reputation: 30332
If that's your full code, you're missing the GTK main loop invocation.
You need to do two things (in this order)
1 - Connect your window's destroy
signal to a function that calls gtk.main_quit()
def on_destroy(widget, user_data=None):
# Exit the app
gtk.main_quit()
window.connect('destroy', on_destroy)
2 - Start the GTK main loop:
gtk.main()
This is where your app is effectively launched, and it will appear to hang at this line until gtk.main_quit()
is called.
More generally... you should clean up the code a bit there :) Look at the "Hello World" demo from the PyGTK tutorial - it basically covers those points and more in greater detail. You'll find that following their general structure for things helps immensely.
If you want timed updates, look at the functions timeout_add and timeout_add_seconds - depending on your version of PyGTK/PyGobject these will be in the glib
or gobject
modules.
(Incidentally, GTKBuilder XML files typically have the .ui
extension, even though Glade doesn't know it.)
Upvotes: 2