标签:
IDL 类型
|
Python |
integer types (byte, short, unsigned short, long, unsigned long, hyper, unsigned hyper
|
Python内部只知道C数据类型long和longlong作为整数类型。在大多数机器上,一个long是一个32位值而longlong是一个64位的值.
|
boolean
|
Python 内部有boolean 数据类型,继承integer type 存在单件真假,pyuno使用区分整数和布尔值. 如果一个UNO方法的参数为boolean,你也可以使用数值传递 例如: #idl signature void takeBool( [in] boolean bool )
unoObject.takeBool( 1 ) # valid, passing true (PyUNO runtime
# does the conversion
unoObject.takeBool( True) ) # valid, passing true
unoObject.takeBool( False ) # valid, passing false
然而当你想明确的指定传递boolean,并用any类型作为参数,你必须使用True 或 False
# idl signature void foo( [in] any value ) # implementation expects a boolean (which is separately documented # e.g. in the service specification. unoObject.foo( True ) # valid, pass a true unoObject.foo( 1 ) # bad, just passing a 1, implementation will |
string
|
通常情况下,string映射python unicode string,但是当传递8位的python string , UNO 桥会将8位的string转换为unicode string.# idl signature foo( [in] string value ) # both lines are valid unoObject.foo( u‘my foo string‘ ) unoObject.foo( ‘my foo string‘ ) |
enum
|
例:
from com.sun.star.uno.TypeClass import UNSIGNED_LONG
unoObject.setValue(UNSIGNED_LONG)
if unoObject.getValue() == UNSIGNED_LONG;
unoObject 映射为枚举类型
|
type
|
例:
from com.sun.star.lang import typeOfXComponent
unoObject.setType( typeOfXComponent )
if unoObject.getType() == typeOfXComponent:
|
struct(and exception)
|
例:
第一种实现方式:使用结构体的构造函数,拷贝构造函数,以及结构体支持等于号操作。
from com.sun.star.beans import PropertyValue
from com.sun.star.uno import Exception,RuntimeException
propVal = PropertyValue() # Default constructor
propVal.Name = "foo"
propVal.Value = 2
if propVal == PropertyValue( "foo", 2 ): # Memberwise constructor
# true !
pass
if propVal == PropertyValue( propVal ): # Copy Constructor
# true
第二种实现方式: uno.createUnoStruct()struct = uno.createUnoStruct( "com.sun.star.beans.PropertyValue" )
struct.Name = "foo"
struct2 = struct
struct2.Name = "python" # modifies also struct, probably not desired !
unoObject.call( struct, struct2 ) # passes the same struct 2 times !
struct.Name = "doobidooo" # even worse style. If the UNO object is implemented
# in python, you possibly modify the callee‘s value.
# Don‘t do this !
|
secquence
|
secquence映射到python为tuple。
secquence<byte>映射为uno.ByteSecquence. 包含字符串类型的成员变量value, value存放字节流。
# idl signature writeBytes( [in] sequence%lt; byte > data ) # out.writeBytes( uno.ByteSequence( "abc" ) ) # you could also write the following begin = uno.ByteSequence( "ab" ) out.writeBytes( begin + "c" ) # but this does not work ! out.writeBytes( "abc" ) # ERROR, no implicit conversion supported by the runtime ! # idl signature long readBytes( [out] sequence<byte> , [in] length ) len,seq = in.readBytes( dummy, 3 ) # the statements do the same thing print seq == "abc": print seq == uno.ByteSequence( "abc" ) |
any | 通常情况下,写python脚本时不需要接触到any类型,只需要根据UNO接口方法所需要的any类型,传入具体的数据类型就OK。 但是有些特殊情况,需要传入指定的any值 例如: # the normal call uno.setPropertyValue( "foo", (4,5)) # the uno.invoke call uno.invoke( obj, "setPropertyValue" , ("foo",uno.Any( "[]short", (4,5))) )我们可以使用uno.Any(),传递类型名称和值来构造Any # constructs a uno.Any, that contains a byte byteAny = uno.Any( "byte" , 5 ) # constructs a sequences of shorts byteAny = uno.Any( "[]short", (4,5)) |
标签:
原文地址:http://www.cnblogs.com/linTracy/p/5367225.html