Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--exclude",
dest="exclude",
action="extend",
nargs="+",
default=[],
help="Files and/or directories to exclude from the package",
help="Files and/or directories to exclude from the package "
"(can be used multiple times)",
)
parser.add_argument(
"--clear-cache",
Expand Down
72 changes: 40 additions & 32 deletions sdk/python/packages/flet/src/flet/controls/gradients.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

__all__ = [
"Gradient",
"GradientTileMode",
"LinearGradient",
"RadialGradient",
"SweepGradient",
"GradientTileMode",
]

from flet.controls.types import Number
Expand Down Expand Up @@ -52,39 +52,42 @@ class Gradient:
"""
A shader that renders a color gradient.

There are several types of gradients: `LinearGradient`, `RadialGradient` and
`SweepGradient`.
There are several types of gradients:

- `LinearGradient`
- `RadialGradient`
- `SweepGradient`
"""

colors: list[str]
"""
The colors the gradient should obtain at
each of the stops. This list must contain at least two colors.

If `stops` is provided, this list must have the same length as `stops`.
If [`stops`][(c).] is provided, this list must have the same length as it.
"""

tile_mode: GradientTileMode = GradientTileMode.CLAMP
"""
How this gradient should tile the plane beyond in the region before `begin` and
after `end`.
after `end`.
"""

rotation: Optional[Number] = None
"""
The rotation of the gradient in
[radians](https://en.wikipedia.org/wiki/Radian), around the center-point of its
bounding box.
The rotation of the gradient in [radians](https://en.wikipedia.org/wiki/Radian),
around the center-point of its bounding box.
"""

stops: Optional[list[Number]] = None
"""
A list of values from `0.0` to `1.0` that denote fractions along the gradient.

If provided, this list must have the same length as `colors`. If the first value is
not `0.0`, then a stop with position `0.0` and a color equal to the first color in
`colors` is implied. If the last value is not `1.0`, then a stop with position `1.0`
and a color equal to the last color in `colors` is implied.
If provided, this list must have the same length as [`colors`][(c).].
If the first value is not `0.0`, then a stop with position `0.0` and a
color equal to the first color in [`colors`][(c).] is implied.
If the last value is not `1.0`, then a stop with position `1.0`
and a color equal to the last color in [`colors`][(c).] is implied.
"""

_type: Optional[str] = field(init=False, repr=False, compare=False, default=None)
Expand All @@ -95,15 +98,16 @@ class LinearGradient(Gradient):
"""
Creates a linear gradient from `begin` to `end`.

More information on [here](https://api.flutter.dev/flutter/painting/LinearGradient-class.html).
More information on
[here](https://api.flutter.dev/flutter/painting/LinearGradient-class.html).
"""

begin: Alignment = field(default_factory=lambda: Alignment.center_left())
begin: Alignment = field(default_factory=lambda: Alignment.CENTER_LEFT)
"""
The offset at which stop `0.0` of the gradient is placed.
"""

end: Alignment = field(default_factory=lambda: Alignment.center_right())
end: Alignment = field(default_factory=lambda: Alignment.CENTER_RIGHT)
"""
The offset at which stop `1.0` of the gradient is placed.
"""
Expand All @@ -118,36 +122,38 @@ class RadialGradient(Gradient):
Creates a radial gradient centered at center that ends at radius distance from the
center.

More information [here](https://api.flutter.dev/flutter/painting/RadialGradient-class.html).
More information
[here](https://api.flutter.dev/flutter/painting/RadialGradient-class.html).
"""

center: Alignment = field(default_factory=lambda: Alignment.CENTER)
"""
The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) square
describing the gradient which will be mapped onto the paint box. For example, an
alignment of (0.0, 0.0) will place the radial gradient in the center of the box.
The center of the gradient, as an offset into the `(-1.0, -1.0)` x `(1.0, 1.0)`
square describing the gradient which will be mapped onto the paint box.
For example, an alignment of `(0.0, 0.0)` will place the radial
gradient in the center of the box.
"""

radius: Number = 0.5
"""
The radius of the gradient, as a fraction of the shortest side of the paint box.
For example, if a radial gradient is painted on a box that is 100.0 pixels wide and
200.0 pixels tall, then a radius of 1.0 will place the 1.0 stop at 100.0 pixels from
the `center`.
For example, if a radial gradient is painted on a box that is `100.0` pixels wide
and `200.0` pixels tall, then a radius of `1.0` will place the `1.0` stop at
`100.0` pixels from the [`center`][(c).].
"""

focal: Optional[Alignment] = None
"""
The focal point of the gradient. If specified, the gradient will appear to be
focused along the vector from `center` to focal.
focused along the vector from [`center`][(c).] to focal.
"""

focal_radius: Number = 0.0
"""
The radius of the focal point of gradient, as a fraction of the shortest side of the
paint box. For example, if a radial gradient is painted on a box that is 100.0
pixels wide and 200.0 pixels tall, then a radius of 1.0 will place the 1.0 stop at
100.0 pixels from the focal point.
paint box. For example, if a radial gradient is painted on a box that is `100.0`
pixels wide and `200.0` pixels tall, then a radius of `1.0` will place the `1.0`
stop at `100.0` pixels from the focal point.
"""

def __post_init__(self):
Expand All @@ -160,21 +166,23 @@ class SweepGradient(Gradient):
Creates a sweep gradient centered at center that starts at `start_angle` and ends
at `end_angle`.

More information [here](https://api.flutter.dev/flutter/painting/SweepGradient-class.html).
More information
[here](https://api.flutter.dev/flutter/painting/SweepGradient-class.html).
"""

center: Alignment = field(default_factory=lambda: Alignment.CENTER)
"""
The center of the gradient, as an offset into the (-1.0, -1.0) x (1.0, 1.0) square
describing the gradient which will be mapped onto the paint box.

For example, an `Alignment.CENTER` will place the sweep gradient in the center of the box.
The center of the gradient, as an offset into the `(-1.0, -1.0)` x `(1.0, 1.0)`
square describing the gradient which will be mapped onto the paint box.

For example, an [`Alignment.CENTER`][flet.] will place the sweep gradient
in the center of the box.
"""

start_angle: Number = 0.0
"""
The angle in [radians](https://en.wikipedia.org/wiki/Radian) at which stop `0.0` of
the gradient is placed.
the gradient is placed.
"""

end_angle: Number = math.pi * 2
Expand Down
3 changes: 3 additions & 0 deletions sdk/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ docstring-code-line-length = 80

[tool.pytest.ini_options]
pythonpath = ["."]

[tool.setuptools.packages.find]
include = ["packages*"]