Python: Expose Slint structs

Structs declared and exported in Slint are now available in the module namespace
with a constructor.

Fixes #5708
This commit is contained in:
Simon Hausmann 2024-07-08 22:20:29 +02:00 committed by Simon Hausmann
parent 048c0eaf08
commit 1e3f05c983
11 changed files with 144 additions and 12 deletions

View file

@ -12,14 +12,22 @@ def test_load_file(caplog):
assert "The property 'color' has been deprecated. Please use 'background' instead" in caplog.text
assert len(list(module.__dict__.keys())) == 2
assert len(list(module.__dict__.keys())) == 3
assert "App" in module.__dict__
assert "Diag" in module.__dict__
assert "MyData" in module.__dict__
instance = module.App()
del instance
instance = module.Diag()
del instance
struct_instance = module.MyData()
struct_instance.name = "Test"
struct_instance.age = 42
struct_instance = module.MyData(name="testing")
assert struct_instance.name == "testing"
def test_load_file_fail():
with pytest.raises(CompileError, match="Could not compile non-existent.slint"):

View file

@ -13,6 +13,11 @@ export global SecondGlobal {
out property <string> second: "second";
}
export struct MyData {
name: string,
age: int
}
export component App inherits Window {
in-out property <string> hello: "World";
callback say-hello(string) -> string;