mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 02:39:28 +00:00
Python: Add missing write-back support for Models
Ooops :-)
This commit is contained in:
parent
cc83784de5
commit
c1e8d7c07d
2 changed files with 49 additions and 0 deletions
|
@ -114,3 +114,35 @@ def test_rust_model_sequence():
|
|||
assert len(model) == 5
|
||||
assert list(model) == [1, 2, 3, 4, 5]
|
||||
assert model[2] == 3
|
||||
|
||||
|
||||
def test_model_writeback():
|
||||
compiler = native.ComponentCompiler()
|
||||
|
||||
compdef = compiler.build_from_source("""
|
||||
export component App {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
|
||||
in-out property<[int]> model;
|
||||
callback write-to-model(int, int);
|
||||
write-to-model(index, value) => {
|
||||
self.model[index] = value
|
||||
}
|
||||
|
||||
}
|
||||
""", "")
|
||||
assert compdef != None
|
||||
|
||||
instance = compdef.create()
|
||||
assert instance != None
|
||||
|
||||
model = models.ListModel([100, 0])
|
||||
|
||||
instance.set_property(
|
||||
"model", model)
|
||||
|
||||
instance.invoke("write-to-model", 1, 42)
|
||||
assert list(instance.get_property("model")) == [100, 42]
|
||||
instance.invoke("write-to-model", 0, 25)
|
||||
assert list(instance.get_property("model")) == [25, 42]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue