Draw Direct Shape Position Size - Protect

The ooodev.format.draw.direct.position_size.position_size.Protect class is used to modify the values seen in Fig. 862 of a shape.

Setup

from __future__ import annotations
import uno
from ooodev.draw import Draw, DrawDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.format.draw.direct.position_size.position_size import Protect


def main() -> int:
    with Lo.Loader(connector=Lo.ConnectSocket()):
        doc = DrawDoc(Draw.create_draw_doc())
        doc.set_visible()
        Lo.delay(500)
        doc.zoom(ZoomKind.ZOOM_75_PERCENT)

        slide = doc.get_slide()

        width = 36
        height = 36
        x = round(width / 2)
        y = round(height / 2)

        rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
        style = Protect(position=True, size=True)
        style.apply(rect.component)

        f_style = Protect.from_obj(rect.component)
        assert f_style is not None

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


if __name__ == "__main__":
    raise SystemExit(main())

Set Protection of a Shape

Setting protection of the shape is done by using the Protection class.

from ooodev.format.draw.direct.position_size.position_size import Protect
# ... other code

rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
style = Protect(position=True, size=True)
style.apply(rect.component)

The results of the setting the shape protection can be seen in Fig. 864.

Shape with protection set

Fig. 864 Shape with protection set

Note

If the position is set to True then the size will also be set to True. Attempting to set prop_size will be ignored if prop_position is set to True.

Get Shape Position

We can get the protection of the shape by using the Protect.from_obj() method.

from ooodev.format.draw.direct.position_size.position_size import Protect
# ... other code

# get the position from the shape
f_style = Protect.from_obj(rect.component)
assert f_style is not None