diff --git a/blueprintcompiler/language/attributes.py b/blueprintcompiler/language/attributes.py index 49707ab..a6db9f1 100644 --- a/blueprintcompiler/language/attributes.py +++ b/blueprintcompiler/language/attributes.py @@ -28,9 +28,13 @@ class BaseAttribute(AstNode): tag_name: str = "" attr_name: str = "name" + @property + def name(self): + return self.tokens["name"] + def emit_xml(self, xml: XmlEmitter): value = self.children[Value][0] - attrs = { self.attr_name: self.tokens["name"] } + attrs = { self.attr_name: self.name } if isinstance(value, TranslatedStringValue): attrs = { **attrs, **value.attrs } diff --git a/blueprintcompiler/language/gtk_a11y.py b/blueprintcompiler/language/gtk_a11y.py index a0e44e0..44a4c1a 100644 --- a/blueprintcompiler/language/gtk_a11y.py +++ b/blueprintcompiler/language/gtk_a11y.py @@ -121,6 +121,10 @@ class A11yProperty(BaseTypedAttribute): else: raise CompilerBugError() + @property + def name(self): + return self.tokens["name"].replace("_", "-") + @property def value_type(self) -> GirType: return get_types(self.root.gir).get(self.tokens["name"]) @@ -181,12 +185,13 @@ def a11y_name_completer(ast_node, match_variables): @decompiler("relation", cdata=True) def decompile_relation(ctx, gir, name, cdata): + name = name.replace("-", "_") ctx.print_attribute(name, cdata, get_types(ctx.gir).get(name)) @decompiler("state", cdata=True) def decompile_state(ctx, gir, name, cdata, translatable="false"): if decompile.truthy(translatable): - ctx.print(f"{name}: _(\"{_escape_quote(cdata)}\");") + ctx.print(f"{name.replace('-', '_')}: _(\"{_escape_quote(cdata)}\");") else: ctx.print_attribute(name, cdata, get_types(ctx.gir).get(name)) diff --git a/tests/samples/accessibility.blp b/tests/samples/accessibility.blp index 117457a..780e940 100644 --- a/tests/samples/accessibility.blp +++ b/tests/samples/accessibility.blp @@ -1,6 +1,6 @@ using Gtk 4.0; -Gtk.Widget { +Gtk.Box { accessibility { label: _("Hello, world!"); labelled_by: my_label; diff --git a/tests/samples/accessibility.ui b/tests/samples/accessibility.ui index 718e24f..50e98c8 100644 --- a/tests/samples/accessibility.ui +++ b/tests/samples/accessibility.ui @@ -1,10 +1,10 @@ - + Hello, world! - my_label + my_label true diff --git a/tests/samples/accessibility_dec.blp b/tests/samples/accessibility_dec.blp index 9daacb4..176faf7 100644 --- a/tests/samples/accessibility_dec.blp +++ b/tests/samples/accessibility_dec.blp @@ -1,6 +1,6 @@ using Gtk 4.0; -Widget { +Box { accessibility { label: _("Hello, world!"); labelled_by: my_label;