Gtk: issue changing TreeView model to CellRendererCombo 'changed' signal

I have a treeview with CellRendererCombo in this column. I use the following code to customize a 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- this treeView, treeViewModelis its model, and comboModelis the model for a combo record containing only two lines.

If I run the code, the combo works as expected, except that when I select the record for the first time, 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()

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 the third time the program crashes. If I changed the connection line to:

crc.connect("edited", changed)

... then the code works fine. However, the value changes only after clicking on the combo box, and I would prefer it to change every time the object was selected. How can I do the latter?

EDIT: API docs pygtk:

, , , . , , , , - .

, . , , , , ENTER . ?

+3
2

CellRendererCombo .

, . , editing-started CellRenderer. Glade .

a focus-out-event changed CellRendererCombo.

, :

comboEditable = None

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"
    e = gtk.gdk.Event(gtk.gdk.FOCUS_CHANGE)
    e.window = treeView.window
    e.send_event = True
    e.in_ = False
    comboEditable.emit('focus-out-event', e)
def started(cell, editable, path):
    # Or to make life more predictable, use a class and set self.comboEditable
    global comboEditable
    comboEditable = editable
crc.connect('changed', changed)
crc.connect('editing-started', started)

treeView.append_column(cl)

, GTK + TreeModel changed. edited.

:

comboEditable = None

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):
    e = gtk.gdk.Event(gtk.gdk.FOCUS_CHANGE)
    e.window = treeView.window
    e.send_event = True
    e.in_ = False
    comboEditable.emit('focus-out-event', e)
def started(cell, editable, path):
    # Or to make life more predictable, use a class and set self.comboEditable
    global comboEditable
    comboEditable = editable
def edited(cell, path, newtext):
    treeViewModel[path][columnNumber] = newText
crc.connect('changed', changed)
crc.connect('editing-started', started)
crc.connect('edited', edited)

treeView.append_column(cl)
+1

, , - pygtk, , .

pygtk

0

Source: https://habr.com/ru/post/1760814/


All Articles