Below an example program in which I try to make something like an
editable grid.
If you edit a field and press Enter or Tab, it should start editing the
next cell to the right.
From the documentation:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATreeView#set_cursor
"Additionally, if column is specified, and start_editing is true, then
editing should be started in the specified cell. "
I tried this in method connect_edit. I supplied both, the TreePath and
the “next” TreeViewColumn. Regardless how if the third option is true or
false, the next cell will only start editing after pressing spacebar.
Anyone has an idea what’s wrong?
#!/usr/bin/ruby
require ‘gtk2’
def connect_edit(renderer,i,view)
renderer.signal_connect(“edited”) do |rendr, row, new_text, model|
iter = view.model.get_iter(row)
iter[i] = new_text
view.set_cursor(Gtk::TreePath.new(row.to_s),view.get_column(i+1),true)
# if 3rd option ‘start_editing’ set to false it has the same effect
view.grab_focus
end
end
liststore = Gtk::ListStore.new(String, String, String, String, String,
String)
5.times do
iter = liststore.append
i = 0
6.times do
iter[i] = “bla”
i = i + 1
end
end
view = Gtk::TreeView.new(liststore)
i = 0
[“foo”,“bar”,“blah”,“more”,“spaceholder”,“stuff”].each do |c|
renderer = Gtk::CellRendererText.new
renderer.editable = true
connect_edit(renderer,i,view)
col = Gtk::TreeViewColumn.new(c, renderer, :text => i)
view.append_column col
i = i + 1
end
w = Gtk::Window.new
w << view
w.show_all
Gtk.main