diff options
author | Xisco Fauli <anistenis@gmail.com> | 2013-02-17 14:59:45 +0100 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2013-02-17 15:27:38 +0100 |
commit | 70b6d7510d6910e046342114a79321ae8654764a (patch) | |
tree | 54d9c1bea910118432917a9ed9a1822f2b77a015 /scripting | |
parent | f27f13b8e8865f0e39fbb9489ed1c0b65857b90e (diff) |
fdo#60670: Create a new document in case there's none
Change-Id: I7e03481beb1d4e60601fd93d787bc7354495e41f
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/examples/python/HelloWorld.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/scripting/examples/python/HelloWorld.py b/scripting/examples/python/HelloWorld.py index 48e778673298..4cad8a8549ea 100644 --- a/scripting/examples/python/HelloWorld.py +++ b/scripting/examples/python/HelloWorld.py @@ -21,7 +21,12 @@ def HelloWorldPython( ): """Prints the string 'Hello World(in Python)' into the current document""" #get the doc from the scripting context which is made available to all scripts - model = XSCRIPTCONTEXT.getDocument() + desktop = XSCRIPTCONTEXT.getDesktop() + model = desktop.getCurrentComponent() +#check whether there's already an opened document. Otherwise, create a new one + if not hasattr(model, "Text"): + model = desktop.loadComponentFromURL( + "private:factory/swriter","_blank", 0, () ) #get the XText interface text = model.Text #create an XTextRange at the end of the document |