mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
language: a11y: Fix property names
Blueprint uses underscores in property/state/relation names, but GtkBuilder expects dashes because it uses the glib names from the GtkAccessible* enums.
This commit is contained in:
parent
d73c83aa63
commit
a4ffdd944f
7 changed files with 42 additions and 34 deletions
|
@ -28,9 +28,13 @@ class BaseAttribute(AstNode):
|
||||||
tag_name: str = ""
|
tag_name: str = ""
|
||||||
attr_name: str = "name"
|
attr_name: str = "name"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.tokens["name"]
|
||||||
|
|
||||||
def emit_xml(self, xml: XmlEmitter):
|
def emit_xml(self, xml: XmlEmitter):
|
||||||
value = self.children[Value][0]
|
value = self.children[Value][0]
|
||||||
attrs = { self.attr_name: self.tokens["name"] }
|
attrs = { self.attr_name: self.name }
|
||||||
|
|
||||||
if isinstance(value, TranslatedStringValue):
|
if isinstance(value, TranslatedStringValue):
|
||||||
attrs = { **attrs, **value.attrs }
|
attrs = { **attrs, **value.attrs }
|
||||||
|
|
|
@ -28,23 +28,23 @@ def get_property_types(gir):
|
||||||
return {
|
return {
|
||||||
"autocomplete": gir.get_type("AccessibleAutocomplete", "Gtk"),
|
"autocomplete": gir.get_type("AccessibleAutocomplete", "Gtk"),
|
||||||
"description": StringType(),
|
"description": StringType(),
|
||||||
"has_popup": BoolType(),
|
"has-popup": BoolType(),
|
||||||
"key_shortcuts": StringType(),
|
"key-shortcuts": StringType(),
|
||||||
"label": StringType(),
|
"label": StringType(),
|
||||||
"level": IntType(),
|
"level": IntType(),
|
||||||
"modal": BoolType(),
|
"modal": BoolType(),
|
||||||
"multi_line": BoolType(),
|
"multi-line": BoolType(),
|
||||||
"multi_selectable": BoolType(),
|
"multi-selectable": BoolType(),
|
||||||
"orientation": gir.get_type("Orientation", "Gtk"),
|
"orientation": gir.get_type("Orientation", "Gtk"),
|
||||||
"placeholder": StringType(),
|
"placeholder": StringType(),
|
||||||
"read_only": BoolType(),
|
"read-only": BoolType(),
|
||||||
"required": BoolType(),
|
"required": BoolType(),
|
||||||
"role_description": StringType(),
|
"role-description": StringType(),
|
||||||
"sort": gir.get_type("AccessibleSort", "Gtk"),
|
"sort": gir.get_type("AccessibleSort", "Gtk"),
|
||||||
"value_max": FloatType(),
|
"value-max": FloatType(),
|
||||||
"value_min": FloatType(),
|
"value-min": FloatType(),
|
||||||
"value_now": FloatType(),
|
"value-now": FloatType(),
|
||||||
"value_text": StringType(),
|
"value-text": StringType(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,24 +52,24 @@ def get_relation_types(gir):
|
||||||
# from <https://docs.gtk.org/gtk4/enum.AccessibleRelation.html>
|
# from <https://docs.gtk.org/gtk4/enum.AccessibleRelation.html>
|
||||||
widget = gir.get_type("Widget", "Gtk")
|
widget = gir.get_type("Widget", "Gtk")
|
||||||
return {
|
return {
|
||||||
"active_descendant": widget,
|
"active-descendant": widget,
|
||||||
"col_count": IntType(),
|
"col-count": IntType(),
|
||||||
"col_index": IntType(),
|
"col-index": IntType(),
|
||||||
"col_index_text": StringType(),
|
"col-index-text": StringType(),
|
||||||
"col_span": IntType(),
|
"col-span": IntType(),
|
||||||
"controls": widget,
|
"controls": widget,
|
||||||
"described_by": widget,
|
"described-by": widget,
|
||||||
"details": widget,
|
"details": widget,
|
||||||
"error_message": widget,
|
"error-message": widget,
|
||||||
"flow_to": widget,
|
"flow-to": widget,
|
||||||
"labelled_by": widget,
|
"labelled-by": widget,
|
||||||
"owns": widget,
|
"owns": widget,
|
||||||
"pos_in_set": IntType(),
|
"pos-in-set": IntType(),
|
||||||
"row_count": IntType(),
|
"row-count": IntType(),
|
||||||
"row_index": IntType(),
|
"row-index": IntType(),
|
||||||
"row_index_text": StringType(),
|
"row-index-text": StringType(),
|
||||||
"row_span": IntType(),
|
"row-span": IntType(),
|
||||||
"set_size": IntType(),
|
"set-size": IntType(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,6 +122,10 @@ class A11yProperty(BaseTypedAttribute):
|
||||||
else:
|
else:
|
||||||
raise CompilerBugError()
|
raise CompilerBugError()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.tokens["name"].replace("_", "-")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value_type(self) -> GirType:
|
def value_type(self) -> GirType:
|
||||||
return get_types(self.root.gir).get(self.tokens["name"])
|
return get_types(self.root.gir).get(self.tokens["name"])
|
||||||
|
|
|
@ -332,7 +332,7 @@ Basic Usage
|
||||||
Gtk.Widget {
|
Gtk.Widget {
|
||||||
accessibility {
|
accessibility {
|
||||||
orientation: vertical;
|
orientation: vertical;
|
||||||
labelled_by: my_label;
|
labelled-by: my_label;
|
||||||
checked: true;
|
checked: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,6 @@ using Gtk 4.0;
|
||||||
|
|
||||||
Widget {
|
Widget {
|
||||||
accessibility {
|
accessibility {
|
||||||
labelled_by: not_an_object;
|
labelled-by: not_an_object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
using Gtk 4.0;
|
using Gtk 4.0;
|
||||||
|
|
||||||
Gtk.Widget {
|
Gtk.Box {
|
||||||
accessibility {
|
accessibility {
|
||||||
label: _("Hello, world!");
|
label: _("Hello, world!");
|
||||||
labelled_by: my_label;
|
labelled-by: my_label;
|
||||||
checked: true;
|
checked: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk" version="4.0"/>
|
<requires lib="gtk" version="4.0"/>
|
||||||
<object class="GtkWidget">
|
<object class="GtkBox">
|
||||||
<accessibility>
|
<accessibility>
|
||||||
<property name="label" translatable="true">Hello, world!</property>
|
<property name="label" translatable="true">Hello, world!</property>
|
||||||
<relation name="labelled_by">my_label</relation>
|
<relation name="labelled-by">my_label</relation>
|
||||||
<state name="checked">true</state>
|
<state name="checked">true</state>
|
||||||
</accessibility>
|
</accessibility>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
using Gtk 4.0;
|
using Gtk 4.0;
|
||||||
|
|
||||||
Widget {
|
Box {
|
||||||
accessibility {
|
accessibility {
|
||||||
label: _("Hello, world!");
|
label: _("Hello, world!");
|
||||||
labelled_by: my_label;
|
labelled-by: my_label;
|
||||||
checked: true;
|
checked: true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue