Add layouts

This commit is contained in:
James Westman 2021-10-30 20:03:37 -05:00
parent cc3ee76dc2
commit c155ba7b15
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
3 changed files with 67 additions and 4 deletions

View file

@ -243,3 +243,21 @@ on one line. The action and icon are optional.
menu { menu {
item _("Copy") "app.copy" "copy-symbolic"; item _("Copy") "app.copy" "copy-symbolic";
} }
Layout Properties
-----------------
Basic Usage
~~~~~~~~~~~
.. code-block::
Gtk.Grid {
Gtk.Label {
layout {
row: 0;
column: 1;
}
}
}

View file

@ -263,12 +263,13 @@ class Child(AstNode):
class ObjectContent(AstNode): class ObjectContent(AstNode):
child_type = "object_content" child_type = "object_content"
def __init__(self, properties=[], signals=[], children=[], style=[]): def __init__(self, properties=[], signals=[], children=[], style=[], layout=None):
super().__init__() super().__init__()
self.properties = properties self.properties = properties
self.signals = signals self.signals = signals
self.children = children self.children = children
self.style = style self.style = style
self.layout = layout or []
@validate() @validate()
@ -290,7 +291,7 @@ class ObjectContent(AstNode):
) )
def emit_xml(self, xml: XmlEmitter): 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) x.emit_xml(xml)
@ -476,8 +477,9 @@ class Menu(AstNode):
xml.end_tag() xml.end_tag()
class MenuAttribute(AstNode): class BaseAttribute(AstNode):
child_type = "attributes" child_type = "attributes"
tag_name: str = ""
def __init__(self, name=None, value=None, translatable=False): def __init__(self, name=None, value=None, translatable=False):
super().__init__() super().__init__()
@ -487,9 +489,33 @@ class MenuAttribute(AstNode):
def emit_xml(self, xml: XmlEmitter): def emit_xml(self, xml: XmlEmitter):
xml.start_tag( xml.start_tag(
"attribute", self.tag_name,
name=self.name, name=self.name,
translatable="yes" if self.translatable else None, translatable="yes" if self.translatable else None,
) )
xml.put_text(str(self.value)) xml.put_text(str(self.value))
xml.end_tag() 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"

View file

@ -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( object_content = Group(
ast.ObjectContent, ast.ObjectContent,
Sequence( Sequence(
OpenBlock(), OpenBlock(),
Until(AnyOf( Until(AnyOf(
style, style,
layout,
binding, binding,
property, property,
signal, signal,