Python: Make the re-exported classes show up property in the documentation

The variable assignment trick doesn't work for pdoc. Instead, fix the name properly and import them as re-export cleanly.
This commit is contained in:
Simon Hausmann 2025-02-08 23:13:21 +01:00 committed by Simon Hausmann
parent 08fc503f68
commit 74f1674c57
6 changed files with 19 additions and 21 deletions

View file

@ -29,7 +29,7 @@ enum PyColorInput {
},
}
#[pyclass]
#[pyclass(name = "Color")]
#[derive(Clone)]
pub struct PyColor {
pub color: slint_interpreter::Color,
@ -124,7 +124,7 @@ enum PyBrushInput {
SolidColor(PyColor),
}
#[pyclass]
#[pyclass(name = "Brush")]
pub struct PyBrush {
pub brush: slint_interpreter::Brush,
}

View file

@ -3,7 +3,7 @@
use pyo3::prelude::*;
#[pyclass(unsendable)]
#[pyclass(unsendable, name = "Image")]
pub struct PyImage {
pub image: slint_interpreter::Image,
}

View file

@ -30,6 +30,9 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
]
dependencies = [
"maturin>=1.8.2",
]
[project.urls]
Homepage = "https://slint.dev"
@ -46,3 +49,9 @@ dev = [
"pdoc>=15.0.1",
"pytest>=8.3.4",
]
[tool.uv]
# Rebuild package when any rust files change
cache-keys = [{file = "pyproject.toml"}, {file = "Cargo.toml"}, {file = "**/*.rs"}]
# Uncomment to build rust code in development mode
# config-settings = { build-args = '--profile=dev' }

View file

@ -13,8 +13,10 @@ import types
import logging
import importlib
import copy
from . import models
from .models import ListModel, Model
from .slint import Image, Color, Brush, Timer, TimerMode
Struct = native.PyStruct
class CompileError(Exception):
def __init__(self, message, diagnostics):
@ -311,16 +313,6 @@ def callback(global_name=None, name=None):
info["global_name"] = global_name
return lambda callback: _callback_decorator(callback, info)
Image = native.PyImage
Color = native.PyColor
Brush = native.PyBrush
ListModel = models.ListModel
Model = models.Model
Timer = native.Timer
TimerMode = native.TimerMode
Struct = native.PyStruct
def set_xdg_app_id(app_id: str):
native.set_xdg_app_id(app_id)

View file

@ -2,9 +2,8 @@
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
from slint import slint as native
from slint import Color, Brush
Color = native.PyColor
Brush = native.PyBrush
def test_col_default():

View file

@ -3,11 +3,9 @@
import pytest
from slint import slint as native
from slint.slint import ValueType, PyImage
from slint.slint import ValueType, Image, Color, Brush
import os
Color = native.PyColor
Brush = native.PyBrush
def test_property_access():
@ -94,9 +92,9 @@ def test_property_access():
assert "cat.jpg" in imageval.path
with pytest.raises(RuntimeError, match="The image cannot be loaded"):
PyImage.load_from_path("non-existent.png")
Image.load_from_path("non-existent.png")
instance.set_property("imageprop", PyImage.load_from_path(os.path.join(
instance.set_property("imageprop", Image.load_from_path(os.path.join(
os.path.dirname(__file__), "../../../examples/iot-dashboard/images/humidity.png")))
imageval = instance.get_property("imageprop")
assert imageval.size == (36, 36)