merged tag ooo/DEV300_m102
[LibreOffice.git] / pyuno / demo / hello_world_comp.py
bloba9bc488853ec4bd9b62955d9fa3d435a44db9b86
1 import uno
2 import unohelper
4 from com.sun.star.task import XJobExecutor
6 # implement a UNO component by deriving from the standard unohelper.Base class
7 # and from the interface(s) you want to implement.
8 class HelloWorldJob( unohelper.Base, XJobExecutor ):
9 def __init__( self, ctx ):
10 # store the component context for later use
11 self.ctx = ctx
13 def trigger( self, args ):
14 # note: args[0] == "HelloWorld", see below config settings
16 # retrieve the desktop object
17 desktop = self.ctx.ServiceManager.createInstanceWithContext(
18 "com.sun.star.frame.Desktop", self.ctx )
20 # get current document model
21 model = desktop.getCurrentComponent()
23 # access the document's text property
24 text = model.Text
26 # create a cursor
27 cursor = text.createTextCursor()
29 # insert the text into the document
30 text.insertString( cursor, "Hello World", 0 )
32 # pythonloader looks for a static g_ImplementationHelper variable
33 g_ImplementationHelper = unohelper.ImplementationHelper()
36 g_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)