Write Direct Character Highlight Class
The ooodev.format.writer.direct.char.highlight.Highlight
is used to set the highlight of one or more characters.
Setting the style
General function used to run these examples.
import sys
from ooodev.format.writer.direct.char.highlight import Highlight
from ooodev.office.write import Write
from ooodev.utils.color import CommonColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(Lo.ConnectPipe()):
doc = Write.create_doc()
GUI.set_visible(doc=doc)
Lo.delay(300)
GUI.zoom(GUI.ZoomEnum.PAGE_WIDTH)
cursor = Write.get_cursor(doc)
hl = Highlight(CommonColor.YELLOW_GREEN)
Write.append(cursor=cursor, text="Highlighting starts ")
pos = Write.get_position(cursor)
Write.append(cursor=cursor, text="here", styles=[hl])
Write.append_para(cursor=cursor, text=".")
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
sys.exit(main())
Examples
Highlight text
cursor = Write.get_cursor(doc)
hl = Highlight(CommonColor.YELLOW_GREEN)
Write.append(cursor=cursor, text="Highlighting starts ")
pos = Write.get_position(cursor)
Write.append(cursor=cursor, text="here", styles=[hl])
Write.append_para(cursor=cursor, text=".")
Getting the style from the text.
cursor.gotoStart(False)
cursor.goRight(pos, False)
cursor.goRight(4, True)
hl = Highlight.from_obj(cursor)
assert hl.prop_color == CommonColor.YELLOW_GREEN
cursor.gotoEnd(False)
Remove Highlighting
Write.style(pos=pos, length=4, styles=[Highlight().empty])