views:

74

answers:

0

I have a treeview with a CellRendererCombo in a given column. I use the following code to set up the column:

crc = gtk.CellRendererCombo()
crc.set_property('model', comboModel)
crc.set_property('text-column', 0)
crc.set_property('editable', True)
crc.set_property('has_entry', False)
cl = gtk.TreeViewColumn(ctitle, crc, text=i)

def changed(cell, path, newiter):
    treeViewModel[path][0] = "HAH"
crc.connect("changed", changed)

treeView.append_column(cl)

treeView is a TreeView, treeViewModel is its model, and comboModel is the model for the combo entry containing just two strings.

If I run the code, then the combo works as expected, except that the first time I select an entry I get the following errors:

c:\python25\lib\site-packages\twisted\internet\gtk2reactor.py:255: Warning: inva
lid unclassed pointer in cast to `GObject'
  gtk.main()
c:\python25\lib\site-packages\twisted\internet\gtk2reactor.py:255: Warning: g_ob
ject_notify: assertion `G_IS_OBJECT (object)' failed
  gtk.main()

On the second time I get:

c:\python25\lib\site-packages\twisted\internet\gtk2reactor.py:255: Warning: inva
lid uninstantiatable type `<invalid>' in cast to `GObject'
  gtk.main()

and on the third time the program crashes. If I change the connect line to:

crc.connect("edited", changed)

...then the code works fine. However, the value only changes after clicking out of the combo box, and I'd rather have it change every time an object is selected. How can I do the latter?

EDIT: I just noticed this in the API docs for pygtk:

Note that as soon as you change the model displayed in the tree view, the tree view will immediately cease the editing operating. This means that you most probably want to refrain from changing the model until the combo cell renderer emits the edited or editing_canceled signal.

It doesn't mention that the code would crash, though. In any case, I'd like it that after clicking an entry in the combobox, editing stops, without having to press ENTER or click somewhere else. How can I accomplish that?