| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | use pyo3_stub_gen::{define_stub_info_gatherer, derive::gen_stub_pyfunction}; |
| 5 | |
| 6 | mod image; |
| 7 | mod interpreter; |
| 8 | use interpreter::{ |
| 9 | CompilationResult, Compiler, ComponentDefinition, ComponentInstance, PyDiagnostic, |
| 10 | PyDiagnosticLevel, PyValueType, |
| 11 | }; |
| 12 | mod brush; |
| 13 | mod errors; |
| 14 | mod models; |
| 15 | mod timer; |
| 16 | mod value; |
| 17 | |
| 18 | #[gen_stub_pyfunction ] |
| 19 | #[pyfunction ] |
| 20 | fn run_event_loop() -> Result<(), errors::PyPlatformError> { |
| 21 | slint_interpreter::run_event_loop().map_err(|e: PlatformError| e.into()) |
| 22 | } |
| 23 | |
| 24 | #[gen_stub_pyfunction ] |
| 25 | #[pyfunction ] |
| 26 | fn quit_event_loop() -> Result<(), errors::PyEventLoopError> { |
| 27 | slint_interpreter::quit_event_loop().map_err(|e: EventLoopError| e.into()) |
| 28 | } |
| 29 | |
| 30 | #[gen_stub_pyfunction ] |
| 31 | #[pyfunction ] |
| 32 | fn set_xdg_app_id(app_id: String) -> Result<(), errors::PyPlatformError> { |
| 33 | slint_interpreter::set_xdg_app_id(app_id).map_err(|e: PlatformError| e.into()) |
| 34 | } |
| 35 | |
| 36 | use pyo3::prelude::*; |
| 37 | |
| 38 | #[pymodule ] |
| 39 | fn slint(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { |
| 40 | i_slint_backend_selector::with_platform(|_b| { |
| 41 | // Nothing to do, just make sure a backend was created |
| 42 | Ok(()) |
| 43 | }) |
| 44 | .map_err(|e| errors::PyPlatformError(e))?; |
| 45 | |
| 46 | m.add_class::<Compiler>()?; |
| 47 | m.add_class::<CompilationResult>()?; |
| 48 | m.add_class::<ComponentInstance>()?; |
| 49 | m.add_class::<ComponentDefinition>()?; |
| 50 | m.add_class::<image::PyImage>()?; |
| 51 | m.add_class::<PyValueType>()?; |
| 52 | m.add_class::<PyDiagnosticLevel>()?; |
| 53 | m.add_class::<PyDiagnostic>()?; |
| 54 | m.add_class::<timer::PyTimerMode>()?; |
| 55 | m.add_class::<timer::PyTimer>()?; |
| 56 | m.add_class::<brush::PyColor>()?; |
| 57 | m.add_class::<brush::PyBrush>()?; |
| 58 | m.add_class::<models::PyModelBase>()?; |
| 59 | m.add_class::<value::PyStruct>()?; |
| 60 | m.add_function(wrap_pyfunction!(run_event_loop, m)?)?; |
| 61 | m.add_function(wrap_pyfunction!(quit_event_loop, m)?)?; |
| 62 | m.add_function(wrap_pyfunction!(set_xdg_app_id, m)?)?; |
| 63 | |
| 64 | Ok(()) |
| 65 | } |
| 66 | |
| 67 | define_stub_info_gatherer!(stub_info); |
| 68 | |