[pygtk] Error when adding longs into a GTK Treeview

Zach Tibbitts zach at collegegeek.org
Fri Mar 2 03:28:50 WST 2007


This may be sort of a long-winded post, so please bear with me.

Consider the following code:

import gtk

window =3D gtk.Window()
treeview =3D gtk.TreeView()
liststore =3D gtk.ListStore(str, long)
treeview.set_model(liststore)
treeview.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(),
text=3D0))
treeview.append_column(gtk.TreeViewColumn("Size", gtk.CellRendererText(),
text=3D1))
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070301/f3c00d64/at=
tachment.htm


More information about the pygtk mailing list