[pygtk] CellRenderCombobox and Treeview: how to get a column that is not showing.

Miguel Ángel García magmaxlistas at gmail.com
Fri Aug 8 13:36:24 WST 2008


Hello.

I'm using a TreeView with a CellRenderCombobox. The model of the
combobox has two columns that represents data from a database, so I
have an id and a text.

When I implements the "on_change" signal, the value I receive is only
the text, but I am not able to get the id.

Here you are a simplification of the code:

---------------------------------------------------------------------------------------
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
import gobject


def edit(cell, path, data, user_data=None):
    print cell, path, data, user_data
    if user_data:
        user_data[path][0]=data

w = gtk.Window()

#list store for cell
modelcell = gtk.ListStore(int, gobject.TYPE_STRING)
for x in range(1, 5):
    modelcell.append([x, "selection %d" % x])

#list store for treeview
modelstore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_OBJECT)
modelstore.append(("nothing selected 1", modelcell))
modelstore.append(("nothing selected 2", modelcell))

#Building the render
cb = gtk.CellRendererCombo()
cb.set_property("model",modelcell)
cb.set_property('text-column', 1)
cb.set_property('editable', gtk.TRUE)

#Setting signals
cb.connect('edited', edit, modelstore)

#Building treeview
# first: columns
c = gtk.TreeViewColumn("Test", cb)
c.set_attributes(cb, text = 0)
# second: treeview
t = gtk.TreeView()
t.append_column(c)
t.set_model(modelstore) 

#building the window
w.add(t)
w.show_all()
gtk.main()
---------------------------------------------------------------------------------------

As you can see, I try to print what tools I have at the 'edit'
function, but I have only the new value, not the new _ID_ value.

I think it must have a way to get the id only and, later, to access the
model to search the key and set the text, but if I try to change the
property "text-column" by setting 0:
cb.set_property('text-column', 0)
, it crashes.

Please... May somebody help me?

Thank very much.



-- 
In a world without walls and fences, who needs Windows and Gates?


More information about the pygtk mailing list