Closed tronical closed 6 months ago
The initial load_file
function is added, which exposes instances as objects with properties and callbacks (as on-prefixed properties). The dynamic import is missing still.
One way for the dynamic import would be to allow for writing an __init__.py
stub that associates a directory with a specific .slint
file, and then allow for writing:
Support ui/__init__.py
referenced ui/main_window.slint
:
from ui import MainWindow
window = MainWindow()
window.show();
Without __init__.py
a neater way might be to add a finder/loader to sys.meta_path
and support import foo
, which loads foo.slint
.
Example:
foo.slint:
export component MainWindow { ... }
blah.py:
import slint
import foo
main_window = foo.MainWindow();
main_window.run()
(this would also work of course with import foo as bar
or import MainWindow from foo
)
I've updated the description with a summary of the implemented API. Closing this as the initial port being done. Documentation is still missing, but that's part of a milestone that was agreed on separately.
The objective of this task is explore the possibility of providing dynamically generated types for “.slint” files. Beyond classic objects with properties, we can experiment with dynamic imports like in the popular “sh” module. We should review this API with experienced Pythonistas in public discussions.
This work will be sponsored by the NLnet foundation.
Edit: The API review makes most sense after the documentation is up and the rest of the project is ready for review, so let's exclude that from the scope of this issue and include it in the before the final release.
The basic API that's implemented now can be summarized like this:
slint.load_file
or viaimport name_of_file_slint
(_slint
suffix triggers).instance.my_callback = self.foo_function
) or by subclassing and using the@slint.callback
decorator on a method.slint.Model
and must providerow_count
,row_data(row)
andset_row_data(row, data)
functions (the latter only if the model is writable). A convenienceslint.ListMode()
class exists that wraps alist
and provides ways of mutating it (and notifying Slint views accordingly)slint.Timer
.slint.Brush
andslint.Color
wrappers.slint.Image
withload_from_path
andload_from_svg_data
static methods for creation, and path/size properties.An example of all this in action can be found in https://github.com/slint-ui/slint/blob/master/examples/printerdemo/python/README.md
Overall README: https://github.com/slint-ui/slint/tree/master/api/python