3

Can somebody explain this behaviour when subclassing Gtk.Entry with a do_changed() method:

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

Specifically, I don't understand why gtk_entry.props.text = 'Apples' would invoke MyEntry.do_changed()


This answer from another question says that "You have to inherit from Gtk.Editable in addition to Gtk.Entry" otherwise "you are overriding the base implementation provided by Gtk.Editable", but does anyone have a more in-depth explanation?

eugenhu
  • 1,168
  • 13
  • 22

0 Answers0