Write Direct Paragraph Outline & List
Overview
Writer has a Outlines & List dialog tab.
The ooodev.format.writer.direct.para.outline_list.Outline, ooodev.format.writer.direct.para.outline_list.LineNum,
and ooodev.format.writer.direct.para.outline_list.ListStyle classes are used to set the outline, list style, and line numbering of a paragraph.
Fig. 975 Writer Paragraph Outline & List dialog
Setup
from ooodev.office.write import Write
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.writer.direct.para.outline_list import LevelKind, Outline, LineNum, ListStyle
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)
Write.append_para(
cursor=cursor, text=p_txt, styles=[Outline(LevelKind.LEVEL_01)]
)
Write.append_para(
cursor=cursor, text=p_txt, styles=[Outline(LevelKind.TEXT_BODY)]
)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Outline Class
The ooodev.format.writer.direct.para.outline_list.Outline class is used to set the outline level of a paragraph.
Example
In this example the first paragraph is given a outline level of 1 using Outline class.
# ... other code
cursor = Write.get_cursor(doc)
Write.append_para(
cursor=cursor, text=p_txt, styles=[Outline(LevelKind.LEVEL_01)]
)
Fig. 976 Outline, Level 1.
ListStyle Class
Example
When creating a list each paragraph becomes the next list item.
For this reason it is best to create a ListStyle and apply it directly to the cursor.
After list is written the cursor can be reset to a default and seen in the examples below.
Number List
In this example the list is set to a Numbered List using Numbering 123 style.
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)
ol = ListStyle(StyleListKind.NUM_123)
# apply numbered list directly to cursor
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# reset cursor for next paragraph
ol.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
Fig. 977 ListStyle, Numbered List 123.
In this example the list is set to a Numbered List using Numbering ivx style.
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)
ol = ListStyle(StyleListKind.NUM_ivx)
# apply numbered list directly to cursor
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# reset cursor for next paragraph
ol.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
Fig. 978 ListStyle, Numbered List ivx.
Number List Reset
Number styles can also be reset.
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)
# set num_start -2 to force number restart.
ol = ListStyle(list_style=StyleListKind.NUM_123, num_start=-2)
# apply numbered list directly to cursor
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# include line number to reset list number
ol = ListStyle(list_style=StyleListKind.NUM_123, num_start=1)
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# reset cursor for next paragraph
ol.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
Fig. 979 ListStyle, Numbered List with number reset.
Other List Styles
Set style using List 3 style.
cursor = Write.get_cursor(doc)
# set num_start -2 to force number restart.
ol = ListStyle(list_style=StyleListKind.LIST_03, num_start=-2)
# apply numbered list directly to cursor
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# reset cursor for next paragraph
ol.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Fig. 980 ListStyle, Numbered List 3.
Set style using List 5 style.
cursor = Write.get_cursor(doc)
# set num_start -2 to force number restart.
ol = ListStyle(list_style=StyleListKind.LIST_05, num_start=-2)
# apply numbered list directly to cursor
ol.apply(cursor)
for i in range(1, 6):
Write.append_para(cursor=cursor, text=f"Num Point {i}")
# reset cursor for next paragraph
ol.default.apply(cursor)
Write.append_para(cursor=cursor, text=p_txt)
Fig. 981 ListStyle, Numbered List 5.
LineNum Class
The LineNum class is used to set line numbering for a paragraph.
If num=0 then this paragraph is include in line numbering.
If num=-1 then this paragraph is excluded in line numbering.
If greater then zero then this paragraph is included in line numbering and the numbering is restarted with value of num.
Example
Set to 3
In this example the paragraph line number start value is set to 3.
# ... other code
ln = LineNum(3)
Write.append_para(cursor=cursor, text=p_txt, styles=[ln])
Fig. 982 Paragraph Line Numbering
Fig. 983 Paragraph Outline & List dialog.
Exclude
In this example the paragraph line number start value is set to -1 (exclude).
# ... other code
ln = LineNum(-1)
Write.append_para(cursor=cursor, text=p_txt, styles=[ln])
Fig. 984 Paragraph Line Numbering
Fig. 985 Paragraph Outline & List dialog.
Include
In this example the paragraph line number start value is set to 0 (include).
# ... other code
ln = LineNum(0)
Write.append_para(cursor=cursor, text=p_txt, styles=[ln])
Fig. 986 Paragraph Line Numbering
Fig. 987 Paragraph Outline & List dialog.