tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / scripting / examples / python / HelloWorld.py
blobed21b200845b037bab039d93d052d79b4707e4c4
1 # HelloWorld python script for the scripting framework
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # This file incorporates work covered by the following license notice:
12 # Licensed to the Apache Software Foundation (ASF) under one or more
13 # contributor license agreements. See the NOTICE file distributed
14 # with this work for additional information regarding copyright
15 # ownership. The ASF licenses this file to you under the Apache
16 # License, Version 2.0 (the "License"); you may not use this file
17 # except in compliance with the License. You may obtain a copy of
18 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 def HelloWorldPython():
22 """Prints the string 'Hello World (in Python)' into the current document.
23 """
25 # Get the doc from the scripting context which is made available to all
26 # scripts.
27 desktop = XSCRIPTCONTEXT.getDesktop()
28 model = desktop.getCurrentComponent()
30 # Check whether there's already an opened document.
31 # Otherwise, create a new one
32 if not hasattr(model, "Text"):
33 model = desktop.loadComponentFromURL(
34 "private:factory/swriter", "_blank", 0, ())
36 # get the XText interface
37 text = model.Text
39 # create an XTextRange at the end of the document
40 tRange = text.End
42 # and set the string
43 tRange.String = "Hello World (in Python)"
45 return None
47 # vim: set shiftwidth=4 softtabstop=4 expandtab: