2010/3/18 Vermeersch Simon <[email protected]>:
> 2010/3/18 Julián Alarcón <[email protected]>:
>> Hi guys, I don't know if this is the right place to bother you with
>> this support ask.
>>
>> I'm making a little app that takes data from PostgreSQL and show it on
>> a TreeView. But, I need to update the data every 5 minutes, but I
>> don't know how to make this. I tried some while loops but the window
>> didn't appear.
>>
>> This is the code: http://paste.ubuntu.com/397321/
>>
>> And this is a little screenshot: http://i42.tinypic.com/14yaazs.jpg
>>
>> Thanks!
>> _______________________________________________
>> pygtk mailing list [email protected]
>> http://www.daa.com.au/mailman/listinfo/pygtk
>> Read the PyGTK FAQ: http://faq.pygtk.org/
>>
>
> You can use the gobject.timeout_add function to update your treeview.
> Something like that:
>
> def __init__(self):
> ....
> gobject.timeout_add(300000, self.refresh_treeview)
>
> def refresh_treeview(self):
> #reload your data and refresh the treeview here
> return True
>
>
> --
> Simon Vermeersch
>
################################
Hi Simon, I just made some changes and add this:
def refresh_treeview(self):
try:
conexiondb = psycopg2.connect("dbname='databas' user='user'
host='172.16.0.1' password='password'");
print "Conexion exitosa"
except:
print "No se pudo conectar a la base de datos"
gtk.main_quit()
cursor = conexiondb.cursor()
cursor.execute("SELECT * FROM datos_aplicacion")
consulta = cursor.fetchall()
datos = gtk.TreeStore(str,str,str,str,str,str,str,str,str,str)
for fila in consulta:
print fila[0], fila[1], fila[2], fila[3], fila[4], fila[5],
fila[6],
fila[7], fila[8], fila[9]
datos.append(None,
[fila[0],fila[1],fila[2],fila[3],fila[4],fila[5],fila[6],fila[7],fila[8],fila[9]])
self.treeview = gtk.TreeView(datos)
# create a CellRendererText to render the data
self.cell = gtk.CellRendererText()
# add the cell to the tvcolumn and allow it to expand
self.tvcolumna1.pack_start(self.cell, True)
self.tvcolumna2.pack_start(self.cell, True)
self.tvcolumna3.pack_start(self.cell, True)
self.tvcolumna4.pack_start(self.cell, True)
self.tvcolumna5.pack_start(self.cell, True)
self.tvcolumna6.pack_start(self.cell, True)
self.tvcolumna7.pack_start(self.cell, True)
self.tvcolumna8.pack_start(self.cell, True)
self.tvcolumna9.pack_start(self.cell, True)
self.tvcolumna10.pack_start(self.cell, True)
# set the cell "text" attribute to column 0 - retrieve text
# from that column in treestore
self.tvcolumna1.add_attribute(self.cell, 'text', 0)
self.tvcolumna2.add_attribute(self.cell, 'text', 1)
self.tvcolumna3.add_attribute(self.cell, 'text', 2)
self.tvcolumna4.add_attribute(self.cell, 'text', 3)
self.tvcolumna5.add_attribute(self.cell, 'text', 4)
self.tvcolumna6.add_attribute(self.cell, 'text', 5)
self.tvcolumna7.add_attribute(self.cell, 'text', 6)
self.tvcolumna8.add_attribute(self.cell, 'text', 7)
self.tvcolumna9.add_attribute(self.cell, 'text', 8)
self.tvcolumna10.add_attribute(self.cell, 'text', 9)
self.window.show_all()
return True
################################
The output of my sql query is working, but the refresh of TreeView is
not working, I just need that. Can you help me? Where is my mistake?
Thanks for your help, my app is getting close to my wish :)
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/