Editable cells, does each column need its own renderer?

In the example that comes with ruby-gtk:
editable_cells.rb

each column gets its own renderer and each renderer is given a column
number so that when the renderer gets the ‘edited’ signal, it already
knows which data is being edited because it can get the iterator [row]
and it already knows the column number.

So I’m wondering, is there any way to re-use renderers for many
columns yet still allow the data to be editable? If so, how can I get
the column number for the cell that is being edited in an ‘edited’
signal handler?

btw, the docs say: “Typically, one cell renderer is used to draw many
cells on the screen. To this extent, it isn’t expected that a
CellRenderer keep any permanent state around.”

-Alex


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

I don’t think you can get the column back from the edited signal(At
least not as far as I can see). I think you’ll be stuck using multiple
renderers unless you do something fancy like catching the column from a
button press event.

Maybe something like (Untested and probably buggy):

@column = nil

mytreeview.signal_connect(“button-press-event”) do |treeview, event|
if(event.event_type == Gdk::Event::BUTTON2_PRESS and event.button ==
1)
[1, 2, 3, 4].each do |i| #1, 2, 3, 4 are the editable columns.
rect = treeview.get_cell_area(nil, treeview.get_column(i))
@column = i if(!(event.x > rect.x and event.x < rect.x +
rect.width))
end
end
end

e_rendr.signal_connect(“edited”, mymodel) do |rendr,row,new_text, model|
if(new_text != model.get_iter(row)[@column])
model.get_iter(row)[@column]=new_text
end
end

Conan

Alex wrote:

In the example that comes with ruby-gtk:
editable_cells.rb

each column gets its own renderer and each renderer is given a column
number so that when the renderer gets the ‘edited’ signal, it already
knows which data is being edited because it can get the iterator [row]
and it already knows the column number.

So I’m wondering, is there any way to re-use renderers for many
columns yet still allow the data to be editable? If so, how can I get
the column number for the cell that is being edited in an ‘edited’
signal handler?

btw, the docs say: “Typically, one cell renderer is used to draw many
cells on the screen. To this extent, it isn’t expected that a
CellRenderer keep any permanent state around.”

-Alex


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/