GNOME Bugzilla – Bug 730974
Auto bind template children in gtk_widget_get_template_child()
Last modified: 2014-05-30 19:34:54 UTC
This would help supporting Composite Templates in high-level bindings because it allows avoidance of gtk_widget_class_bind_template_child_full() in the GObject class initializer. It seems this is just a matter of changing the boolean flag in the call to get_auto_child_hash(): https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=3.13.2#n16856 If this is not acceptable, one alternative is to give access to the builder object used by the template, something like gtk_widget_get_template_builder() From this we can use the builder to access template via. an override of get_template_children(): builder = widget.get_template_builder() child = builder.get_object('some_child') See also bug 701843
Hi Simon, It is not possible to implement gtk_widget_get_template_child() in this way because there is no GtkBuilder that exists at any time that a GtkWidget subclass could ever call gtk_widget_get_template_child(), and this should not really change (the GtkBuilder instance only exists for a quick moment inside the scope of gtk_widget_init_template(), aside from this there is no need for an entire instance of GtkBuilder to exist). By the way I have been watching the pygobject bug and I'm happy/excited to see progress in this front. Is calling gtk_widget_class_bind_template_child_full() from subclassed python widget's class initializers really a show stopper for you ?
(In reply to comment #1) > ... (the GtkBuilder instance only exists for a quick moment inside > the scope of gtk_widget_init_template(), aside from this there is no need for > an entire instance of GtkBuilder to exist). Ok, thanks for the explanation. > Is calling gtk_widget_class_bind_template_child_full() > from subclassed python widget's class initializers really a show stopper for > you ? Nope, not a show stopper. Just a little inconvenience. We can work around it by adding our own recursive widget search and caching hack, or by doing things properly and calling gtk_widget_class_bind_template_child_full() based on a Python descriptor developers add to their class.