Draw Direct Shape Text - Columns
The ooodev.format.draw.direct.text.TextColumns
class is used to modify the values seen in Fig. 873 of a shape.
For an example of using text columns with Writer see Live LibreOffice Python UNO - Text Columns Example.
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.text import TextColumns
from ooodev.format.draw.direct.text.text import TextAnchor, ShapeBasePointKind
from ooodev.format.draw.direct.para.alignment import Alignment, ParagraphAdjust
from ooodev.format import Styler
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 = 100
height = 50
x = 10
y = 10
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
sb = []
for _ in range(12):
sb.append("Hello World!")
rect.set_string("\n".join(sb))
anchor = TextAnchor(anchor_point=ShapeBasePointKind.CENTER, full_width=True)
align = Alignment(align=ParagraphAdjust.CENTER)
txt_cols = TextColumns(col_count=2, spacing=0.5)
Styler.apply(rect.component, anchor, align, txt_cols)
Lo.delay(1_000)
doc.close_doc()
return 0
if __name__ == "__main__":
raise SystemExit(main())
Set Text Columns of Shape Text
Setting Text Columns of the shape text is done by using the TextColumns
class.
Note that the anchor and alignment must also be to see the results of the text columns.
The Styler
class is used to apply several styles to the shape at one time.
rect = slide.draw_rectangle(x=x, y=y, width=width, height=height)
# ... other code
anchor = TextAnchor(anchor_point=ShapeBasePointKind.CENTER, full_width=True)
align = Alignment(align=ParagraphAdjust.CENTER)
txt_cols = TextColumns(col_count=2, spacing=0.5)
Styler.apply(rect.component, anchor, align, txt_cols)
The dialog results of the setting the shape text columns can be seen in Fig. 874.
The output results of the setting the shape text columns can be seen in Fig. 875.
Get Shape Text Columns
We can get the text columns of the shape by using the TextColumns.from_obj()
method.
# get the properties from the shape
f_style = TextColumns.from_obj(rect.component)
assert f_style.prop_col_count == 2