在宏开发期间将python脚本“部署”到LibreOffice的首选方法?

时间:2012-05-24 17:10:35

标签: python openoffice.org libreoffice

至少在Linux上为LibreOffice / OpenOffice在python中开发宏时,我已经读过你必须将py脚本放在特定的目录中。

Python LibreOffice / OOo开发人员是否有一个首选方法来部署这些脚本,或者是否有其他方法可以在LibreOffice / OOo中指定您希望这些脚本的位置?

2 个答案:

答案 0 :(得分:1)

也许一个好的方法是熟悉Python设置工具本身(http://packages.python.org/an_example_pypi_project/setuptools.html),并编写一个适当的setup.py脚本,它将放置所有需要的文件在合适的目录中。

您的宏甚至可以使用“easy_install”Python框架

进行安装

答案 1 :(得分:-1)

为了避免重新加载已更改的宏(即使将其部署到正确的文件夹),您可以让LibreOffice在开发期间侦听套接字:

import uno

def getModel():
    # get the uno component context from the PyUNO runtime
    localContext = uno.getComponentContext()

    # create the UnoUrlResolver
    resolver = localContext.ServiceManager.createInstanceWithContext(
    "com.sun.star.bridge.UnoUrlResolver", localContext)

    # connect to the running office
    context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
    manager = context.ServiceManager

    # get the central desktop object
    desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

    # access the current writer document
    return desktop.getCurrentComponent()

当您准备好在this article

中部署时,我将解释如何替换此开发支柱