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/.
14 from com
.sun
.star
.task
import XJobExecutor
17 # The MainJob is a UNO component derived from unohelper.Base class
18 # and also the XJobExecutor, the implemented interface
19 class MainJob(unohelper
.Base
, XJobExecutor
):
20 def __init__(self
, ctx
):
22 # handling different situations (inside LibreOffice or other process)
24 self
.sm
= ctx
.getServiceManager()
25 self
.desktop
= XSCRIPTCONTEXT
.getDesktop()
27 self
.sm
= ctx
.ServiceManager
28 self
.desktop
= self
.ctx
.getServiceManager().createInstanceWithContext(
29 "com.sun.star.frame.Desktop", self
.ctx
)
31 def trigger(self
, args
):
32 desktop
= self
.ctx
.ServiceManager
.createInstanceWithContext(
33 "com.sun.star.frame.Desktop", self
.ctx
)
34 model
= desktop
.getCurrentComponent()
35 if not hasattr(model
, "Text"):
36 model
= self
.desktop
.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())
38 cursor
= text
.createTextCursor()
39 text
.insertString(cursor
, "Hello Extension argument -> " + args
+ "\n", 0)
42 # Starting from Python IDE
47 ctx
= officehelper
.bootstrap()
49 print("ERROR: Could not bootstrap default Office.")
55 # Starting from command line
56 if __name__
== "__main__":
60 # pythonloader loads a static g_ImplementationHelper variable
61 g_ImplementationHelper
= unohelper
.ImplementationHelper()
63 g_ImplementationHelper
.addImplementation(
64 MainJob
, # UNO object class
65 "org.extension.sample.do", # implementation name (customize for yourself)
66 ("com.sun.star.task.Job",), ) # implemented services (only 1)
68 # vim: set shiftwidth=4 softtabstop=4 expandtab: