Write Direct Shape Area Transparency Transparency

The ooodev.format.writer.direct.shape.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.writer.direct.shape.transparency import Transparency as ShapeTransparency
from ooodev.utils.color import StandardColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.office.write import Write
from ooodev.office.draw import Draw


def main() -> int:
    with Lo.Loader(Lo.ConnectPipe()):
        doc = Write.create_doc()
        GUI.set_visible(doc=doc)
        Lo.delay(300)
        GUI.zoom(GUI.ZoomEnum.ENTIRE_PAGE)

        page = Write.get_draw_page(doc)
        rect = Draw.draw_rectangle(slide=page, x=10, y=10, width=100, height=100)
        color_style = ShapeColor(StandardColor.RED)
        style = ShapeTransparency(60)
        Styler.apply(rect, color_style, style)
        page.add(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())

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. 1010.

Shape with pattern

Fig. 1010 Shape with pattern

Get Shape Transparency

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

from ooodev.format.writer.direct.shape.transparency import Transparency as ShapeTransparency
# ... other code

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