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:
Simon Hausmann 2024-03-05 16:14:01 +01:00 committed by Simon Hausmann
parent d0fc025bc8
commit 280f314eeb
4 changed files with 28 additions and 3 deletions

View file

@ -163,8 +163,9 @@ def test_callbacks():
if __name__ == "__main__":
import slint
instance = slint.load_file(
module = slint.load_file(
"../../examples/printerdemo/ui/printerdemo.slint")
instance = module.MainWindow()
instance.set_global_callback(
"PrinterQueue", "start-job", lambda title: print(f"new print job {title}"))
instance.run()

View file

@ -0,0 +1,13 @@
# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
from slint import load_file
import os
def test_load_file():
module = load_file(os.path.join(os.path.dirname(
__spec__.origin), "test_load_file.slint"))
assert list(module.__dict__.keys()) == ["App"]
instance = module.App()
del instance

View file

@ -0,0 +1,4 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
export component App { }