[pygtk] Liststore and Decimal

Juan Pablo Daniel jpdborgna at gmail.com
Thu Jan 10 01:33:03 WST 2008


I finally make it work using object for the type. I added a cell
renderer wich sets "text" to str(myDecimal)

On Jan 7, 2008 6:29 PM, Juan Pablo Daniel <jpdborgna at gmail.com> wrote:
> On Jan 7, 2008 5:44 PM, Johan Dahlin <johan at gnome.org> wrote:
> > On Jan 7, 2008 3:33 PM, Juan Pablo Daniel <jpdborgna at gmail.com> wrote:
> > > Hello list! Its my first post here.
> > > I am wanting to store a Decimal() object in a list store but dont know
> > > what type of column use.
> >
> > Can you live with having values truncated a bit? If so using a float
> > column would probably be the best option.
> No, i cant. :( i would like to, but no.
> > You could also use a string column, but then you will get alphabetical
> > sorting and not numerical.
> >
> > Perhaps object is an option, but I am unsure if sorting and
> > representation will be sufficient for you.
> > Just try float, string and object and see what kind of behavior they give you.
> >
>
> The behavior is what you say, whit float everthing is fine but the
> rounding errors i get, with string the sorting is alphanumeric, but it
> is fine, but the prograrm have too much types conversiong and parsing
> for going from string to decimal.
> With type object dosnt work or i am doing wrong:
>
> > /home/giba/tachikoma/Salida.py(91)fill_stock()
> -> self.stock_store = gtk.ListStore( str,gobject.TYPE_OBJECT)
> (Pdb) n
> > /home/giba/tachikoma/Salida.py(92)fill_stock()
> -> for a in r:
> (Pdb) n
> > /home/giba/tachikoma/Salida.py(93)fill_stock()
> -> self.stock_store.append(a);
> (Pdb) p r
> (('MODEM1', Decimal("100.00")), ('MODEM2', Decimal("200.00")),
> ('MODEM3', Decimal("300.00")), ('MODEM4', Decimal("400.00")))
> (Pdb) p a
> ('MODEM1', Decimal("100.00"))
> (Pdb) n
> TypeError: 'value is of wrong type for this column'
> > /home/giba/tachikoma/Salida.py(93)fill_stock()
> -> self.stock_store.append(a);
> (Pdb)
>
> Any idea?
> Thanks.
>
> Saludos, Juan Pablo.
>
> > Johan
> >
>


More information about the pygtk mailing list