[pygtk] TreeView / ListStore question: tabbing through coulmns
Jordan Callicoat
monkeesage at gmail.com
Thu Feb 1 06:48:35 WST 2007
Hi list,
I have a callback connected to a treeview (liststore model,
editable) for 'key_press_event', and I want to capture 'Tab' key
presses and move from one column to the next. I have this working; the
problem is, when the current cell is being edited, and I call
'set_cursor' to move to the next column, the text from the original
cell is not updated. I think I need to emit the 'edited' signal on the
cellrenderer before I call 'set_cursor', but I'm running into the
problem of getting the updated text from the cell in order to pass it to
emit. How can I do this properly? Here's the callback:
def on_key_press(self, widget, event):
keyname = gtk.gdk.keyval_name(event.keyval)
if keyname == 'Tab': # event.keyval = 65289
row, col = widget.get_cursor()
if row == None:
row = self.get_first_selected_row()
if col == None:
col = 0
else:
col = col.get_data('id') + 1
if col == self.colcount:
col = 0
if isinstance(row, (list, tuple)):
row = row[0]
renderer = widget.get_column(col - 1).get_data('renderer')
tree_iter = self.model.get_iter(row)
text = self.model.get_value(tree_iter, col - 1)
renderer.emit('edited', row, text)
widget.set_cursor(row, widget.get_column(col), True) # <- ?????
self.get_rows()
return True # cancel the event
Ps. This is just draft code, I know it's ugly. I'll refactor
and clean everything after I get it working right. :)
Thanks,
Jordan
More information about the pygtk
mailing list