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 51a362c..161c608 100644 --- a/blueprintcompiler/language/gtk_a11y.py +++ b/blueprintcompiler/language/gtk_a11y.py @@ -28,23 +28,23 @@ def get_property_types(gir): return { "autocomplete": gir.get_type("AccessibleAutocomplete", "Gtk"), "description": StringType(), - "has_popup": BoolType(), - "key_shortcuts": StringType(), + "has-popup": BoolType(), + "key-shortcuts": StringType(), "label": StringType(), "level": IntType(), "modal": BoolType(), - "multi_line": BoolType(), - "multi_selectable": BoolType(), + "multi-line": BoolType(), + "multi-selectable": BoolType(), "orientation": gir.get_type("Orientation", "Gtk"), "placeholder": StringType(), - "read_only": BoolType(), + "read-only": BoolType(), "required": BoolType(), - "role_description": StringType(), + "role-description": StringType(), "sort": gir.get_type("AccessibleSort", "Gtk"), - "value_max": FloatType(), - "value_min": FloatType(), - "value_now": FloatType(), - "value_text": StringType(), + "value-max": FloatType(), + "value-min": FloatType(), + "value-now": FloatType(), + "value-text": StringType(), } @@ -52,24 +52,24 @@ def get_relation_types(gir): # from widget = gir.get_type("Widget", "Gtk") return { - "active_descendant": widget, - "col_count": IntType(), - "col_index": IntType(), - "col_index_text": StringType(), - "col_span": IntType(), + "active-descendant": widget, + "col-count": IntType(), + "col-index": IntType(), + "col-index-text": StringType(), + "col-span": IntType(), "controls": widget, - "described_by": widget, + "described-by": widget, "details": widget, - "error_message": widget, - "flow_to": widget, - "labelled_by": widget, + "error-message": widget, + "flow-to": widget, + "labelled-by": widget, "owns": widget, - "pos_in_set": IntType(), - "row_count": IntType(), - "row_index": IntType(), - "row_index_text": StringType(), - "row_span": IntType(), - "set_size": IntType(), + "pos-in-set": IntType(), + "row-count": IntType(), + "row-index": IntType(), + "row-index-text": StringType(), + "row-span": IntType(), + "set-size": IntType(), } @@ -122,6 +122,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"]) diff --git a/docs/examples.rst b/docs/examples.rst index e53da1c..bf28784 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -332,7 +332,7 @@ Basic Usage Gtk.Widget { accessibility { orientation: vertical; - labelled_by: my_label; + labelled-by: my_label; checked: true; } } diff --git a/tests/sample_errors/a11y_prop_obj_dne.blp b/tests/sample_errors/a11y_prop_obj_dne.blp index 96074fa..e0285ff 100644 --- a/tests/sample_errors/a11y_prop_obj_dne.blp +++ b/tests/sample_errors/a11y_prop_obj_dne.blp @@ -2,6 +2,6 @@ using Gtk 4.0; Widget { accessibility { - labelled_by: not_an_object; + labelled-by: not_an_object; } } diff --git a/tests/samples/accessibility.blp b/tests/samples/accessibility.blp index 117457a..ec563b4 100644 --- a/tests/samples/accessibility.blp +++ b/tests/samples/accessibility.blp @@ -1,9 +1,9 @@ using Gtk 4.0; -Gtk.Widget { +Gtk.Box { accessibility { label: _("Hello, world!"); - labelled_by: my_label; + labelled-by: my_label; checked: true; } } 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..a603e25 100644 --- a/tests/samples/accessibility_dec.blp +++ b/tests/samples/accessibility_dec.blp @@ -1,9 +1,9 @@ using Gtk 4.0; -Widget { +Box { accessibility { label: _("Hello, world!"); - labelled_by: my_label; + labelled-by: my_label; checked: true; } }