Exemplo n.º 1
0
def _get_style_item(node: Style, attr: XmlAttr):
    setter = get_setter(attr)
    value = attr.value if attr.value else ''
    if is_expression(value):
        expression_body = parse_expression(value).body
        value = execute(expression_body, node.node_globals.to_dictionary())
    return StyleItem(setter, attr.name, value)
Exemplo n.º 2
0
def get_init_value(attr: XmlAttr, node_globals: InheritedDict) -> Any:
    """Evaluates attribute value and returns it"""
    stripped_value = attr.value.strip() if attr.value else ''
    if is_expression(stripped_value):
        body = parse_expression(stripped_value)[1]
        parameters = node_globals.to_dictionary() if node_globals else {}
        return execute(body, parameters)
    return attr.value
Exemplo n.º 3
0
def render_attribute(node: Node, xml_attr: XmlAttr) -> Tuple[Setter, Any]:
    """Returns setter and value"""
    setter = get_setter(xml_attr)
    value = xml_attr.value if xml_attr.value else ''
    if is_expression(value):
        expression_ = Expression(parse_expression(value)[1])
        value = execute(expression_, node.node_globals.to_dictionary())
    return setter, value
Exemplo n.º 4
0
def bind_custom_variable_and_expression(
        context: BindingContext) -> TwoWaysBinding:
    """
    Create two ways binding between variable and expression.
    Expression should be "[binding type]:{[variable to bind]}:{[expression to bind]}"
    """
    (var_body, value_body) = context.expression_body.split('}:{')
    variable: Variable = execute(Expression(var_body),
                                 context.node.node_globals.to_dictionary())
    custom_context = BindingContext(context)
    custom_context.expression_body = value_body
    return bind_variable_and_expression(variable, custom_context)