From 3ebe5c72c1d4600e7d43202b29c83a35eaf27b9f Mon Sep 17 00:00:00 2001 From: James Westman Date: Tue, 16 May 2023 17:42:53 -0500 Subject: [PATCH] Fix templates in bind-property --- blueprintcompiler/outputs/xml/__init__.py | 11 ++++++++++- tests/samples/template_bind_property.blp | 5 +++++ tests/samples/template_bind_property.ui | 7 +++++++ tests/test_samples.py | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/samples/template_bind_property.blp create mode 100644 tests/samples/template_bind_property.ui diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index fd0bb70..a58ca9d 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -141,7 +141,16 @@ class XmlOutput(OutputFormat): if value.bidirectional: bind_flags.append("bidirectional") - props["bind-source"] = value.source + if ( + value.source == "template" + and value.context[ScopeCtx].template is not None + ): + props["bind-source"] = value.context[ + ScopeCtx + ].template.gir_class.glib_type_name + else: + props["bind-source"] = value.source + props["bind-property"] = value.property_name props["bind-flags"] = "|".join(bind_flags) or None xml.put_self_closing("property", **props) diff --git a/tests/samples/template_bind_property.blp b/tests/samples/template_bind_property.blp new file mode 100644 index 0000000..e2be0bf --- /dev/null +++ b/tests/samples/template_bind_property.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +template $MyTemplate { + object: bind-property template.object2; +} \ No newline at end of file diff --git a/tests/samples/template_bind_property.ui b/tests/samples/template_bind_property.ui new file mode 100644 index 0000000..eb55547 --- /dev/null +++ b/tests/samples/template_bind_property.ui @@ -0,0 +1,7 @@ + + + + + diff --git a/tests/test_samples.py b/tests/test_samples.py index 34fe45f..30a41aa 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -177,6 +177,7 @@ class TestSamples(unittest.TestCase): "template", "template_binding", "template_binding_extern", + "template_bind_property", "template_id", "template_no_parent", "template_simple_binding",