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


On 04/24/2012 10:40 PM, Jordi Llonch wrote:
I am trying to add a new path into AutoText Paths configuration using PyUNO.

By executing the following code, AutoText UserPaths shows the added path
but changes
are not set to LibreOffice configuration.

What I am doing wrong?

Trying this with latest LO master (on Fedora 16, not Mac OS X, but that should hardly make a difference here I'd assume), it does work fine for me (and correctly saves the new UserPaths value in registrymodifications.xcu). However, I had to make two changes to the Python script (attached):

* desktop and config need to be obtained via the remote service manager, not the local one. (The behaviour of S.createInstanceWithContext(D, C) apparently changed with my recent rewrite of the default service manager. Now, D is always instantiated relative to S, regardless of the given C -- the latter is only passed on to the instantiated service. In the past, it appears that D was instantiated relative to C's service manager instead of the given S -- which looks kinda broken, given you explicitly ask S to create an instance.) Surely a gotcha to watch out for...

* If the AutoText UserPaths property does not yet have a value, reading its value returns None instead of () (as the property is implicitly nillable). That makes "autotext_path.UserPaths + (path,)" fail.

Stephan
import uno
from com.sun.star.beans import PropertyValue

unourl = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"

def make_properties(dc):
    p = []
    for k,v in dc.iteritems():
        x = PropertyValue()
        x.Name = k
        x.Value = v
        p.append(x)
    return tuple(p)

def main():

    context = uno.getComponentContext()

    resolver = context.ServiceManager.createInstanceWithContext(
        "com.sun.star.bridge.UnoUrlResolver", context)

    ctx = resolver.resolve(unourl)
    smgr = ctx.ServiceManager
    desktop = smgr.createInstanceWithContext(
        "com.sun.star.frame.Desktop", ctx)

    args = make_properties({"nodepath":"/org.openoffice.Office.Paths/Paths"})

    config = smgr.createInstance(
        "com.sun.star.configuration.ConfigurationProvider")
    update_access = config.createInstanceWithArguments(
        "com.sun.star.configuration.ConfigurationUpdateAccess", args)

    path = "$(home)/autotext"

    autotext_path = update_access.getByName("AutoText")
    user_paths = autotext_path.UserPaths
    if user_paths == None:
        user_paths = ()
    autotext_path.UserPaths = user_paths + (path,)
    update_access.commitChanges()

    # TEST results
    access = config.createInstanceWithArguments(
        "com.sun.star.configuration.ConfigurationAccess", args)
    print access.getByName("AutoText").UserPaths

if __name__ == '__main__':
    main()

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.