mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-03 07:04:34 +00:00
Python: Rework the load_file API, part 1
Return a namespace that contains a "class type" for constructing the component instance - similar to the Node.js API.
This commit is contained in:
parent
d0fc025bc8
commit
280f314eeb
4 changed files with 28 additions and 3 deletions
|
@ -2,13 +2,20 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
|
||||
|
||||
from . import slint as native
|
||||
import types
|
||||
|
||||
|
||||
def load_file(path):
|
||||
compiler = native.ComponentCompiler()
|
||||
compdef = compiler.build_from_path(path)
|
||||
instance = compdef.create()
|
||||
return instance
|
||||
|
||||
module = types.SimpleNamespace()
|
||||
setattr(module, compdef.name, type("SlintMetaClass", (), {
|
||||
"__compdef": compdef,
|
||||
"__new__": lambda cls: cls.__compdef.create()
|
||||
}))
|
||||
|
||||
return module
|
||||
|
||||
|
||||
Image = native.PyImage
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue