[pygtk] two treeview problems, this time with attachment

N. Volbers mithrandir42 at web.de
Tue Feb 21 06:01:10 WST 2006


Hello everyone on the list,

I have two questions regarding the treeview widget:

(1) (see attached sample script) Using a CellRendererCombo it is
possible to manipulate the model data by choosing a value from the
combo. Clicking on 'apply' in the sample script will dump the values in
the model to stdout. My problem occurs, if you try to modify a value by
selecting a value in the combo, and then you immediately click on apply
without leaving the combo. In this case the 'edited' signal of the
treeview is not emitted and the selected value in the combo is not set
in the model! However, at least for myself I would prefer this kind of
behaviour. Is there any way to force the treeview to finish any pending
edit operations?

(2) For some columns, I would like to have a button appear if you enter
the row, e.g. a little button with three dots indicating that if you
click on the button you will get a fancy dialog. I guess it would be
possible to write such a thing using a GenericCellRenderer, but I would
be very happy if anybody could point out existing code to me?

With best regards,

Niklas Volbers.


-------------- next part --------------

import gtk


model = gtk.ListStore(str)
for i in range(4):
    model.append((str(i),))

cell_model = gtk.ListStore(str)
for i in range(10):
    cell_model.append((str(i),))
    
treeview = gtk.TreeView(model)
cell = gtk.CellRendererCombo()
cell.set_property('text-column',0)
cell.set_property('model', cell_model)

def on_edited(cell,path,new_text,model,index):
    model[path][index]=new_text
cell.connect('edited', on_edited, model, 0)
cell.set_property('editable', True)

column = gtk.TreeViewColumn('a',cell)
column.set_attributes(cell, text=0)
treeview.append_column(column)

button = gtk.Button(stock=gtk.STOCK_APPLY)
def on_clicked(sender):#
    print "model values: "
    iter = model.get_iter_first()
    while iter is not None:
        print "  %s" % model[iter][0]
        iter = model.iter_next(iter)
button.connect('clicked', on_clicked)

vbox = gtk.VBox()
vbox.pack_start(treeview,True,True)
vbox.pack_start(button,False,True)

win = gtk.Window()
win.connect("destroy", gtk.main_quit)
win.add(vbox)
win.set_size_request(480,320)
win.show_all()
gtk.main()


More information about the pygtk mailing list