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("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+help@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

Context


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.