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