Re: Updating GtkCellRendererText after editing



On Mon, 2003-06-16 at 14:25, David M. Cook wrote:
On Mon, Jun 16, 2003 at 05:50:49PM +0200, Sylvain Daubert wrote:

Could someone explain me how i can update my cell ?

You need to set the newtext in the store.  This means you need to know which
column of the store is associated with that renderer.  You know this when
you're adding TreeViewColumns to the TreeView, and there are various ways to
pass this info around: as user data when connecting the signal, using
set_data on the renderer, as a global data structure, etc.  Excuse me for
thinking in Python:

cell = gtk.CellRendererText()
# j is the store column to take text from
# In C you'd probably use a pointer to a struct for user data.
cell.connect("edited", edited_callback, store, j) 
column = gtk.TreeViewColumn(colname, cell, text=j, ...)

Then in your callback:

def edited_callback(renderer, path_string, newtext, store, colno):
    path = tuple(path_string.split(':')) #gtk_tree_path_new_from_string
    iter = store.get_iter(path)
    store.set(iter, colno, newtext)

The API was not very well thought out here, IMO.  

If you go through all the considerations, I think you'll find it's
about the only way it *could* work. For example, the editable text
cell might not correspond to a column in the store at all, but
rather to some application data structure that is exposed via
'data_func'. 

I forget why the path_string is involved here rather than a path,
... it seems a bit strange to me at this point But the basic concept
of a callback to do the back connection from editing the view
to changing the model is unavoidable.

There is an example in C in gtk-demo.

Regards,
                                                Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]