fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / pyuno / demo / hello_world_comp.py
blob73bdc1fc4257b276262dedbfcbc1eeecf4bbae47
1 # -*- tab-width: 4; indent-tabs-mode: nil; c-basic-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 uno
21 import unohelper
23 from com.sun.star.task import XJobExecutor
25 # implement a UNO component by deriving from the standard unohelper.Base class
26 # and from the interface(s) you want to implement.
27 class HelloWorldJob(unohelper.Base, XJobExecutor):
28 def __init__(self, ctx):
29 # store the component context for later use
30 self.ctx = ctx
32 def trigger(self, args):
33 # note: args[0] == "HelloWorld", see below config settings
35 # retrieve the desktop object
36 desktop = self.ctx.ServiceManager.createInstanceWithContext(
37 "com.sun.star.frame.Desktop", self.ctx)
39 # get current document model
40 model = desktop.getCurrentComponent()
42 # access the document's text property
43 text = model.Text
45 # create a cursor
46 cursor = text.createTextCursor()
48 # insert the text into the document
49 text.insertString(cursor, "Hello World", 0)
51 # pythonloader looks for a static g_ImplementationHelper variable
52 g_ImplementationHelper = unohelper.ImplementationHelper()
54 g_ImplementationHelper.addImplementation( \
55 HelloWorldJob, # UNO object class
56 "org.openoffice.comp.pyuno.demo.HelloWorld", # implementation name
57 ("com.sun.star.task.Job",),) # list of implemented services
58 # (the only service)
60 # vim:set shiftwidth=4 softtabstop=4 expandtab: