mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-22 00:02:40 +00:00
Python: Add support for converting structs
They map to Python dicts. cc #4202
This commit is contained in:
parent
d486012bcf
commit
b4cddbbe18
2 changed files with 63 additions and 21 deletions
|
@ -14,6 +14,11 @@ def test_property_access():
|
|||
callback globallogic();
|
||||
}
|
||||
|
||||
export struct MyStruct {
|
||||
title: string,
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
export component Test {
|
||||
in property <string> strprop: "Hello";
|
||||
in property <int> intprop: 42;
|
||||
|
@ -23,6 +28,10 @@ def test_property_access():
|
|||
in property <brush> brushprop;
|
||||
in property <color> colprop;
|
||||
in property <[string]> modelprop;
|
||||
in property <MyStruct> structprop: {
|
||||
title: "builtin",
|
||||
finished: true,
|
||||
};
|
||||
|
||||
callback test-callback();
|
||||
}
|
||||
|
@ -59,6 +68,15 @@ def test_property_access():
|
|||
with pytest.raises(ValueError, match="wrong type"):
|
||||
instance.set_property("boolprop", 0)
|
||||
|
||||
structval = instance.get_property("structprop")
|
||||
assert isinstance(structval, dict)
|
||||
assert structval == {'title': 'builtin', 'finished': True}
|
||||
instance.set_property("structprop", {'title': 'new', 'finished': False})
|
||||
assert instance.get_property("structprop") == {'title': 'new', 'finished': False}
|
||||
|
||||
with pytest.raises(TypeError, match="'int' object cannot be converted to 'PyString'"):
|
||||
instance.set_property("structprop", {42: 'wrong'})
|
||||
|
||||
with pytest.raises(ValueError, match="no such property"):
|
||||
instance.set_global_property("nonexistent", "theglobalprop", 42)
|
||||
with pytest.raises(ValueError, match="no such property"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue