Validate parent object for accessibility and layout

This commit is contained in:
James Westman 2021-11-12 17:10:30 -06:00
parent 2224f0958c
commit e759569c3f
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
8 changed files with 40 additions and 4 deletions

View file

@ -106,6 +106,14 @@ def _get_docs(gir, name):
class A11y(AstNode):
@validate("accessibility")
def container_is_widget(self):
widget = self.root.gir.get_type("Widget", "Gtk")
container_type = self.parent_by_type(ast.Object).gir_class
if container_type and not container_type.assignable_to(widget):
raise CompileError(f"{container_type.full_name} is not a {widget.full_name}, so it doesn't have accessibility properties")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("accessibility")
for child in self.children:
@ -158,7 +166,7 @@ a11y_prop = Group(
a11y = Group(
A11y,
Sequence(
Keyword("accessibility"),
Keyword("accessibility", True),
OpenBlock().expected("`{`"),
Until(a11y_prop, CloseBlock()),
)