Python PyGOobject树视图:使用Tab键在单元格之间移动后确认编辑 [英] Python PyGOobject treeview: confirm edit after move between cells with Tab key
问题描述
搜索了很长时间之后,我发现了一个解决方案(非常简单),可以使用Tab键在维护的单元格之间移动,并在编辑模式下维护单元格.
After searching for a long time I found a solution (pretty simple) to move between cells of a treeview grid using Tab key and mantaining cells in edit mode.
现在我遇到了一个问题:仅在按Enter键之后才进行单元格编辑确认. 如果按Tab键,似乎会触发edit_cananceled事件.
Now I've got a problem: cell edit confirmation happens only after pressing Enter key. If I press Tab key a editing_canceled event appears to be triggered.
如何解决?如何在按Tab键时也允许数据确认?
How to solve it? How to permit the data confirmation also on tab key press?
这是我的Treeview按键事件的事件处理程序:
This is my event handler for treeview key-press-event:
def key_tree_Tab(self, treeview, event,namewidget):
path, col = treeview.get_cursor()
## only visible columns!!
columns = [c for c in treeview.get_columns() if c.get_visible()]
colnum = columns.index(col)
if event.keyval==65289:
if colnum + 1 < len(columns):
next_column = columns[colnum + 1]
treeview.set_cursor(path,next_column,start_editing=True)
else:
tmodel = treeview.get_model()
titer = tmodel.iter_next(tmodel.get_iter(path))
if titer is None:
titer = tmodel.get_iter_first()
path = tmodel.get_path(titer)
next_column = columns[0]
treeview.set_cursor(path,next_column,start_editing=True)
return True
谢谢大家!!!!
推荐答案
我知道这个线程很久以前了.我使用当前版本的Python3和Gtk3尝试了您的代码,但无法正常工作.它仅适用于新行.现有行不会跳至下一个单元格.如果我添加"return True",那么即使有现有单元格,每个单元格都可以按Tab键显示,但是没有一个单元格会更新.
I know this thread is long ago. I tried your code with current version of Python3 and Gtk3 and does not work. It works only with new rows. The existing rows do not tab to next cell. If I add "return True" then every cell can Tab even with existing cells, but none gets updated.
这篇关于Python PyGOobject树视图:使用Tab键在单元格之间移动后确认编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!