mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add layouts
This commit is contained in:
parent
cc3ee76dc2
commit
c155ba7b15
3 changed files with 67 additions and 4 deletions
|
@ -243,3 +243,21 @@ on one line. The action and icon are optional.
|
|||
menu {
|
||||
item _("Copy") "app.copy" "copy-symbolic";
|
||||
}
|
||||
|
||||
|
||||
Layout Properties
|
||||
-----------------
|
||||
|
||||
Basic Usage
|
||||
~~~~~~~~~~~
|
||||
|
||||
.. code-block::
|
||||
|
||||
Gtk.Grid {
|
||||
Gtk.Label {
|
||||
layout {
|
||||
row: 0;
|
||||
column: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -263,12 +263,13 @@ class Child(AstNode):
|
|||
|
||||
class ObjectContent(AstNode):
|
||||
child_type = "object_content"
|
||||
def __init__(self, properties=[], signals=[], children=[], style=[]):
|
||||
def __init__(self, properties=[], signals=[], children=[], style=[], layout=None):
|
||||
super().__init__()
|
||||
self.properties = properties
|
||||
self.signals = signals
|
||||
self.children = children
|
||||
self.style = style
|
||||
self.layout = layout or []
|
||||
|
||||
|
||||
@validate()
|
||||
|
@ -290,7 +291,7 @@ class ObjectContent(AstNode):
|
|||
)
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
for x in [*self.properties, *self.signals, *self.children, *self.style]:
|
||||
for x in self.child_nodes:
|
||||
x.emit_xml(xml)
|
||||
|
||||
|
||||
|
@ -476,8 +477,9 @@ class Menu(AstNode):
|
|||
xml.end_tag()
|
||||
|
||||
|
||||
class MenuAttribute(AstNode):
|
||||
class BaseAttribute(AstNode):
|
||||
child_type = "attributes"
|
||||
tag_name: str = ""
|
||||
|
||||
def __init__(self, name=None, value=None, translatable=False):
|
||||
super().__init__()
|
||||
|
@ -487,9 +489,33 @@ class MenuAttribute(AstNode):
|
|||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag(
|
||||
"attribute",
|
||||
self.tag_name,
|
||||
name=self.name,
|
||||
translatable="yes" if self.translatable else None,
|
||||
)
|
||||
xml.put_text(str(self.value))
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class MenuAttribute(BaseAttribute):
|
||||
child_type = "attributes"
|
||||
tag_name = "attribute"
|
||||
|
||||
|
||||
class Layout(AstNode):
|
||||
child_type = "layout"
|
||||
|
||||
def __init__(self, layout_props=None):
|
||||
super().__init__()
|
||||
self.layout_props = layout_props or []
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("layout")
|
||||
for prop in self.layout_props:
|
||||
prop.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class LayoutProperty(BaseAttribute):
|
||||
child_type = "layout_props"
|
||||
tag_name = "property"
|
||||
|
|
|
@ -244,12 +244,31 @@ def parse(tokens) -> T.Tuple[ast.UI, T.Optional[MultipleErrors]]:
|
|||
),
|
||||
)
|
||||
|
||||
layout_prop = Group(
|
||||
ast.LayoutProperty,
|
||||
Statement(
|
||||
UseIdent("name"),
|
||||
Op(":"),
|
||||
value.expected("a value"),
|
||||
)
|
||||
)
|
||||
|
||||
layout = Group(
|
||||
ast.Layout,
|
||||
Sequence(
|
||||
Keyword("layout"),
|
||||
OpenBlock().expected("`{`"),
|
||||
Until(layout_prop, CloseBlock()),
|
||||
)
|
||||
)
|
||||
|
||||
object_content = Group(
|
||||
ast.ObjectContent,
|
||||
Sequence(
|
||||
OpenBlock(),
|
||||
Until(AnyOf(
|
||||
style,
|
||||
layout,
|
||||
binding,
|
||||
property,
|
||||
signal,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue