Write Direct Paragraph Borders

Overview

Writer has an Borders dialog tab.

The ooodev.format.writer.direct.para.borders.Borders class is used to set the paragraph borders.

Writer Paragraph Borders dialog

Fig. 942 Writer Paragraph Borders dialog.

Setup

General function used to run these examples:

from ooodev.format.writer.style import Para as StylePara
from ooodev.office.write import Write
from ooodev.utils.color import CommonColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.writer.direct.para.borders import (
    Borders,
    BorderLineKind,
    Padding,
    Side,
    Shadow,
)

def main() -> int:
    p_txt = (
        "To Sherlock Holmes she is always THE woman. I have seldom heard"
        " him mention her under any other name. In his eyes she eclipses"
        " and predominates the whole of her sex. It was not that he felt"
        " any emotion akin to love for Irene Adler. All emotions, and that"
        " one particularly, were abhorrent to his cold, precise but"
        " admirably balanced mind. He was, I take it, the most perfect"
        " reasoning and observing machine that the world has seen, but as a"
        " lover he would have placed himself in a false position. He never"
        " spoke of the softer passions, save with a gibe and a sneer. They"
        " were admirable things for the observer--excellent for drawing the"
        " veil from men's motives and actions. But for the trained reasoner"
        " to admit such intrusions into his own delicate and finely"
        " adjusted temperament was to introduce a distracting factor which"
        " might throw a doubt upon all his mental results. Grit in a"
        " sensitive instrument, or a crack in one of his own high-power"
        " lenses, would not be more disturbing than a strong emotion in a"
        " nature such as his. And yet there was but one woman to him, and"
        " that woman was the late Irene Adler, of dubious and questionable memory."
    )

    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)
        bdr = Borders(
            all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET),
            shadow=Shadow(),
            padding=Padding(all=1.7),
            merge=False,
        )
        Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
        StylePara.default.apply(cursor)
        Write.append_para(cursor=cursor, text=p_txt)
        Lo.delay(1_000)
        Lo.close_doc(doc)
    return 0


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

Examples

After applying borders to a paragraph, the default paragraph style is applied to the paragraph using Resetting Paragraph Style to Default.

Apply Border

Create a border around a paragraph.

Note that next paragraph has the same border properties because merge is the default behaviour.

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET))
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
Write.append_para(cursor=cursor, text=p_txt)
Writer Paragraph Borders

Fig. 943 Writer Paragraph Borders.

Writer Paragraph Borders Dialog

Fig. 944 Writer Paragraph Borders Dialog.

When merge=False the paragraphs have the same border properties but are not merged.

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET), merge=False)
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
Write.append_para(cursor=cursor, text=p_txt)
Writer Paragraph Borders

Fig. 945 Writer Paragraph Borders.

Resetting for the next paragraph can be done by applying Para.default to the cursor.

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET), merge=False)
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
StylePara.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Writer Paragraph Borders

Fig. 946 Writer Paragraph Borders.

Apply Border With Shadow

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(
    all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET),
    shadow=Shadow(),
    merge=False,
)
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
StylePara.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Writer Paragraph Borders

Fig. 947 Writer Paragraph Borders.

Writer Paragraph Borders Dialog

Fig. 948 Writer Paragraph Borders Dialog.

Apply Border With Shadow and Padding

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(
    all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET),
    padding=Padding(all=7.7),
    shadow=Shadow(),
    merge=False,
)
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])
StylePara.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Writer Paragraph Borders

Fig. 949 Writer Paragraph Borders.

Writer Paragraph Borders Dialog

Fig. 950 Writer Paragraph Borders Dialog.

Getting Borders from Paragraph

A paragraph cursor object is used to select the first paragraph in the document. The paragraph cursor is then used to get the style.

# ... other code

cursor = Write.get_cursor(doc)
bdr = Borders(
    all=Side(line=BorderLineKind.DASH_DOT, color=CommonColor.BLUE_VIOLET),
    padding=Padding(all=7.7),
    shadow=Shadow(),
    merge=False,
)
Write.append_para(cursor=cursor, text=p_txt, styles=[bdr])

para_cursor = Write.get_paragraph_cursor(cursor)
para_cursor.gotoPreviousParagraph(False)
para_cursor.gotoEndOfParagraph(True)

para_bdr = Borders.from_obj(para_cursor)
assert para_bdr.prop_inner_sides.prop_left.prop_line == BorderLineKind.DASH_DOT
assert para_bdr.prop_inner_sides.prop_right.prop_color == CommonColor.BLUE_VIOLET

StylePara.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)