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("com.sun.star.frame.Desktop",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")
        mri.inspect(obj)


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

# 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: users+h...@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Reply via email to