Document how to handle typing/linting with Gtk.Template.Child
Gtk.Template.Child()
is kind of "magical" in that it returns an instance which is used when initializing the instance of the class with the @Gtk.Template
.
@Gtk.Template(filename="my_window.ui")
class MyWindow(Gtk.ApplicationWindow):
__gtype_name__ = "MyWindow"
my_input = Gtk.Template.Child("my_input")
get_input_text():
return self.my_input.get_text().lstrip()
This will work, but it pylint and IDEs and text editors won't understand that self.my_input is actually a Gtk.Entry
here, and will say "Instance of 'Child' has no 'get_text' member (no-member)".
But if you declare it on a separate line it works for me:
my_input: Gtk.Entry
my_input = Gtk.Template.Child("my_input")
This did not work for me (not sure why):
my_input: Gtk.Entry = Gtk.Template.Child("my_input")
Edited by friday