Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index

Am 29.05.2012 23:36, leeand00 wrote:

I suppose the confusing bit would be where the UNO components come in, how
are these handled in Python?

class Office:
    '''Frequently used methods in office context'''
    def __init__(self, ctx=uno.getComponentContext()):
        self.ctx = ctx
        self.smgr = self.ctx.ServiceManager

    def createUnoService(self, service):
        return self.smgr.createInstance(service)

    def getDesktop(self):
return self.smgr.createInstanceWithContext("",self.ctx)

    def getCurrentComponent(self):
        return self.getDesktop().getCurrentComponent()

    def getCurrentFrame(self):
        return self.getDesktop().getCurrentFrame()

    def getCurrentComponentWindow(self):
        return self.getCurrentFrame().getComponentWindow()

    def getCurrentContainerWindow(self):
        return self.getCurrentFrame().getContainerWindow()

    def getCurrentController(self):
        return self.getCurrentFrame().getController()

    def callMRI(self,obj=None):
'''Create an instance of MRI inspector and inspect the given object (default is selection)'''
        if not obj:
            obj = self.getCurrentController().getSelection()
        mri = self.createUnoService("mytools.Mri")

def testMessageAndMRI(*args):
'''A macro to be called from the office GUI'''
    o = Office(XSCRIPTCONTEXT.getComponentContext())

# this is the list of callable macros:
g_exportedScripts = testMessageAndMRI,

The rest is a piece of cake if you know how to write Python code.

For unsubscribe instructions e-mail to:
Posting guidelines + more:
List archive:
All messages sent to this list will be publicly archived and cannot be deleted


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.