From e4bad039b0ff3d054666eb6161004c1df75ea933 Mon Sep 17 00:00:00 2001 From: James Westman Date: Tue, 16 May 2023 17:14:34 -0500 Subject: [PATCH] Fix simple bindings with template soure --- blueprintcompiler/outputs/xml/__init__.py | 11 ++++++++++- tests/samples/template_simple_binding.blp | 5 +++++ tests/samples/template_simple_binding.ui | 7 +++++++ tests/test_samples.py | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/samples/template_simple_binding.blp create mode 100644 tests/samples/template_simple_binding.ui diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index 0fc2c5e..fd0bb70 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -114,7 +114,16 @@ class XmlOutput(OutputFormat): elif isinstance(value, Binding): if simple := value.simple_binding: - props["bind-source"] = simple.source + if ( + simple.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"] = simple.source + props["bind-property"] = simple.property_name props["bind-flags"] = "sync-create" xml.put_self_closing("property", **props) diff --git a/tests/samples/template_simple_binding.blp b/tests/samples/template_simple_binding.blp new file mode 100644 index 0000000..549f885 --- /dev/null +++ b/tests/samples/template_simple_binding.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +template $MyTemplate { + prop: bind template.prop2; +} \ No newline at end of file diff --git a/tests/samples/template_simple_binding.ui b/tests/samples/template_simple_binding.ui new file mode 100644 index 0000000..41788e4 --- /dev/null +++ b/tests/samples/template_simple_binding.ui @@ -0,0 +1,7 @@ + + + + + diff --git a/tests/test_samples.py b/tests/test_samples.py index f6ba1a0..fa628be 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -178,6 +178,7 @@ class TestSamples(unittest.TestCase): "template_binding", "template_binding_extern", "template_no_parent", + "template_simple_binding", "typeof", "unchecked_class", ]