[pygtk] Error when adding longs into a GTK Treeview

Volker Helm Helm.volker at gmx.de
Fri Mar 2 16:10:53 WST 2007


There is an easy solution:

import gobject

liststore = gtk.ListStore(str, gobject.TYPE_INT64)

Not nice, because it doesn't work with long, but working.

Cheers,

Volker

-------- Original-Nachricht --------
Datum: Thu, 1 Mar 2007 13:28:50 -0500
Von: "Zach Tibbitts" <zach at collegegeek.org>
An: pygtk at daa.com.au
CC: 
Betreff: [pygtk] Error when adding longs into a GTK Treeview

> This may be sort of a long-winded post, so please bear with me.
> 
> Consider the following code:
> 
> import gtk
> 
> window = gtk.Window()
> treeview = gtk.TreeView()
> liststore = gtk.ListStore(str, long)
> treeview.set_model(liststore)
> treeview.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(),
> text=0))
> treeview.append_column(gtk.TreeViewColumn("Size", gtk.CellRendererText(),
> text=1))
> window.add(treeview)
> window.show_all()
> 
> liststore.append(["Foo", 100])
> try:
>     gtk.main()
> except KeyboardInterrupt:
>     pass
> 
> When run, it works just fine, and behaves as you expect it to.  However,
> if
> you append a value
> where the long is large enough, such as:
> 
>     liststore.append(["Foo", 9999999999])
> 
> Python throws an error:
> 
> Traceback (most recent call last):
>   File "tree.py", line 13, in <module>
>     liststore.append(["Foo", 9999999999])
> TypeError: value is of wrong type for this column
> 
> Even though 9999999999 is a valid long and Python has no problem handling
> it
> normally. The
> odd part, is that if you set up the ListStore to accept two strings, ie
> gtk.ListStore(str, str), and
> then you still pass it the (string, long) pair, it accepts the values just
> fine, regardless of how
> large the long is.  This is what I've done for the time being, to get my
> code to work, but the
> problem is that when you have a list of values, such as (1, 3, 200), and
> the
> ListStore interprets
> them as strings, the list will be sorted alphabetically, not numerically,
> so
> the list sorts to:
> (1, 200, 3).
> 
> My program winds up with a few very large values in the ListStore, which
> is
> how I ran into this
> problem, and I'd like to find a solution.
> 
> Thanks,
> 
> Zach
> -- 
> Zach Tibbitts - zach at collegegeek.org
> http://collegegeek.org

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser


More information about the pygtk mailing list