[pygtk] Liststore model

Chris Lambacher chris at kateandchris.net
Fri Jan 12 23:52:10 WST 2007


On Fri, Jan 12, 2007 at 03:32:05PM +0100, Volker Helm wrote:
> Hi Jarek,
> 
> > > 1. A select is send to a database:
> > > cur.execute("select position,article,name,amount,value from
> > table_bill_pos")
> > > pos = cur.fetchall()
> > > 
> > > 2. depending on the result, I generate the model:
> > > listmodel = gtk.ListStore(int,str,str,str,str)
columns = [int, str, str, int]
listmodel = gtk.ListStore(*columns)
columns.append(str)
listmodel = gtk.ListStore(*columns)


see http://docs.python.org/tut/node6.html#SECTION006740000000000000000

> > > 
> > > 3. create the TreeView:
> > > tv = gtk.TreeView(listmodel)
> > > 
> > > My problem is the second part, since I've got many queries against the
> > database and changing the queries quite often. 
> > > So, I want to generate the _listmodel_ dynamically. Next time, maybe the
> > query could be something like (int,str,str,str,str,str,int), because I
> > added two  columns.
> > 
> > Cursor objects have description. It's a tuple, where second element is
> > typecode. You can build your ListStore using that information.
> 
> that sound great, but I'm blocked. I using cur.description to get the information of each column (type and header). But I don't know a way to generate the gtk.ListStore() dynamically.
See my comments above
> 
> Can you give me some code that shows the way of doing it. I tried to generate a basic gtk.ListStore(int) model, then appending further columns, but I could get it work. 
> 
> If I solve this problem, I would make a little tutorial about this, maybe someone has similar problems.
> 
> Thanks you,

Your welcome,
Chris


More information about the pygtk mailing list