Gtk.TreeView中的Gtk.Entry(CellRenderer) [英] Gtk.Entry in Gtk.TreeView (CellRenderer)

查看:103
本文介绍了Gtk.TreeView中的Gtk.Entry(CellRenderer)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Gtk.Entry(与Gtk.EntryCompletion连接在一起)打包到Gtk.TreeView中的单元格中.有谁知道该怎么做? (我只需要在表格视图中的文本条目上完成输入.)

I want to pack a Gtk.Entry (with Gtk.EntryCompletion hooked up) into a cell in a Gtk.TreeView. Does anyone know how this can be done? (I just need entry completion on a text entry in a tabular view.)

我可能需要继承Gtk.CellRendererGtk.CellRendererText的子类,并覆盖start_editing方法(或类似方法)吗?我可以找到子类化Gtk.CellRenderer的示例,但没有修改可编辑的行为.我也找不到Gtk.CellRendererText类的源代码.

Do I perhaps need to subclass Gtk.CellRenderer or Gtk.CellRendererText, and override the start_editing method (or similar)? I can find examples of subclassing Gtk.CellRenderer, but not modifying the editable behaviour. I can't find the source-code for the Gtk.CellRendererText class, either.

我正在使用Gobject自省(即from gi.repository import Gio, Gtk, GLib, Gdk).

I'm using Gobject Introspection (i.e. from gi.repository import Gio, Gtk, GLib, Gdk).

推荐答案

好的,我终于弄清楚了该怎么做.

Okay, I finally worked out how to do this.

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())

灵感源自 PyGTK常见问题解答 ,并适用于pygobject.

Inspiration dervied from the PyGTK FAQ, and adapted to pygobject.

这篇关于Gtk.TreeView中的Gtk.Entry(CellRenderer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