Python Gtk.TreeView(CellRenderer)中的Gtk.Entry
我想将Python Gtk.TreeView(CellRenderer)中的Gtk.Entry,python,gtk,pygobject,gobject,gobject-introspection,Python,Gtk,Pygobject,Gobject,Gobject Introspection,我想将Gtk.Entry(连接Gtk.EntryCompletion后)打包到Gtk.TreeView中的单元格中。有人知道如何做到这一点吗?(我只需要在表格视图中的文本条目上完成输入。) 我是否需要将Gtk.CellRenderer或Gtk.cellRenderText子类化,并覆盖start\u editing方法(或类似方法)?我可以找到子类化Gtk.CellRenderer的示例,但不修改可编辑行为。我也找不到Gtk.cellRenderText类的源代码 我正在使用Gobject内省(
Gtk.Entry
(连接Gtk.EntryCompletion
后)打包到Gtk.TreeView
中的单元格中。有人知道如何做到这一点吗?(我只需要在表格视图中的文本条目上完成输入。)
我是否需要将Gtk.CellRenderer
或Gtk.cellRenderText
子类化,并覆盖start\u editing
方法(或类似方法)?我可以找到子类化Gtk.CellRenderer
的示例,但不修改可编辑行为。我也找不到Gtk.cellRenderText
类的源代码
我正在使用Gobject内省(即,从gi.repository导入Gio、Gtk、GLib、Gdk的
)。您不必子类化,Gtk+很少需要这样做。当然,在Python中(比在C中)它可能更实用,如果是这样的话,它应该很好
显示如何通过将
属性设置为TRUE
来启用编辑
您可以使用
将光标移动到单元格,也可以开始以编程方式进行编辑。您不必子类化,GTK+很少需要这样做。当然,在Python中(比在C中)它可能更实用,如果是这样的话,它应该很好
显示如何通过将
属性设置为TRUE
来启用编辑
您可以使用
将光标移动到单元格,还可以开始以编程方式进行编辑。好的,我终于找到了方法
class CellRendererAutoComplete(Gtk.CellRendererText):
""" Text entry cell which accepts a Gtk.EntryCompletion object """
__gtype_name__ = 'CellRendererAutoComplete'
def __init__(self, completion):
self.completion = completion
Gtk.CellRendererText.__init__(self)
def do_start_editing(
self, event, treeview, path, background_area, cell_area, flags):
if not self.get_property('editable'):
return
entry = Gtk.Entry()
entry.set_completion(self.completion)
entry.connect('editing-done', self.editing_done, path)
entry.show()
entry.grab_focus()
return entry
def editing_done(self, entry, path):
self.emit('edited', path, entry.get_text())
灵感来源于,并适应了pygobject
好的,我终于想出了如何做到这一点
class CellRendererAutoComplete(Gtk.CellRendererText):
""" Text entry cell which accepts a Gtk.EntryCompletion object """
__gtype_name__ = 'CellRendererAutoComplete'
def __init__(self, completion):
self.completion = completion
Gtk.CellRendererText.__init__(self)
def do_start_editing(
self, event, treeview, path, background_area, cell_area, flags):
if not self.get_property('editable'):
return
entry = Gtk.Entry()
entry.set_completion(self.completion)
entry.connect('editing-done', self.editing_done, path)
entry.show()
entry.grab_focus()
return entry
def editing_done(self, entry, path):
self.emit('edited', path, entry.get_text())
灵感来源于,并改编为pygobject
谢谢,但我知道所有这些,它根本没有解决我的问题。我需要截获或覆盖编辑时的事件,以便修改行为,将Gtk.Entry
与完成挂钩,或将其替换为我自己的、启用完成的。我今天早上找到了我要查找的内容(请参阅我的答案)。我想这是一个晚上的睡眠帮助了我,除了+1之外,我还要感谢你发布了一些东西,让我今天早上又开始思考这个问题:)谢谢!我不认为你能帮我的忙,是吗?谢谢,但我知道这一切,它根本没有解决我的问题。我需要截获或覆盖编辑时的事件,以便修改行为,将Gtk.Entry
与完成挂钩,或将其替换为我自己的、启用完成的。我今天早上找到了我要查找的内容(请参阅我的答案)。我想这是一个晚上的睡眠帮助了我,除了+1之外,我还要感谢你发布了一些东西,让我今天早上又开始思考这个问题:)谢谢!我不认为你能帮助我,是吗?你,或者其他任何人来到这里,可能希望检查我的完整(阅读,复杂)答案,不需要子类化。你,或者其他任何人来到这里,可能希望检查我的完整(阅读,复杂)答案,不需要子类化。