[pygobject] docs: add an example of using a subclass in a UI definition
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] docs: add an example of using a subclass in a UI definition
- Date: Fri, 30 Apr 2021 05:03:12 +0000 (UTC)
commit c682706527f295a7f5c90d33a5f83e14e14baceb
Author: Chris Mayo <aklhfex gmail com>
Date: Thu Feb 25 19:18:51 2021 +0000
docs: add an example of using a subclass in a UI definition
docs/guide/gtk_template.rst | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
---
diff --git a/docs/guide/gtk_template.rst b/docs/guide/gtk_template.rst
index 1e80fddf..3e340600 100644
--- a/docs/guide/gtk_template.rst
+++ b/docs/guide/gtk_template.rst
@@ -88,3 +88,36 @@ to the name of the built-in widget:
</child>
</template>
</interface>
+
+
+Subclasses that declare ``__gtype_name__`` can be used as objects in the XML:
+
+.. code-block:: python
+
+ xml = """\
+ <interface>
+ <template class="example3" parent="GtkBox">
+ <child>
+ <object class="ExampleButton" id="hello_button">
+ <property name="label">Hello World</property>
+ <signal name="clicked" handler="hello_button_clicked" swapped="no" />
+ </object>
+ </child>
+ </template>
+ </interface>
+ """
+
+
+ class HelloButton(Gtk.Button):
+ __gtype_name__ = "ExampleButton"
+
+
+ @Gtk.Template(string=xml)
+ class Foo(Gtk.Box):
+ __gtype_name__ = "example3"
+
+ hello_button = Gtk.Template.Child()
+
+ @Gtk.Template.Callback()
+ def hello_button_clicked(self, *args):
+ pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]