mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-03 05:12:55 +00:00
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:
parent
048c0eaf08
commit
1e3f05c983
11 changed files with 144 additions and 12 deletions
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue