[pygtk] Liststore model
Seth Mahoney
smahoney at pdx.edu
Sat Jan 13 11:30:10 WST 2007
If this doesn't work, then I've got another idea (though I don't know if
it will work for you, either). You could try generating the liststore
with a str for every possible column, and then only show the columns you
need. So, if there were five different data items:
store = gtk.ListStore(str, str, str, str, str)
and then use gtk.TreeView.append_column() and
gtk.TreeView.remove_column() to hide and show columns as necessary.
OR (and I'm not sure this will work for you either), just have one
column, and create its data on the fly by joining strings. So:
store = gtk.ListStore(str)
store.append([data1 + " " + data2 + " " + data 3 ...)
On Fri, 2007-01-12 at 09:52 -0500, Chris Lambacher wrote:
> 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
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>
More information about the pygtk
mailing list