Python: Add more type stubs to the internal Rust API

This commit is contained in:
Simon Hausmann 2025-02-12 11:32:26 +01:00 committed by Simon Hausmann
parent 7c75720c9a
commit c111098e49
4 changed files with 29 additions and 1 deletions

View file

@ -6,6 +6,7 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use pyo3_stub_gen::derive::gen_stub_pyclass_enum;
use slint_interpreter::{ComponentHandle, Value};
use i_slint_compiler::langtype::Type;
@ -244,6 +245,7 @@ impl ComponentDefinition {
}
}
#[gen_stub_pyclass_enum]
#[pyclass(name = "ValueType")]
pub enum PyValueType {
Void,

View file

@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
use pyo3_stub_gen::define_stub_info_gatherer;
use pyo3_stub_gen::{define_stub_info_gatherer, derive::gen_stub_pyfunction};
mod image;
mod interpreter;
@ -22,6 +22,7 @@ fn quit_event_loop() -> Result<(), errors::PyEventLoopError> {
slint_interpreter::quit_event_loop().map_err(|e| e.into())
}
#[gen_stub_pyfunction]
#[pyfunction]
fn set_xdg_app_id(app_id: String) -> Result<(), errors::PyPlatformError> {
slint_interpreter::set_xdg_app_id(app_id).map_err(|e| e.into())

View file

@ -131,3 +131,22 @@ class Timer:
def set_interval(self, interval:datetime.timedelta) -> None:
...
def set_xdg_app_id(app_id: str):
...
class PyModelBase:
...
class PyStruct:
...
class ValueType(Enum):
Void = auto()
Number = auto()
String = auto()
Bool = auto()
Model = auto()
Struct = auto()
Brush = auto()
Image = auto()

View file

@ -3,9 +3,11 @@
use pyo3::prelude::*;
use pyo3::types::PyDict;
use pyo3_stub_gen::{derive::gen_stub_pyclass, derive::gen_stub_pymethods};
use std::collections::HashMap;
#[gen_stub_pyclass]
pub struct PyValue(pub slint_interpreter::Value);
struct PyValueRef<'a>(&'a slint_interpreter::Value);
@ -120,12 +122,14 @@ impl From<slint_interpreter::Value> for PyValue {
}
}
#[gen_stub_pyclass]
#[pyclass(subclass, unsendable)]
#[derive(Clone, Default)]
pub struct PyStruct {
data: slint_interpreter::Struct,
}
#[gen_stub_pymethods]
#[pymethods]
impl PyStruct {
#[new]
@ -171,11 +175,13 @@ impl From<slint_interpreter::Struct> for PyStruct {
}
}
#[gen_stub_pyclass]
#[pyclass(unsendable)]
struct PyStructFieldIterator {
inner: std::collections::hash_map::IntoIter<String, slint_interpreter::Value>,
}
#[gen_stub_pymethods]
#[pymethods]
impl PyStructFieldIterator {
fn __iter__(slf: PyRef<'_, Self>) -> PyRef<'_, Self> {