sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / pyuno / demo / hello_world_comp.py
blob020953b4f41a0968c8e965e400d3bff8cd4a34b3
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/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import unohelper
22 from com.sun.star.task import XJobExecutor
24 # implement a UNO component by deriving from the standard unohelper.Base class
25 # and from the interface(s) you want to implement.
26 class HelloWorldJob(unohelper.Base, XJobExecutor):
27 def __init__(self, ctx):
28 # store the component context for later use
29 self.ctx = ctx
31 def trigger(self, args):
32 # note: args[0] == "HelloWorld", see below config settings
34 # retrieve the desktop object
35 desktop = self.ctx.ServiceManager.createInstanceWithContext(
36 "com.sun.star.frame.Desktop", self.ctx)
38 # get current document model
39 model = desktop.getCurrentComponent()
41 # access the document's text property
42 text = model.Text
44 # create a cursor
45 cursor = text.createTextCursor()
47 # insert the text into the document
48 text.insertString(cursor, "Hello World", 0)
50 # pythonloader looks for a static g_ImplementationHelper variable
51 g_ImplementationHelper = unohelper.ImplementationHelper()
53 g_ImplementationHelper.addImplementation( \
54 HelloWorldJob, # UNO object class
55 "org.openoffice.comp.pyuno.demo.HelloWorld", # implementation name
56 ("com.sun.star.task.Job",),) # list of implemented services
57 # (the only service)
59 # vim: set shiftwidth=4 softtabstop=4 expandtab: