1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
17 remote_context
= officehelper
.bootstrap()
18 print("Connected to a running office ...")
19 srv_mgr
= remote_context
.getServiceManager()
20 desktop
= srv_mgr
.createInstanceWithContext("com.sun.star.frame.Desktop", remote_context
)
22 print("Opening an empty Writer document")
23 doc_url
= "private:factory/swriter"
24 doc
= desktop
.loadComponentFromURL(doc_url
, "_blank", 0, tuple())
27 text
.setString("Please select something in this text and press then \"return\" in the shell "
28 "where you have started the example.\n")
30 # Returned object supports service com.sun.star.text.TextDocumentView and com.sun.star.view.OfficeDocumentView
31 # Both of them implements interface com::sun::star::view::XViewSettingsSupplier
32 obj
= doc
.getCurrentController()
33 obj
.getViewSettings().setPropertyValue("ZoomType", 0)
36 input("Please select something in the test document and press "
37 "then \"return\" to continues the example ... ")
39 frame
= desktop
.getCurrentFrame()
40 selection
= frame
.getController().getSelection()
42 if selection
.supportsService("com.sun.star.text.TextRanges"):
43 for selected
in selection
:
44 print("You have selected a text range:", f
'"{selected.getString()}".')
46 if selection
.supportsService("com.sun.star.text.TextGraphicObject"):
47 print("You have selected a graphics.")
49 if selection
.supportsService("com.sun.star.text.TexttableCursor"):
50 print("You have selected a text table.")
52 # When object returned from loadComponentFromURL does not support a service
53 # that implements XCloseable interface, fallback to call
64 if __name__
== "__main__":
67 # vim: set shiftwidth=4 softtabstop=4 expandtab: