[pygtk] Liststore model
Volker Helm
Helm.volker at gmx.de
Sat Jan 13 00:33:53 WST 2007
Hi Chris,
I going to make this work next week. Thanks for your help, I never used the *-operator before, I think I'll change this.
Have a nice weekend,
Volker
-------- Original-Nachricht --------
Datum: Fri, 12 Jan 2007 09:52:10 -0500
Von: Chris Lambacher <chris at kateandchris.net>
An: Volker Helm <Helm.volker at gmx.de>
Betreff: Re: Re: [pygtk] Liststore model
> 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
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
More information about the pygtk
mailing list