Draw Direct Shape Position Size - Size
The ooodev.format.draw.direct.position_size.position_size.Size
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 Size
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 = Size(width=50, height=50)
style.apply(rect.component)
f_style = Size.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 Size of a Shape
Setting size of the shape is done by using the Size
class.
from ooodev.format.draw.direct.position_size.position_size import Size
# ... other code
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
style = Size(width=50, height=50)
style.apply(rect.component)
The results of the setting the shape size can be seen in Fig. 865.
Get Shape Size
We can get the position of the shape by using the Size.from_obj()
method.
from ooodev.format.draw.direct.position_size.position_size import Size
# ... other code
# get the size from the shape
f_style = Size.from_obj(rect.component)
assert f_style is not None