Search code examples
pythonlibreoffice-calc

There is an error adding a custom LibreOffice extension


Good afternoon.

I wrote an extension for LibreOffice. Here is its structure:

enter image description here

The contents of the file datalink.py:

import uno
import unohelper
from com.sun.star.task import XJobExecutor
from pythonpath.services.messageboxservice import MessageBoxService

class DataLink(unohelper.Base, XJobExecutor):
   implementationName = "vnd.datalink"                                     
   serviceNames = ("com.sun.star.task.Job",)                               

   def __init__(self, context):
      self.context = context

   def trigger(self, args):                                               
      MessageBoxService("Hello World!!! Args: " + args, "Info")

g_ImplementationHelper = unohelper.ImplementationHelper()

g_ImplementationHelper.addImplementation(DataLink, DataLink.implementationName, DataLink.serviceNames,)

The contents of the file messageboxservice.py:

import uno

from com.sun.star.awt.MessageBoxType import INFOBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK

class MessageBoxService:

   @staticmethod
   def Show(text, caption, type = INFOBOX):
      context = uno.getComponentContext()
      sManager = context.ServiceManager
      toolkit = sManager.createInstance("com.sun.star.awt.Toolkit")
      msgbox = toolkit.createMessageBox(None, type, BUTTONS_OK, caption, text)
      return msgbox.execute()

The contents of the file manifest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
     <manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
     <manifest:file-entry manifest:full-path="datalink.py" manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
</manifest:manifest>

When you add a DataLink.oxt extension file to LibreOffice, the following error occurs: enter image description here

Question: How did I correct this error?

P.S. may need to make any changes to the above files


Solution

  • Everything inside the pythonpath directory is included in the path, not the directory itself. So, the import statement should be:

    from services.messageboxservice import MessageBoxService
    

    For reference, see https://wiki.openoffice.org/wiki/Python/Transfer_from_Basic_to_Python#Importing_Modules, although it doesn't give a clear example that answers your question.