Hi,
lets for a moment assume, that that userAttrs would be a container for propertyvalue arrays and one wants to insert an array named "ElementName", then the following code would be nicest:
myAttr = uno.createUnoStruct("com.sun.star.beans.PropertyValue") myAttr.Name = "URL"
myAttr.Value = "myURL"
I find it strange, that you want to use a PropertyValue struct as your attribute value. Wouldn't simply using myAttr = "myURL" be better? Why do you need the redundant name "URL"?
(Unless UserDefinedAttributes is specified to be a container of named PropertyValues - which I'd consider a design flaw).
uno.invoke( userAttrs , "insertByName", (myAttr.Name, uno.Any( \ "[]com.sun.star.beans.PropertyValue", myAttr)) )
Not knowing much about PyUno, is "[]com.sun.star.beans.PropertyValue" really correct for a single property value struct? Looks like that would require an array to me.
from com.sun.star.beans import PropertyValue
try:
userAttrs = cell.UserDefinedAttributes
# comma at the end indicates a sequence
myAttrSeq = PropertyValue( "URL", "myURL" ),
userAttrs.insertByName( "ElementName", myAttrSeq)The pyuno bridge converts myAttrSeq to a sequence of any, however a lot of implementations in OOo can't deal with this (these implementations in general use the C++ Any >>= operator instead of the type converter), so the caller somehow needs to pass the explicit type of the argument. That's what the uno.invoke() function is for, in the above sample, it would be called the following way:
uno.invoke( userAttrs, "insertByName",
( "ElementName",
uno.Any( "[]com.sun.star.beans.PropertyValue",
myAttrSeq ) ) )uno.invoke ensures, that when userAttrs is a bridged object, the correct type gets passed, but when userAttrs is a local python object, the Any () part gets stripped away, so that a python uno object implementation never has to deal with uno.Any() ( this is a lesson learned from the unfortunate Any in java ). In fact, uno.Any in python can only be used with uno.invoke.
Bye,
Joerg
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
