| View previous topic :: View next topic |
| Author |
Message |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sun May 13, 2012 6:55 pm Post subject: [Solved] Porting a Java extension to Python |
|
|
(All the files that are mentioned in here are in http://dl.dropbox.com/u/41945052/test.oxt )
Hi all,
I'm currently trying to port the Creative Commons extension for LibreOffice from Java to Python (the source for the Java code can be obtained from http://code.creativecommons.org/svnroot/ccooo/branches/akila-gsoc-2010 ). I decided to use the same Addons.xcu , description.xml , META-INF/manifest.xml files. I added a test python file named test.py and and edited the entry in the META-INF/manifest.xml file from ,
| Code: | | <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java" manifest:full-path="cooo.jar"/> |
to
| Code: | | <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Python" manifest:full-path="test.py"/> |
Then I added everything to a folder and zipped the folder and changed the extension to .oxt and installed it to LibreOffice. According to the Addons.xcu , a new menu item named creative commons should appear under the Insert menu. But this is not visible. Also I cannot uninstall the extension by clicking on the remove button in the extensions manager. Nothing happens when I click on the remove button.
Can somebody help me to establish the menu entries using these files..? Also, as I'm a novice to LibreOffice extensions development, am I doing this packaging in a correct way..?[/url]
Last edited by ishanthilina on Wed May 16, 2012 9:06 am; edited 1 time in total |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sun May 13, 2012 11:53 pm Post subject: |
|
|
| Your oxt package have to be packed as these files are placed in the top of the zip archive. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Mon May 14, 2012 3:58 am Post subject: function binding |
|
|
| hanya wrote: | | Your oxt package have to be packed as these files are placed in the top of the zip archive. |
It worked..!. Thanks a lot Hanya .
Now I need to rectify another thingy. I need to bind the function calls in the Addons.xcu file to the methods in the test.py. Can someone please point out how can I do this for the following line?
The line 42 in Addons.xcu
| Code: | | <value>org.creativecommons.openoffice.ccooo:InsertStatement</value> |
I need to bind this function call to a function in the test.py. I tried adding the following lines. But it did not work.
| Code: | def InsertStatement():
print 'TEST'
|
I get the message, This operation is not supported on this operating system
Can somebody please help to rectify this issue? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Mon May 14, 2012 6:39 am Post subject: |
|
|
| Quote: | | I need to bind this function call to a function in the test.py. I tried adding the following lines. But it did not work. | You can not make direct link to the python function stored in the component file from Addons.xcu.
It seems your test package includes service supports XJobExecutor interface, it can call like as follows: | Code: | | service:org.creativecommons.openoffice.ccooo.Import? |
And the original extension uses protocol handler mechanism to execute. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Wed May 16, 2012 9:05 am Post subject: Thank you! |
|
|
| hanya wrote: | | Quote: | | I need to bind this function call to a function in the test.py. I tried adding the following lines. But it did not work. | You can not make direct link to the python function stored in the component file from Addons.xcu.
It seems your test package includes service supports XJobExecutor interface, it can call like as follows: | Code: | | service:org.creativecommons.openoffice.ccooo.Import? |
And the original extension uses protocol handler mechanism to execute. |
Thanks a lot Hanya. That solves the problem. You are really helpful  |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Fri May 18, 2012 9:02 pm Post subject: |
|
|
| hanya wrote: | | Quote: | | I need to bind this function call to a function in the test.py. I tried adding the following lines. But it did not work. | You can not make direct link to the python function stored in the component file from Addons.xcu.
It seems your test package includes service supports XJobExecutor interface, it can call like as follows: | Code: | | service:org.creativecommons.openoffice.ccooo.Import? |
And the original extension uses protocol handler mechanism to execute. |
Hanya,
I'd also like to learn the protocol handler mechanism , can you please point out the things I need to add/change in my test.py in order to use the protocol handler mechanism..?
I tried adding the following part to test.py
| Code: | from com.sun.star.frame import XDispatch
class addin(unohelper.Base, XDispatch):
"""
"""
def __init__(self,ctx ):
"""
"""
self.ctx=ctx
def dispatch(url, arguments):
print 'in dispatch'
g_ImplementationHelper.addImplementation(
addin,
"org.creativecommons.openoffice.ccooo:InsertPictureFlickr",
("com.sun.star.task.Job",),)
|
Also I added the following ProtocolHandler.xcu file to the root of the folder hierarchy.
| Code: |
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" oor:name="ProtocolHandler" oor:package="org.openoffice.Office">
<node oor:name="HandlerSet">
<node oor:name="org.creativecommons.openoffice.CcOOoAddin" oor:op="replace">
<prop oor:name="Protocols" oor:type="oor:string-list">
<value>org.creativecommons.openoffice.ccooo:*</value>
</prop>
</node>
</node>
</oor:component-data>
|
But I still get the This operation is not supported by this operating system error.
Thanks a lot for the support you are providing.[/code] |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Fri May 18, 2012 10:39 pm Post subject: |
|
|
You have to implement your component according to:
http://api.libreoffice.org/docs/common/ref/com/sun/star/frame/ProtocolHandler.html
And
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Protocol_Handler
You can port original org.creativecommons.openoffice.CcOOoAddin class from Java to Python.
Your component should be registered under css.frame.ProtocolHandler service and it must to implement css.frame.XDispatchProvider interface. I suppose you to implement css.lang.XInitialization interface too. If the component supports it written in Python, the initialize method is not called but the arguments are passed to the constructor of the class which implements the component. And also css.lang.XServiceInfo interface is required.
The following code is not tested but it could be something like: | Code: |
import unohelper
from com.sun.star.frame import XDispatch, XDispatchProvider
from com.sun.star.lang import XInitialization, XServiceInfo
SERVICE_NAME = "com.sun.star.frame.ProtocolHandler"
IMPLE_NAME = "org.creativecommons.openoffice.ccooo:InsertPictureFlickr"
class Example(unohelper.Base, XInitialization, XServiceInfo, XDispatchProvider, XDispatch):
def __init__(self, ctx, *args):
self.ctx = ctx
self.frame = None
self.initialize(args)
def supportsService(self,name):
return (name == SERVICE_NAME)
def getImplementationName(self):
return IMPLE_NAME
def getSupportedServiceNames(self):
return (SERVICE_NAME,)
# XInitialization
def initialize(self, args):
if args:
self.frame = args[0]
# XDispatchProvider
def queryDispatch(self, url, name, flags):
if url.Protocol == "foo:":
return self
return None
def queryDispatches(self, req):
pass
# XDispatch
def dispatch(self, url, args):
if url.Complete == "foo:do":
self.do()
def addStatusListener(self, control, url):
pass
def removeStatusListener(self, control, url):
pass
def do(self):
pass
g_ImplementationHelper.addImplementation(
Example,
"org.creativecommons.openoffice.ccooo:InsertPictureFlickr",
("com.sun.star.frame.ProtocolHandler",),) |
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sat May 19, 2012 2:20 am Post subject: |
|
|
Thanks a lot for the reply Hanya.
I modified the queryDispatch method as follows (Hoping that it will get called in a gui event). But I cannot see any output (Except theb). This operation is not supported by this operating system error.
| Code: |
# XDispatchProvider
def queryDispatch(self, url, name, flags):
print 'ss'
if url.Protocol == "org.creativecommons.openoffice.ccooo:":
return self
return None
|
Following is the link to the complete extension.
http://dl.dropbox.com/u/41945052/project.oxt
Can you please provide me a hint on where have I got the things wrong :-s |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sat May 19, 2012 4:28 am Post subject: |
|
|
The name of the child node of HandlerSet node must to be the same with the implementation name of your protocol handler: | Code: | <oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node oor:name="HandlerSet">
<node oor:name="org.creativecommons.openoffice.CcOOoAddin" oor:op="replace"> |
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sat May 19, 2012 6:49 am Post subject: |
|
|
Dear Hanya,
Really sorry for being such a pain to you. But I still cannot get this working.
What I did-
1- Rename the test.py file as CcOOoAddin.py
2- Edited the ProtocolHandler.xcu file as follows.
| Code: | <?xml version='1.0' encoding='UTF-8'?>
<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node oor:name="HandlerSet">
<node oor:name="org.creativecommons.openoffice.CcOOoAddin" oor:op="replace">
<prop oor:name="Protocols" oor:type="oor:string-list">
<value>org.creativecommons.openoffice.ccooo:*</value>
</prop>
</node>
</node>
</oor:component-data> |
But still it's not working
The extension with the changes can be downloaded from http://dl.dropbox.com/u/41945052/project_1.oxt |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sat May 19, 2012 7:29 am Post subject: |
|
|
The implementation name of your component is specified in the second argument of the addImplementation method of the implementation helper:
| Code: | g_ImplementationHelper.addImplementation(
Example,
IMPLE_NAME,
(SERVICE_NAME_1,),) |
And the same name have to be returned by the getImplementationName method of css.lang.XServiceInfo interface. |
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sat May 19, 2012 8:02 am Post subject: |
|
|
| hanya wrote: | The implementation name of your component is specified in the second argument of the addImplementation method of the implementation helper:
| Code: | g_ImplementationHelper.addImplementation(
Example,
IMPLE_NAME,
(SERVICE_NAME_1,),) |
And the same name have to be returned by the getImplementationName method of css.lang.XServiceInfo interface. |
Hanya,
everywhere it is set as "org.creativecommons.openoffice.ccooo:InsertPictureFlickr" . I checked it.  |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Sat May 19, 2012 8:42 am Post subject: |
|
|
| Quote: | | everywhere it is set as "org.creativecommons.openoffice.ccooo:InsertPictureFlickr" . I checked it. | In the project_1.oxt?
You have to like as follows:
| Code: | <?xml version='1.0' encoding='UTF-8'?>
<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node oor:name="HandlerSet">
<node oor:name="org.creativecommons.openoffice.CcOOoAddin" oor:op="replace">
<prop oor:name="Protocols" oor:type="oor:string-list">
<value>org.creativecommons.openoffice.ccooo:*</value>
</prop>
</node>
</node>
</oor:component-data>
|
| Code: | import unohelper
from com.sun.star.frame import XDispatch, XDispatchProvider
from com.sun.star.lang import XInitialization, XServiceInfo
SERVICE_NAME = "com.sun.star.frame.ProtocolHandler"
IMPLE_NAME = "org.creativecommons.openoffice.CcOOoAddin"
class Example(unohelper.Base, XInitialization, XServiceInfo, XDispatchProvider, XDispatch):
def __init__(self, ctx, *args):
self.ctx = ctx
self.frame = None
self.initialize(args)
def supportsService(self,name):
return (name == SERVICE_NAME)
def getImplementationName(self):
return IMPLE_NAME
def getSupportedServiceNames(self):
return (SERVICE_NAME,)
# XInitialization
def initialize(self, args):
if args:
self.frame = args[0]
# XDispatchProvider
def queryDispatch(self, url, name, flags):
print 'ss'
if url.Protocol == "org.creativecommons.openoffice.ccooo:":
return self
return None
def queryDispatches(self, req):
pass
# XDispatch
def dispatch(self, url, args):
if url.Complete == "foo:do":
self.do()
def addStatusListener(self, control, url):
pass
def removeStatusListener(self, control, url):
pass
def do(self):
pass
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
Example,
"org.creativecommons.openoffice.CcOOoAddin",
("com.sun.star.frame.ProtocolHandler",),)
|
|
|
| Back to top |
|
 |
ishanthilina General User

Joined: 17 Mar 2012 Posts: 46
|
Posted: Sat May 19, 2012 9:43 am Post subject: |
|
|
Thanks a lot Hanya. That worked like a charm. Don't know how to thank you. Really sorry for the trouble I caused you throughout the day . Thank you very much!. |
|
| Back to top |
|
 |
|