Write Direct Paragraph Area Hatch Class
Overview
Writer has an Area Hatch dialog section.
The ooodev.format.writer.direct.para.area.Hatch
class is used to set the paragraph background hatch.
There are many presets for hatch available.
Using the PresetHatchKind
enum, you can set the hatch to one of the presets.
These examples use the ooodev.theme.ThemeTextDoc
class and the ooodev.utils.color.RGB
to determine the font color for the paragraph text.
This is done to ensure that the text is readable.
Setup
General function used to run these examples:
from typing import TYPE_CHECKING, cast
from ooodev.format.writer.direct.char.font import Font
from ooodev.format.writer.direct.para.area import Hatch, PresetHatchKind
from ooodev.office.write import Write
from ooodev.theme import ThemeTextDoc
from ooodev.utils.color import StandardColor, RGB
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
if TYPE_CHECKING:
from com.sun.star.text import TextRangeContentProperties # service
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.ConnectPipe()):
doc = Write.create_doc()
GUI.set_visible(doc=doc)
Lo.delay(300)
GUI.zoom(GUI.ZoomEnum.ZOOM_100_PERCENT)
cursor = Write.get_cursor(doc)
theme_doc = ThemeTextDoc()
doc_color = RGB.from_int(theme_doc.doc_color)
if doc_color.is_dark():
font_color = StandardColor.WHITE
else:
font_color = StandardColor.BLACK
doc_font_style = Font(color=font_color)
doc_font_style.apply(cursor)
hatch_style = Hatch.from_preset(PresetHatchKind.YELLOW_45_DEGREES_CROSSED)
Write.append_para(cursor=cursor, text=p_txt, styles=[hatch_style])
return 0
if __name__ == "__main__":
SystemExit(main())
Examples
Apply Hatch
Create a hatch for the paragraph background.
# ... other code
cursor = Write.get_cursor(doc)
# ... other code
hatch_style = Hatch.from_preset(PresetHatchKind.YELLOW_45_DEGREES_CROSSED)
Write.append_para(cursor=cursor, text=p_txt, styles=[hatch_style])
Get Hatch from Paragraph
# ... other code
cursor = Write.get_cursor(doc)
# ... other code
para_cursor = Write.get_paragraph_cursor(cursor)
para_cursor.gotoPreviousParagraph(False)
para_cursor.gotoEndOfParagraph(True)
text_para = cast("TextRangeContentProperties", para_cursor)
para_hatch = Hatch.from_obj(text_para.TextParagraph)
assert para_hatch.prop_name == str(PresetHatchKind.YELLOW_45_DEGREES_CROSSED)
para_cursor.gotoEnd(False)