Hi,

I'm trying to create an auto editable gtk.TreeView. What I mean with 'auto' is that 
you don't have to press the 'Enter' key when you are on a particular cell to make it 
editable. Just moving around the cells should make them editable (think in widgets 
like the ones used in spreadsheet programs).

There are two steps to make this possible with gtk.TreeView:

1. When the cursor moves you have to make the new cell editable
2. When we go out of a editable cell we need to move the cursor to the next cell. Here 
'next' depends on the key the user presses to go out of the editable cell.

I'm currently working on step 1 and I was succesfull with a small demo in C. The funny 
thing is that exactly the same code in Python doesn't work. I'll attach both codes and 
I'll try to explain what I think is happening:

What I do is connect_after the 'move-cursor' signal of the gtk.TreeView to a callback. 
In this callback I retrieve the current cursor and call treeview.set_cursor(path, 
column, start_editing=gtk.TRUE), which should make that cell editable if we trust the 
API doc. Note: I use the connect_after and not the connect method because the default 
signal handler is the one which actually move the cursor and if our callback is called 
first we would be working with the old cursor.

The commented line in the Python code is a nasty hack that make it works. It simply 
add a timeout that set the cursor, instead of setting the cursor in the 'move-cursor' 
callback. You can uncomment it to see what I mean.

I suppose this is a bug in PyGTK (since the C code works) but I'm not sure so I want 
some comments before filling a bug report.

By the way, any clue to implement step 2 is greatly welcomed :)

Regards

Lorenzo

Attachment: editable-treeview.c
Description: Binary data

import pygtk
pygtk.require('2.0')
import gtk
import gobject
def move_cursor(treeview, step, count):
    path, column = treeview.get_cursor()
    treeview.set_cursor(path, column, gtk.TRUE)
#    gobject.timeout_add(100, lambda t, p, c: t.set_cursor(p, c, gtk.TRUE),
#                        treeview, path, column)
def test():
    window = gtk.Window()
    window.connect('destroy', lambda e: gtk.main_quit())
    window.set_default_size(300,300)

    model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT,
                          gobject.TYPE_BOOLEAN)
    model.append(['foo1', 23, gtk.TRUE])
    model.append(['foo2', 24, gtk.TRUE])
    model.append(['foo3', 25, gtk.TRUE])
    treeView = gtk.TreeView(model)
    treeView.connect_after('move-cursor', move_cursor)
    renderer = gtk.CellRendererText()
    column = gtk.TreeViewColumn('column 1', renderer, text=0, editable=2)
    column.set_flags(gtk.CAN_FOCUS)
    treeView.append_column(column)
    renderer = gtk.CellRendererText()
    column = gtk.TreeViewColumn('column 2', renderer, text=1, editable=2)
    column.set_flags(gtk.CAN_FOCUS)
    treeView.append_column(column)
    treeView.show()
    window.add(treeView)
    window.show()
    gtk.main()
if __name__ == '__main__':
    test()

-----------------------------7d3126720140
Content-Disposition: form-data; name="x"

22
-----------------------------7d3126720140
Content-Disposition: form-data; name="y"

4
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to