On Wed, 2011-08-17 at 09:06 +0100, Caolán McNamara wrote:
> I imagine that if you basically opengrok for mailmerge.py and
> mailmerge.component and follow the same pattern for your one that it'll
> get you a lot closer.

Seeing as this is a bit tricky to get up and running, attached is a
rough-and-ready patch to turn wizards->letter into "hello world" in
python.

i.e.

a) add a "hello_world.component" (which gets run through the usual xslt
script via the local makefile.mk to tweak it to give the right location
where the .py will finally get installed) that describes a
hello_world.py component. The .component has the implementation name,
e.g. org.openoffice.comp.pyuno.demo.HelloWorld in it and the services it
implements, e.g. com.sun.star.task.Job

b) I added a hello_world.py that implements that, see its
g_ImplementationHelper.addImplementation for the matching implementation
name and services

c) add that hello_world.component to "postprocess" where it will be
basically added as an entry into the services.rdb in the final install
sets install/program/services.rdb (which is an xml file these days. That
should end up having "<component loader="com.sun.star.loader.Python"
uri="vnd.openoffice.pymodule:hello_world"><implementation
name="org.openoffice.comp.pyuno.demo.HelloWorld"><service
name="com.sun.star.task.Job"/></implementation></component></components>" in 
it).

d) change the wizards->letter line in officecfg to call it

e) modify scp2 to install it

f) I haven't a clue what the entry in instsetoo_native does anymore, I
think I used to know :-)

hope this helps.

C.
diff --git a/instsetoo_native/util/makefile.mk b/instsetoo_native/util/makefile.mk
index 8132e8c..137ea2f 100644
--- a/instsetoo_native/util/makefile.mk
+++ b/instsetoo_native/util/makefile.mk
@@ -69,6 +69,7 @@ LOCALPYFILES= \
     $(BIN)$/pythonloader.py \
     $(BIN)$/officehelper.py \
     $(BIN)$/mailmerge.py \
+    $(BIN)$/hello_world.py \
     $(BIN)$/msgbox.py
 .ENDIF
 
diff --git a/officecfg/registry/data/org/openoffice/Office/Common.xcu b/officecfg/registry/data/org/openoffice/Office/Common.xcu
index 998ab38..305f36a 100644
--- a/officecfg/registry/data/org/openoffice/Office/Common.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/Common.xcu
@@ -386,7 +386,7 @@
     <node oor:name="Wizard">
       <node oor:name="m0" oor:op="replace" install:module="writer">
         <prop oor:name="URL"  oor:type="xs:string">
-          <value >service:com.sun.star.wizards.letter.CallWizard?start</value>
+          <value >service:org.openoffice.comp.pyuno.demo.HelloWorld?insert</value>
         </prop>
         <prop oor:name="Title">
           <value xml:lang="en-US">~Letter...</value>
diff --git a/postprocess/packcomponents/makefile.mk b/postprocess/packcomponents/makefile.mk
index bdfecb4..689792d 100644
--- a/postprocess/packcomponents/makefile.mk
+++ b/postprocess/packcomponents/makefile.mk
@@ -376,7 +376,7 @@ my_components += avmediagstreamer
 my_components += avmedia.jar
 .END
 
-my_ooo_components = mailmerge
+my_ooo_components = mailmerge hello_world
 
 .INCLUDE: target.mk
 
diff --git a/pyuno/demo/hello_world_comp.py b/pyuno/demo/hello_world_comp.py
deleted file mode 100644
index 32f4056..0000000
--- a/pyuno/demo/hello_world_comp.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
-
-import uno
-import unohelper
-
-from com.sun.star.task import XJobExecutor
-
-# implement a UNO component by deriving from the standard unohelper.Base class
-# and from the interface(s) you want to implement.
-class HelloWorldJob(unohelper.Base, XJobExecutor):
-    def __init__(self, ctx):
-        # store the component context for later use
-        self.ctx = ctx
-
-    def trigger(self, args):
-        # note: args[0] == "HelloWorld", see below config settings
-
-        # retrieve the desktop object
-        desktop = self.ctx.ServiceManager.createInstanceWithContext(
-            "com.sun.star.frame.Desktop", self.ctx)
-
-        # get current document model
-        model = desktop.getCurrentComponent()
-
-        # access the document's text property
-        text = model.Text
-
-        # create a cursor
-        cursor = text.createTextCursor()
-
-        # insert the text into the document
-        text.insertString(cursor, "Hello World", 0)
-
-# pythonloader looks for a static g_ImplementationHelper variable
-g_ImplementationHelper = unohelper.ImplementationHelper()
-
-g_ImplementationHelper.addImplementation( \
-    HelloWorldJob,                               # UNO object class
-    "org.openoffice.comp.pyuno.demo.HelloWorld", # implemenation name
-    ("com.sun.star.task.Job",),)                 # list of implemented services
-                                                 # (the only service)
-
-# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/scp2/source/ooo/file_ooo.scp b/scp2/source/ooo/file_ooo.scp
index d48bba1..a1c0e77 100644
--- a/scp2/source/ooo/file_ooo.scp
+++ b/scp2/source/ooo/file_ooo.scp
@@ -2126,6 +2126,17 @@ File gid_File_Extension_Dictionary_Zu
 End
 #endif
 
+#ifndef AIX
+#ifndef DISABLE_PYUNO
+File gid_File_PyHelloWorld
+    TXT_FILE_BODY;
+    Dir = gid_Dir_Program;
+    Name = "hello_world.py";
+    Styles = (PACKED);
+End
+#endif
+#endif
+
 // #ifdef BUILD_SPECIAL
 // File gid_File_Extension_Oxt_Oooimprovement
 //    Name = "OOoImprovement.oxt";
