GTK3使用`do_changed()`方法对Gtk.Entry进行子类化

时间:2018-02-06 03:01:46

标签: python python-3.x gtk3

当使用Gtk.Entry方法对do_changed()进行子类化时,是否可以解释此行为:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MyEntry(Gtk.Entry):
    def do_show(self):
        print('`{0._name}` show'.format(self))

    def do_changed(self):
        print('`{0._name}` changed, text is now {0.props.text!r}'.format(self))

    def do_activate(self):
        print('`{0._name}` activate'.format(self))

    def do_destroy(self):
        print('`{0._name}` destroy'.format(self))

gtk_entry = Gtk.Entry()
gtk_entry._name = 'gtk_entry'

my_entry = MyEntry()
my_entry._name = 'my_entry'

# Statement:                     # Output:
gtk_entry.show()                 #
my_entry.show()                  # `my_entry` show
                                 #
gtk_entry.props.text = 'Apples'  # `gtk_entry` changed, text is now 'Apples'
my_entry.props.text = 'Oranges'  # `my_entry` changed, text is now 'Oranges'
                                 #
gtk_entry.activate()             #
my_entry.activate()              # `my_entry` activate
                                 #
gtk_entry.destroy()              #
my_entry.destroy()               # `my_entry` destroy

具体来说,我不明白为什么gtk_entry.props.text = 'Apples'会调用MyEntry.do_changed()

This answer from another question说"除了Gtk.Entry"你还必须继承Gtk.Editable。否则"你正在重写Gtk.Editable"提供的基础实现,但有没有人有更深入的解释?

0 个答案:

没有答案