2

When developing macros in python for LibreOffice / OpenOffice on Linux at least, I've read that you have to place your py scripts in a particular directory.

Is there a preferred method among Python LibreOffice/OOo developers for deploying these scripts, or is there another way to specify within LibreOffice/OOo to specify where you want these scripts to be?

leeand00
  • 25,510
  • 39
  • 140
  • 297

2 Answers2

1

Maybe a nice way to go is to get familiarized with Python setup tools itself (http://packages.python.org/an_example_pypi_project/setuptools.html), and write a proper setup.py script which would place all needed files in the appropriate dirs.

Your macros could them even be installable with the "easy_install" Python framework

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Is setup.py similar to make or ant or maven or rake any other number of build tools? – leeand00 May 24 '12 at 19:08
  • Here's an answer to the question of what setup.py is: http://stackoverflow.com/questions/1471994/what-is-setup-py – leeand00 May 25 '12 at 14:21
-1

To avoid the need to reload a changed macro (even when it is deployed to the correct folder), you can have LibreOffice listen on a socket during development:

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()

I explain how to replace this development prop when you are ready to deploy in this article

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127
  • 1
    A link to a potential solution is always welcome, but please [add context around the link](http://meta.stackoverflow.com/a/8259/169503) so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being _barely more than a link to an external site_ is a possible reason as to [Why and how are some answers deleted?](http://stackoverflow.com/help/deleted-answers). – Petter Friberg Feb 08 '17 at 09:54