Write Style Frame Class

Applying Page Frame Styles can be accomplished using the ooodev.format.writer.style.Frame class.

Setup

General function used to run these examples.

import uno
from ooodev.format.writer.style import Frame, StyleFrameKind
from ooodev.format.writer.modify.frame.area import Color as FrameAreaColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.office.write import Write
from ooodev.units import UnitMM
from ooodev.utils.color import StandardColor

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)

        cursor = Write.get_cursor(doc)

        txt = "Hello"
        Write.append(cursor=cursor, text=txt)

        style = Frame(name=StyleFrameKind.FRAME)
        tf = Write.add_text_frame(
            cursor=cursor,
            ypos=UnitMM(20),
            text="World",
            width=UnitMM(40),
            height=UnitMM(40),
            styles=[style],
        )

        frm_area_color = FrameAreaColor(
            color=StandardColor.BRICK_LIGHT2, style_name=StyleFrameKind.FRAME
        )
        frm_area_color.apply(doc)

        f_style = Frame.from_obj(tf)
        assert f_style.prop_name == style.prop_name

        Lo.delay(1_000)

        Lo.close_doc(doc)

    return 0


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

Apply Style

In this example we will insert a text frame and apply the Frame style as seen in Fig. 1175 to it. Then we will apply the area color Brick Light 2 to the Frame style.

The result of running the following script can be seen in Fig. 1176.

# ... other code
txt = "Hello"
Write.append(cursor=cursor, text=txt)

style = Frame(name=StyleFrameKind.FRAME)
# create a frame and apply the frame style to the text frame
tf = Write.add_text_frame(
    cursor=cursor,
    ypos=UnitMM(20),
    text="World",
    width=UnitMM(40),
    height=UnitMM(40),
    styles=[style],
)

# create a frame area color and apply it to the frame style
frm_area_color = FrameAreaColor(color=StandardColor.BRICK_LIGHT2, style_name=StyleFrameKind.FRAME)
frm_area_color.apply(doc)
Frame Style

Fig. 1175 Frame Style

Styles applied to Frame Page

Fig. 1176 Styles applied to Frame Page

Get Style from Cursor

# ... other code
f_style = Frame.from_obj(tf)
assert f_style.prop_name == style.prop_name