mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-17 22:08:39 +00:00
Python: Use kwargs passed to the instance constructors
And set properties, like in JavaScript.
This commit is contained in:
parent
a3b7a6da50
commit
2234878453
2 changed files with 18 additions and 0 deletions
|
@ -98,6 +98,9 @@ def _build_class(compdef):
|
|||
self.__instance__.set_callback(
|
||||
name, mk_callback(self, value))
|
||||
|
||||
for prop, val in kwargs.items():
|
||||
setattr(self, prop, val)
|
||||
|
||||
properties_and_callbacks = {
|
||||
"__init__": cls_init
|
||||
}
|
||||
|
|
|
@ -38,3 +38,18 @@ def test_load_file_wrapper():
|
|||
assert instance.MyGlobal.global_prop == "This is global"
|
||||
|
||||
del instance
|
||||
|
||||
|
||||
def test_constructor_kwargs():
|
||||
module = load_file(os.path.join(os.path.dirname(
|
||||
__spec__.origin), "test_load_file.slint"), quiet=False)
|
||||
|
||||
def early_say_hello(arg):
|
||||
return "early:" + arg
|
||||
|
||||
instance = module.App(hello="Set early", say_hello=early_say_hello)
|
||||
|
||||
assert instance.hello == "Set early"
|
||||
assert instance.invoke_say_hello("test") == "early:test"
|
||||
|
||||
del instance
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue