hi everybody, I been looking for a way to extend the gtk.ListStore to avoid the data replication, with this I mean that for example I have Photo class with uri property (where is located the photo), and other things, one way is construct a classic gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT) and iterate over my list of Photo instances and read the uri and size and append to the ListStore, but If something changes inside some of the instances I will have to update the ListStore, so I don't want to do this. The other way that I found (the one that I want to implent) is proposed by Davyd Madeley[0], but it doesn't work, I attached a small test case.
how do you handle the ListStore to avoid data replication?, somebody has some tip to do with pygtk the same that davyd does with gobject? thanks indvance. [0] http://davyd.livejournal.com/252351.html this is the output of my test case. my_list_store.py:98: GtkWarning: gtk_list_store_get_value: assertion `column < list_store->n_columns' failed self.show_all() my_list_store.py:98: Warning: g_object_set_property: assertion `G_IS_VALUE (value)' failed self.show_all() my_list_store.py:98: Warning: g_value_unset: assertion `G_IS_VALUE (value)' failed self.show_all() my_list_store.py:104: GtkWarning: gtk_list_store_get_value: assertion `column < list_store->n_columns' failed gtk.main() my_list_store.py:104: Warning: g_object_set_property: assertion `G_IS_VALUE (value)' failed gtk.main() my_list_store.py:104: Warning: g_value_unset: assertion `G_IS_VALUE (value)' failed gtk.main() -- Felipe Reyes Astorga counter.li.org #316380
##
## my_list_store.py
## Login : <[EMAIL PROTECTED]>
## Started on Wed Jul 2 10:55:18 2008 Felipe Reyes
## $Id$
##
## Copyright (C) 2008 Felipe Reyes
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import gobject
import gtk
import random
class Photo(gobject.GObject, object):
"""Contains the information of a photo
"""
def __init__(self, id):
super(Photo, self).__init__()
self.id = id
self.uri = str("test://%d" % (self.id))
self.size = random.randint(1, 100)
gobject.type_register(Photo)
class PhotoListStore (gtk.ListStore):
def __init__ (self):
super(PhotoListStore, self).__init__(Photo)
self._col_types = [Photo, # Photo
gobject.TYPE_STRING, # Pixbuf
gobject.TYPE_INT] # uri
def get_n_columns(self):
return len(self._col_types)
def get_column_type(self, index):
return self._col_types[index]
def get_value(self, iter, column):
obj = gtk.ListStore.get_value (self, iter, 0)
if column == 0:
return obj
elif column == 1:
return obj.uri
elif column == 2:
return obj.size
else:
return None
gobject.type_register(PhotoListStore)
class Window(gtk.Window):
def __init__(self):
super(Window, self).__init__(gtk.WINDOW_TOPLEVEL)
liststore = PhotoListStore()
liststore.clear()
for i in range(10):
picture = Photo(random.randint(1, 100))
liststore.append([picture])
treeview = gtk.TreeView(liststore)
col = gtk.TreeViewColumn("uri")
treeview.append_column(col)
cell = gtk.CellRendererText()
col.pack_start(cell)
col.add_attribute(cell, "text", 1)
col = gtk.TreeViewColumn("uri")
treeview.append_column(col)
cell = gtk.CellRendererText()
col.pack_start(cell)
col.add_attribute(cell, "text", 2)
self.add(treeview)
self.show_all()
gobject.type_register(Window)
if __name__ == '__main__':
Window()
gtk.main()
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
_______________________________________________ pygtk mailing list [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
