OOO Development Tools

Book:

  • Python LibreOffice Programming

Help:

  • Help Documentation
    • Spreadsheets (Calc)
    • Chart2
    • Draw Documents (Draw)
    • Text Documents (Writer)
      • Write Formatting and Style
        • Direct
        • Modify
        • Style
    • Common Help Topics

Guides:

  • Guides

Misc:

  • Events
  • Version History
  • Credits and Acknowledgements

DEVELOPER API:

  • ooodev

DEVELOPING ODEV:

  • Dev Docs
OOO Development Tools
  • Help Documentation
  • Text Documents (Writer)
  • Write Formatting and Style
  • Direct
  • Writer Format Direct Character
  • Write Direct Character Hyperlink Class
  • Edit on GitHub

Write Direct Character Hyperlink Class

Table of Contents

  • Setting the style

  • Examples

    • Adding Hyperlink

    • Remove Hyperlink

    • Getting the Hyperlink from the text

  • Related Topics

The ooodev.format.writer.direct.char.hyperlink.Hyperlink class is used to create a hyperlink in a document.

Setting the style

General function used to run these examples.

import sys
from ooodev.format.writer.direct.char.hyperlink import Hyperlink, TargetKind
from ooodev.office.write import Write
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.ENTIRE_PAGE)
        cursor = Write.get_cursor(doc)

        ln_name = "OooDev"
        ln_url = "https://python-ooo-dev-tools.readthedocs.io/en/latest/"

        hl = Hyperlink(name=ln_name, url=ln_url)
        Write.append(cursor, "OOO Development Tools", (hl,))
        Write.append_para(cursor, " Docs")

        Write.append(cursor, "Source on Github ")

        pos = Write.get_position(cursor)

        ln_name = "OOODEV_GITHUB"
        ln_url = "https://github.com/Amourspirit/python_ooo_dev_tools"
        hl = Hyperlink(name=ln_name, url=ln_url, target=TargetKind.BLANK)
        Write.append(cursor, "OOO Development Tools on Github", (hl,))

        Lo.delay(2_000)

        # remove the hyperlink
        Write.style_left(cursor=cursor, pos=pos, styles=(hl.empty,))

        # get the hyperlink from the document
        cursor.gotoStart(False)
        cursor.goRight(21, True)
        ooo_dev_hl = Hyperlink.from_obj(cursor)
        cursor.gotoEnd(False)
        print(ooo_dev_hl.prop_url)

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

    return 0


if __name__ == "__main__":
    sys.exit(main())

Examples

Adding Hyperlink

cursor = Write.get_cursor(doc)

ln_name = "OooDev"
ln_url = "https://python-ooo-dev-tools.readthedocs.io/en/latest/"
hl = Hyperlink(name=ln_name, url=ln_url)

Write.append(cursor, "OOO Development Tools", (hl,))
Write.append_para(cursor, " Docs")
# ... other code
Hyperlink text

Fig. 931 Hyperlink text

Remove Hyperlink

cursor = Write.get_cursor(doc)
# ... other code

pos = Write.get_position(cursor)

# ... other code

Write.style_left(cursor=cursor, pos=pos, styles=(hl.empty,))
Hyperlink removed

Fig. 932 Hyperlink removed

Getting the Hyperlink from the text

# ... other code
# get the hyperlink from the document
cursor.gotoStart(False)
cursor.goRight(21, True)
ooo_dev_hl = Hyperlink.from_obj(cursor)
cursor.gotoEnd(False)
print(ooo_dev_hl.prop_url)

Related Topics

See also

  • Formatting and Styling kinds

  • Format Coding Style

  • GUI

  • Lo

  • ooodev.format.writer.direct.char.hyperlink.Hyperlink

Previous Next

© Copyright 2022-2024, :Barry-Thomas-Paul: Moss. Revision 8b0142c4.

Built with Sphinx using a theme provided by Read the Docs.