mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-03 18:29:09 +00:00
Python: Add support for assigning colors directly to brushes
This commit is contained in:
parent
3c9b57ecf8
commit
3e66b98121
3 changed files with 12 additions and 2 deletions
|
@ -32,7 +32,7 @@ enum PyColorInput {
|
|||
#[pyclass]
|
||||
#[derive(Clone)]
|
||||
pub struct PyColor {
|
||||
color: slint_interpreter::Color,
|
||||
pub color: slint_interpreter::Color,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
|
|
|
@ -31,7 +31,7 @@ def test_property_access():
|
|||
in property <bool> boolprop: true;
|
||||
in property <image> imgprop;
|
||||
in property <brush> brushprop: Colors.rgb(255, 0, 255);
|
||||
in property <color> colprop;
|
||||
in property <color> colprop: Colors.rgb(0, 255, 0);
|
||||
in property <[string]> modelprop;
|
||||
in property <MyStruct> structprop: {
|
||||
title: "builtin",
|
||||
|
@ -104,6 +104,12 @@ def test_property_access():
|
|||
brushval = instance.get_property("brushprop")
|
||||
assert str(brushval.color) == "argb(255, 128, 128, 128)"
|
||||
|
||||
brushval = instance.get_property("colprop")
|
||||
assert str(brushval.color) == "argb(255, 0, 255, 0)"
|
||||
instance.set_property("colprop", Color("rgb(128, 128, 128)"))
|
||||
brushval = instance.get_property("colprop")
|
||||
assert str(brushval.color) == "argb(255, 128, 128, 128)"
|
||||
|
||||
with pytest.raises(ValueError, match="no such property"):
|
||||
instance.set_global_property("nonexistent", "theglobalprop", 42)
|
||||
with pytest.raises(ValueError, match="no such property"):
|
||||
|
|
|
@ -75,6 +75,10 @@ impl FromPyObject<'_> for PyValue {
|
|||
ob.extract::<PyRef<'_, crate::brush::PyBrush>>()
|
||||
.map(|pybrush| slint_interpreter::Value::Brush(pybrush.brush.clone()))
|
||||
})
|
||||
.or_else(|_| {
|
||||
ob.extract::<PyRef<'_, crate::brush::PyColor>>()
|
||||
.map(|pycolor| slint_interpreter::Value::Brush(pycolor.color.clone().into()))
|
||||
})
|
||||
.or_else(|_| {
|
||||
ob.extract::<PyRef<'_, crate::models::PyModelBase>>()
|
||||
.map(|pymodel| slint_interpreter::Value::Model(pymodel.as_model()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue