Write Direct Paragraph Tabs

Overview

Writer has a Tabs dialog tab.

The ooodev.format.writer.direct.para.tabs.Tabs class is used to set the paragraph tabs.

Writer Paragraph Tabs dialog

Fig. 990 Writer Paragraph Tabs dialog.

Setup

General function used to run these examples:

from ooodev.office.write import Write
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.writer.direct.para.tabs import Tabs, TabAlign, FillCharKind


def main() -> int:
    with Lo.Loader(Lo.ConnectSocket()):
        doc = Write.create_doc()
        GUI.set_visible(True, doc)
        Lo.delay(500)
        GUI.zoom(GUI.ZoomEnum.ENTIRE_PAGE)

        cursor = Write.get_cursor(doc)
        tb = Tabs(position=11.3, align=TabAlign.LEFT, fill_char=FillCharKind.UNDER_SCORE)
        Write.append_para(cursor=cursor, text="Some Paragraph", styles=[tb])

        tb = Tabs(position=12.0, align=TabAlign.DECIMAL)
        tb.apply(cursor)

        tb = Tabs(position=6.5, align=TabAlign.CENTER, fill_char="*")
        tb.apply(cursor)

        tb = Tabs.find(cursor, 6.5)
        tb.prop_align = TabAlign.RIGHT
        tb.prop_fill_char = FillCharKind.DASH
        tb.apply(cursor)

        Tabs.remove_by_pos(cursor, 12.0)

        Tabs.remove_all(cursor)

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


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

Examples

Tabs in Writer are determined by Position. When adding a Tab with the same Position value as another existing Tab it results the existing Tab’s values being updated.

Adding Tabs

Add via creating a paragraph

# ... other code
cursor = Write.get_cursor(doc)
tb = Tabs(position=11.3, align=TabAlign.LEFT, fill_char=FillCharKind.UNDER_SCORE)
Write.append_para(cursor=cursor, text="Some Paragraph", styles=[tb])
Writer Paragraph Tabs dialog

Fig. 991 Writer Paragraph Tabs dialog.

Add via applying directly to Cursor

# ... other code
cursor = Write.get_cursor(doc)
tb = Tabs(position=11.3, align=TabAlign.LEFT, fill_char=FillCharKind.UNDER_SCORE)
Write.append_para(cursor=cursor, text="Some Paragraph", styles=[tb])

tb = Tabs(position=12.0, align=TabAlign.DECIMAL)
tb.apply(cursor)
Writer Paragraph Tabs dialog

Fig. 992 Writer Paragraph Tabs dialog.

# ... other code
cursor = Write.get_cursor(doc)
tb = Tabs(position=11.3, align=TabAlign.LEFT, fill_char=FillCharKind.UNDER_SCORE)
Write.append_para(cursor=cursor, text="Some Paragraph", styles=[tb])

tb = Tabs(position=12.0, align=TabAlign.DECIMAL)
tb.apply(cursor)

tb = Tabs(position=6.5, align=TabAlign.CENTER, fill_char="*")
tb.apply(cursor)
Writer Paragraph Tabs dialog

Fig. 993 Writer Paragraph Tabs dialog.

Updating an existing tab

Finds the tab that was initially set with a position of 6.5, updates is value and applies it to the cursor.

# ... other code
cursor = Write.get_cursor(doc)
tb = Tabs(position=11.3, align=TabAlign.LEFT, fill_char=FillCharKind.UNDER_SCORE)
Write.append_para(cursor=cursor, text="Some Paragraph", styles=[tb])

tb = Tabs(position=12.0, align=TabAlign.DECIMAL)
tb.apply(cursor)

The result is the value are now updated.

Writer Paragraph Tabs dialog

Fig. 994 Writer Paragraph Tabs dialog.

Removing Tabs

Removing a Tab

Remove a Tab can be done via Tabs.remove_by_pos, which removes a tab with it position as input. Or Tabs.remove which can take a Tab or TabStop as input (Tabs inherits from Tab).

# ... other code
Tabs.remove_by_pos(cursor, 12.0)
Writer Paragraph Tabs dialog

Fig. 995 Writer Paragraph Tabs dialog.

# ... other code
Tabs.remove_all(cursor)
Writer Paragraph Tabs dialog

Fig. 996 Writer Paragraph Tabs dialog.