xref: /aoo42x/main/pyuno/demo/hello_world_comp.py (revision cdf0e10c)
1import uno
2import unohelper
3
4from com.sun.star.task import XJobExecutor
5
6# implement a UNO component by deriving from the standard unohelper.Base class
7# and from the interface(s) you want to implement.
8class HelloWorldJob( unohelper.Base, XJobExecutor ):
9    def __init__( self, ctx ):
10        # store the component context for later use
11        self.ctx = ctx
12
13    def trigger( self, args ):
14        # note: args[0] == "HelloWorld", see below config settings
15
16        # retrieve the desktop object
17        desktop = self.ctx.ServiceManager.createInstanceWithContext(
18            "com.sun.star.frame.Desktop", self.ctx )
19
20        # get current document model
21        model = desktop.getCurrentComponent()
22
23	# access the document's text property
24	text = model.Text
25
26	# create a cursor
27	cursor = text.createTextCursor()
28
29	# insert the text into the document
30	text.insertString( cursor, "Hello World", 0 )
31
32# pythonloader looks for a static g_ImplementationHelper variable
33g_ImplementationHelper = unohelper.ImplementationHelper()
34
35#
36g_ImplementationHelper.addImplementation( \
37	HelloWorldJob,                        # UNO object class
38	"org.openoffice.comp.pyuno.demo.HelloWorld", # implemenation name
39	("com.sun.star.task.Job",),)          # list of implemented services
40	                                      # (the only service)
41