diff --git a/scp2/source/ooo/module_hidden_ooo.scp b/scp2/source/ooo/module_hidden_ooo.scp
index f9f29be..f700f30 100644
--- a/scp2/source/ooo/module_hidden_ooo.scp
+++ b/scp2/source/ooo/module_hidden_ooo.scp
@@ -693,6 +693,7 @@ Module gid_Module_Root_Files_6
     gid_File_Oo_Ad_Ldap_Xcd_Sample,
     gid_File_Share_Registry_Main_Xcd,
     gid_File_Share_Registry_Forcedefault_Xcd,
+	gid_File_PyHelloWorld,
 	gid_File_Pymailmerge,
 	gid_File_Pymailmerge_msgbox,
     gid_File_Xsl_Common_Measure_Conversion,
diff --git a/scripting/prj/d.lst b/scripting/prj/d.lst
index f1caf45..f935f29 100644
--- a/scripting/prj/d.lst
+++ b/scripting/prj/d.lst
@@ -16,6 +16,7 @@ mkdir: %_DEST%\bin\pyuno
 
 ..\%__SRC%\lib\lib*static*.dylib %_DEST%\lib\lib*static*.dylib
 ..\%__SRC%\misc\mailmerge.component %_DEST%\xml\mailmerge.component
+..\%__SRC%\misc\hello_world.component %_DEST%\xml\hello_world.component
 ..\%__SRC%\misc\ScriptFramework.component %_DEST%\xml\ScriptFramework.component
 ..\%__SRC%\misc\ScriptProviderForJava.component %_DEST%\xml\ScriptProviderForJava.component
 ..\%__SRC%\misc\basprov.component %_DEST%\xml\basprov.component
diff --git a/scripting/source/pyprov/makefile.mk b/scripting/source/pyprov/makefile.mk
index a304d97..8a90649 100755
--- a/scripting/source/pyprov/makefile.mk
+++ b/scripting/source/pyprov/makefile.mk
@@ -40,12 +40,13 @@ TARGET=pyprov
 ALL : ALLTAR \
     $(DLLDEST)$/officehelper.py	\
     $(DLLDEST)$/msgbox.py \
-    $(DLLDEST)$/mailmerge.py
+    $(DLLDEST)$/mailmerge.py \
+    $(DLLDEST)$/hello_world.py
 
 $(DLLDEST)$/%.py: %.py
     cp $? $@
 
-ALLTAR : $(MISC)/mailmerge.component
+ALLTAR : $(MISC)/mailmerge.component $(MISC)/hello_world.component
 
 $(MISC)/mailmerge.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
         mailmerge.component
@@ -53,6 +54,12 @@ $(MISC)/mailmerge.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
         '$(COMPONENTPREFIX_BASIS_PYTHON)mailmerge' -o $@ \
         $(SOLARENV)/bin/createcomponent.xslt mailmerge.component
 
+$(MISC)/hello_world.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
+        hello_world.component
+    $(XSLTPROC) --nonet --stringparam uri \
+        '$(COMPONENTPREFIX_BASIS_PYTHON)hello_world' -o $@ \
+        $(SOLARENV)/bin/createcomponent.xslt hello_world.component
+
 # scripting provider extension
 .IF "$(L10N_framework)"=="" && "$(ENABLE_SCRIPTING_PYTHON)" == "YES"
 
--- /dev/null	2011-08-03 13:24:57.102409564 +0100
+++ b/scripting/source/pyprov/hello_world.component	2011-08-17 16:21:45.755744886 +0100
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component loader="com.sun.star.loader.Python"
+    xmlns="http://openoffice.org/2010/uno-components";>
+  <implementation name="org.openoffice.comp.pyuno.demo.HelloWorld">
+    <service name="com.sun.star.task.Job"/>
+  </implementation>
+</component>
--- /dev/null	2011-08-03 13:24:57.102409564 +0100
+++ b/scripting/source/pyprov/hello_world.py	2011-08-17 16:03:13.340544116 +0100
@@ -0,0 +1,43 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+
+import uno
+import unohelper
+
+from com.sun.star.task import XJobExecutor
+
+# implement a UNO component by deriving from the standard unohelper.Base class
+# and from the interface(s) you want to implement.
+class HelloWorldJob(unohelper.Base, XJobExecutor):
+    def __init__(self, ctx):
+        # store the component context for later use
+        self.ctx = ctx
+
+    def trigger(self, args):
+        # note: args[0] == "HelloWorld", see below config settings
+
+        # retrieve the desktop object
+        desktop = self.ctx.ServiceManager.createInstanceWithContext(
+            "com.sun.star.frame.Desktop", self.ctx)
+
+        # get current document model
+        model = desktop.getCurrentComponent()
+
+        # access the document's text property
+        text = model.Text
+
+        # create a cursor
+        cursor = text.createTextCursor()
+
+        # insert the text into the document
+        text.insertString(cursor, "Hello World", 0)
+
+# pythonloader looks for a static g_ImplementationHelper variable
+g_ImplementationHelper = unohelper.ImplementationHelper()
+
+g_ImplementationHelper.addImplementation( \
+    HelloWorldJob,                               # UNO object class
+    "org.openoffice.comp.pyuno.demo.HelloWorld", # implemenation name
+    ("com.sun.star.task.Job",),)                 # list of implemented services
+                                                 # (the only service)
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to