diff options
author | Chenxiong Qi <qcxhome@gmail.com> | 2022-09-14 09:29:25 +0800 |
---|---|---|
committer | Hossein <hossein@libreoffice.org> | 2022-10-13 15:41:40 +0200 |
commit | 665d1633c9e08da85fae179e62923211bc07c480 (patch) | |
tree | cd6d451f6b57b21f086278be851ae8b69fe0f57f /odk/examples/python/DocumentLoader | |
parent | 5956cecdf61846671f7d028ad60623e1e840ad3f (diff) |
tdf#143123 port DocumentHandling examples to Python
This port keeps the similarity with Java ones as much as possible.
examples.html is also updated by adding the Python examples.
Signed-off-by: Chenxiong Qi <qcxhome@gmail.com>
Change-Id: I2af26aaf42f5408bf254a4e0507442200f843661
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139887
Tested-by: Jenkins
Reviewed-by: Hossein <hossein@libreoffice.org>
Diffstat (limited to 'odk/examples/python/DocumentLoader')
-rw-r--r-- | odk/examples/python/DocumentLoader/DocumentLoader.py | 44 | ||||
-rw-r--r-- | odk/examples/python/DocumentLoader/README.md | 12 |
2 files changed, 0 insertions, 56 deletions
diff --git a/odk/examples/python/DocumentLoader/DocumentLoader.py b/odk/examples/python/DocumentLoader/DocumentLoader.py deleted file mode 100644 index 521b63ce9066..000000000000 --- a/odk/examples/python/DocumentLoader/DocumentLoader.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# - -import uno -from com.sun.star.connection import NoConnectException -from os.path import isfile, abspath -from sys import argv, exit - -if __name__ == "__main__": - if len(argv) < 2: - print("usage: $OFFICE_PROGRAM_PATH/python DocumentLoader.py <path>") - exit(1) - if not isfile(argv[1]): - print("%s could not be opened" % argv[1]) - exit(1) - - # UNO component context for initializing the Python runtime - localContext = uno.getComponentContext() - - # Create an instance of a service implementation - resolver = localContext.ServiceManager.createInstanceWithContext( - "com.sun.star.bridge.UnoUrlResolver", localContext) - - try: - context = resolver.resolve( - "uno:socket,host=localhost," - "port=2083;urp;StarOffice.ComponentContext") - except NoConnectException: - raise Exception("Error: cannot establish a connection to LibreOffice.") - - desktop = context.ServiceManager.createInstanceWithContext( - "com.sun.star.frame.Desktop", context) - url = uno.systemPathToFileUrl(abspath(argv[1])) - - # Load a LibreOffice document, and automatically display it on the screen - xComp = desktop.loadComponentFromURL(url, "_blank", 0, tuple([])) - -# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/odk/examples/python/DocumentLoader/README.md b/odk/examples/python/DocumentLoader/README.md deleted file mode 100644 index d95c933ab9c1..000000000000 --- a/odk/examples/python/DocumentLoader/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# DocumentLoader -This example is somehow similar to DocumentLoader in C++ and Java. -to get started, first start LibreOffice listening on port 2083 - - $OFFICE_PROGRAM_PATH/soffice "--accept=socket,port=2083;urp;" - -The syntax to run this example is: - - $OFFICE_PROGRAM_PATH/python DocumentLoader.py <path> - -You should use 'setsdkenv_unix' for Unix/Linux and setsdkenv_windows.bat for Windows. In this way, -the LibreOffice internal Python interpreter will be used. |