Draw Direct Shape Area Transparency Gradient
The ooodev.format.draw.direct.transparency.Gradient
class is used to modify the values seen in Fig. 846 of a shape.
Setup
from __future__ import annotations
import uno
from ooodev.format import Styler
from ooodev.format.draw.direct.area import Color as ShapeColor
from ooodev.format.draw.direct.transparency import Gradient as ShapeGradient
from ooodev.format.draw.direct.transparency import GradientStyle, IntensityRange
from ooodev.office.draw import Draw
from ooodev.utils.color import StandardColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Draw.create_draw_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
GUI.zoom(GUI.ZoomEnum.ZOOM_75_PERCENT)
slide = Draw.get_slide(doc)
width = 36
height = 36
x = int(width / 2)
y = int(height / 2) + 20
rect = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
color_style = ShapeColor(StandardColor.RED)
style = ShapeGradient(
style=GradientStyle.LINEAR, angle=30, grad_intensity=IntensityRange(0, 100)
)
Styler.apply(rect, color_style, style)
# style.apply(rect)
f_style = ShapeGradient.from_obj(rect)
assert f_style
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Add a gradient transparency to the shape
Adding a transparency gradient to the shape is done by using the ShapeGradient
class.
from ooodev.format import Styler
from ooodev.format.draw.direct.area import Color as ShapeColor
from ooodev.format.draw.direct.transparency import Gradient as ShapeGradient
from ooodev.format.draw.direct.transparency import GradientStyle, IntensityRange
# ... other code
rect = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
color_style = ShapeColor(StandardColor.RED)
style = ShapeGradient(
style=GradientStyle.LINEAR, angle=30, grad_intensity=IntensityRange(0, 100)
)
Styler.apply(rect, color_style, style)
The results of the setting the shape transparency gradient can be seen in Fig. 847.
Get Shape Transparency Gradient
We can get the transparency gradient of the shape by using the ShapeGradient.from_obj()
method.
from ooodev.format.draw.direct.transparency import Gradient as ShapeGradient
# ... other code
# get the style from the shape
f_style = ShapeGradient.from_obj(rect)
assert f_style