From 9dcd06de5189152abe14dcd6d5ff3f6d1eb25032 Mon Sep 17 00:00:00 2001 From: James Westman Date: Fri, 28 Apr 2023 20:42:46 -0500 Subject: [PATCH] Make builder template factories use a subscope --- .../language/gtk_list_item_factory.py | 10 ++++++++++ tests/sample_errors/subscope.blp | 9 +++++++++ tests/sample_errors/subscope.err | 1 + tests/samples/subscope.blp | 9 +++++++++ tests/samples/subscope.ui | 15 +++++++++++++++ tests/test_samples.py | 2 ++ 6 files changed, 46 insertions(+) create mode 100644 tests/sample_errors/subscope.blp create mode 100644 tests/sample_errors/subscope.err create mode 100644 tests/samples/subscope.blp create mode 100644 tests/samples/subscope.ui diff --git a/blueprintcompiler/language/gtk_list_item_factory.py b/blueprintcompiler/language/gtk_list_item_factory.py index d25b96d..ae9d019 100644 --- a/blueprintcompiler/language/gtk_list_item_factory.py +++ b/blueprintcompiler/language/gtk_list_item_factory.py @@ -1,6 +1,8 @@ from .gobject_object import ObjectContent, validate_parent_type from ..parse_tree import Keyword from ..ast_utils import AstNode, validate +from .common import * +from .contexts import ScopeCtx class ListItemFactory(AstNode): @@ -19,6 +21,14 @@ class ListItemFactory(AstNode): "sub-templates", ) + @context(ScopeCtx) + def scope_ctx(self) -> ScopeCtx: + return ScopeCtx(node=self) + + @validate() + def unique_ids(self): + self.context[ScopeCtx].validate_unique_ids() + @property def content(self) -> ObjectContent: return self.children[ObjectContent][0] diff --git a/tests/sample_errors/subscope.blp b/tests/sample_errors/subscope.blp new file mode 100644 index 0000000..59d3a9f --- /dev/null +++ b/tests/sample_errors/subscope.blp @@ -0,0 +1,9 @@ +using Gtk 4.0; + +BuilderListItemFactory { + template { + child: label; + } +} + +Label label {} \ No newline at end of file diff --git a/tests/sample_errors/subscope.err b/tests/sample_errors/subscope.err new file mode 100644 index 0000000..454e292 --- /dev/null +++ b/tests/sample_errors/subscope.err @@ -0,0 +1 @@ +5,12,5,Could not find object with ID label \ No newline at end of file diff --git a/tests/samples/subscope.blp b/tests/samples/subscope.blp new file mode 100644 index 0000000..a14591b --- /dev/null +++ b/tests/samples/subscope.blp @@ -0,0 +1,9 @@ +using Gtk 4.0; + +Gtk.BuilderListItemFactory { + template { + child: Gtk.Label label {}; + } +} + +Gtk.Label label {} \ No newline at end of file diff --git a/tests/samples/subscope.ui b/tests/samples/subscope.ui new file mode 100644 index 0000000..61bdc18 --- /dev/null +++ b/tests/samples/subscope.ui @@ -0,0 +1,15 @@ + + + + + + + +]]> + + + diff --git a/tests/test_samples.py b/tests/test_samples.py index 8ee9015..7af9e1b 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -184,6 +184,7 @@ class TestSamples(unittest.TestCase): self.assert_sample("string_list") self.assert_sample("strings") self.assert_sample("style") + self.assert_sample("subscope") self.assert_sample( "template", skip_run=True ) # The template class doesn't exist @@ -258,6 +259,7 @@ class TestSamples(unittest.TestCase): self.assert_sample_error("size_group_obj_dne") self.assert_sample_error("strv") self.assert_sample_error("styles_in_non_widget") + self.assert_sample_error("subscope") self.assert_sample_error("two_templates") self.assert_sample_error("uint") self.assert_sample_error("using_invalid_namespace")