Draw Direct Shape Area Transparency Transparency

The ooodev.format.draw.direct.transparency.Transparency class is used to modify the values seen in Fig. 848 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 Transparency as ShapeTransparency
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 = ShapeTransparency(60)
        Styler.apply(rect, color_style, style)
        # style.apply(rect)

        f_style = ShapeTransparency.from_obj(rect)
        assert f_style

        Lo.delay(1_000)
        Lo.close_doc(doc)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
Area Transparency dialog

Fig. 848 Area Pattern dialog

Add a transparency to the shape

Adding a transparency to the shape is done by using the ShapeTransparency class.

from ooodev.format import Styler
from ooodev.format.draw.direct.transparency import Transparency as ShapeTransparency
# ... other code

rect = Draw.draw_rectangle(slide=slide, x=x, y=y, width=width, height=height)
color_style = ShapeColor(StandardColor.RED)
style = ShapeTransparency(60)
Styler.apply(rect, color_style, style)

The results of the setting the shape style can be seen in Fig. 849.

Shape with pattern

Fig. 849 Shape with pattern

Get Shape Transparency

We can get the style of the shape by using the ShapeTransparency.from_obj() method.

from ooodev.format.draw.direct.area import Pattern as ShapeTransparency
# ... other code

# get the style from the shape
f_style = ShapeTransparency.from_obj(rect)
assert f_style