mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-31 15:47:26 +00:00
Python: Fix access to globals when there's more than one
The getter for the global didn't capture the correct global_class, just the last iteration. This fixes the broken printer demo.
This commit is contained in:
parent
86cde942b7
commit
0b6381d012
3 changed files with 15 additions and 5 deletions
|
@ -178,11 +178,15 @@ def _build_class(compdef):
|
|||
for global_name in compdef.globals:
|
||||
global_class = _build_global_class(compdef, global_name)
|
||||
|
||||
def global_getter(self):
|
||||
wrapper = global_class()
|
||||
setattr(wrapper, "__instance__", self.__instance__)
|
||||
return wrapper
|
||||
properties_and_callbacks[global_name] = property(global_getter)
|
||||
def mk_global(global_class):
|
||||
def global_getter(self):
|
||||
wrapper = global_class()
|
||||
setattr(wrapper, "__instance__", self.__instance__)
|
||||
return wrapper
|
||||
|
||||
return property(global_getter)
|
||||
|
||||
properties_and_callbacks[global_name] = mk_global(global_class)
|
||||
|
||||
return type("SlintClassWrapper", (Component,), properties_and_callbacks)
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@ def test_load_file_wrapper():
|
|||
|
||||
assert instance.MyGlobal.minus_one(100) == 99
|
||||
|
||||
assert instance.SecondGlobal.second == "second"
|
||||
|
||||
del instance
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ export global MyGlobal {
|
|||
}
|
||||
}
|
||||
|
||||
export global SecondGlobal {
|
||||
out property <string> second: "second";
|
||||
}
|
||||
|
||||
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