• Matthew J. Francis's avatar
    Make PyUNO provide more Pythonic behaviour · af8143bc
    Matthew J. Francis yazdı
    - Simplifies working with UNO objects by giving the behaviour of
    Python lists, dicts and iterators to objects which implement UNO
    container interfaces
    
    - Applies a custom behaviour to allow objects which implement
    com::sun::star::table::XCellRange to yield cells and cell ranges by
    subscript
    
    - When UNO container objects are addressed in the new style,
    eliminates the requirement to manually construct Any objects for
    contained elements which are typed sequences
    
    - Allows lists and iterators to be passed wherever a UNO method
    accepts a sequence
    
    - Relaxes the requirements for initialising UNO structs to allow
    some members to be skipped when all initialisers are passed by name
    
    1. Collection interfaces
    ========================
    
    Objects which implement core UNO collection interfaces are made to
    behave in a way that is more natural for Python code.
    
    com::sun::star::container::XIndexAccess
    com::sun::star::container::XIndexReplace
    com::sun::star::container::XIndexContainer
    - Objects provide Python list access semantics
        num = len(obj)              # Number of elements
        val = obj[0]                # Access by index
        val1,val2 = obj[2:4]        # Access by slice
        val1,val2 = obj[0:3:2]      # Access by extended slice
        if val in obj: ...          # Test value presence
        for val in obj: ...         # Implicit iterator (values)
        itr = iter(obj)             # Named iterator (values)
        obj[0] = val                # Replace by index
        obj[2:4] = val1,val2        # Replace by slice
        obj[0:3:2] = val1,val2      # Replace by extended slice
        obj[2:3] = val1,val2        # Insert/replace by slice
        obj[2:2] = (val,)           # Insert by slice
        obj[2:4] = (val,)           # Replace/delete by slice
        obj[2:3] = ()               # Delete by slice (implicit)
        del obj[0]                  # Delete by index
        del obj[2:4]                # Delete by slice
    
    com::sun::star::container::XNameAccess
    com::sun::star::container::XNameReplace
    com::sun::star::container::XNameContainer
    - Objects provide Python dict access semantics
        num = len(obj)              # Number of keys
        val = obj[key]              # Access by key
        if key in obj: ...          # Test key presence
        for key in obj: ...         # Implicit iterator (keys)
        itr = iter(obj)             # Named iterator (keys)
        obj[key] = val              # Replace by key
        obj[key] = val              # Insert by key
        del obj[key]                # Delete by key
    
    com::sun::star::container::XEnumerationAccess
    - Objects provide Python iterable semantics
        for val in obj: ...         # Implicit iterator
        itr = iter(obj)             # Named iterator
    
    com::sun::star::container::XEnumeration
    - Objects provide Python iterator semantics
        for val in itr: ...         # Iteration of named iterator
        if val in itr: ...          # Test value presence
    
    Objects which implement both XIndex* and XName* are supported, and
    respond to both integer and string keys. However, iterating over
    such an object will return the keys (like a Python dict) rather than
    the values (like a Python list).
    
    2. Cell ranges
    ==============
    
    A custom behaviour is applied to objects which implement
    com::sun::star::table::XCellRange to allow their cells and cell
    ranges to be addressed by subscript, in the style of a Python list
    or dict (read-only). This is applicable to Calc spreadsheet sheets,
    Writer text tables and cell ranges created upon these.
        cell = cellrange[0,0]       # Access cell by indices
        rng = cellrange[0,1:2]      # Access cell range by index,slice
        rng = cellrange[1:2,0]      # Access cell range by slice,index
        rng = cellrange[0:1,2:3]    # Access cell range by slices
        rng = cellrange['A1:B2']    # Access cell range by descriptor
        rng = cellrange['Name']     # Access cell range by name
    
    Note that the indices used are in Python/C order, and differ from
    the arguments to methods provided by XCellRange.
    - The statement cellrange[r,c], which returns the cell from row r
    and column c, is equivalent to calling
        XCellRange::getCellByPosition(c,r)
    - The statement cellrange[t:b,l:r], which returns a cell range
    covering rows t to b(non-inclusive) and columns l to r(non-
    inclusive), is equivalent to calling
        XCellRange::getCellRangeByPosition(l,t,r-1,b-1).
    
    In contrast to the handling of objects implementing XIndex*,
    extended slice syntax is not supported. Negative indices (from-end
    addresses) are supported only for objects which also implement
    com::sun::star::table::XColumnRowRange (currently Calc spreadsheet
    sheets and cell ranges created upon these). For such objects, the
    following syntax is also available:
        rng = cellrange[0]          # Access cell range by row index
        rng = cellrange[0,:]        # Access cell range by row index
        rng = cellrange[:,0]        # Access cell range by column index
    
    3. Elimination of explicit Any
    ==============================
    
    PyUNO has not previously been able to cope with certain method
    arguments which are typed as Any but require a sequence of specific
    type to be passed. This is a particular issue for container
    interfaces such as XIndexContainer and XNameContainer.
    
    The existing solution to dealing with such methods is to use a
    special method to pass an explicitly typed Any, giving code such as:
    
        index = doc.createInstance("com.sun.star.text.ContentIndex");
        ...
        uno.invoke( index.LevelParagraphStyles , "replaceByIndex",
                    (0, uno.Any("[]string", ('Caption',))) )
    
    The new Pythonic container access is able to correctly infer the
    expected type of the sequences required by these arguments. In the
    new style, the above call to .replaceByIndex() can instead be
    written:
    
        index.LevelParagraphStyles[0] = ('Caption',)
    
    4. List and iterator arguments
    ==============================
    
    Wherever a UNO API expects a sequence, a Python list or iterator can
    now be passed. This enables the use of list comprehensions and
    generator expressions for method calls and property assignments.
    
    Example:
    
        tbl = doc.createInstance('com.sun.star.text.TextTable')
        tbl.initialize(10,10)
        # ... insert table ...
        # Assign numbers 0..99 to the cells using a generator expression
        tbl.Data = ((y for y in range(10*x,10*x + 10)) for x in range(10))
    
    5. Tolerant struct initialisation
    =================================
    
    Previously, a UNO struct could be created fully uninitialised, or by
    passing a combination of positional and/or named arguments to its
    constructor. However, if any arguments were passed, all members were
    required to be initialised or an exception was thrown.
    This requirement is relaxed such that when all arguments passed to a
    struct constructor are by name, some may be omitted. The existing
    requirement that all members must be explicitly initialised when
    some constructor arguments are unnamed (positional) is not affected.
    
    Example:
    
        from com.sun.star.beans import PropertyValue
        prop = PropertyValue(Name='foo', Value='bar')
    
    Change-Id: Id29bff10a18099b1a00af1abee1a6c1bc58b3978
    Reviewed-on: https://gerrit.libreoffice.org/16272Tested-by: 's avatarJenkins <ci@libreoffice.org>
    Reviewed-by: 's avatarMatthew Francis <mjay.francis@gmail.com>
    af8143bc
Adı
Son kayıt (commit)
Son güncelleme
.git-hooks Loading commit data...
UnoControls Loading commit data...
accessibility Loading commit data...
android Loading commit data...
animations Loading commit data...
apple_remote Loading commit data...
avmedia Loading commit data...
basctl Loading commit data...
basebmp Loading commit data...
basegfx Loading commit data...
basic Loading commit data...
bean Loading commit data...
bin Loading commit data...
binaryurp Loading commit data...
bridges Loading commit data...
canvas Loading commit data...
chart2 Loading commit data...
clew Loading commit data...
cli_ure Loading commit data...
codemaker Loading commit data...
comphelper Loading commit data...
compilerplugins Loading commit data...
config_host Loading commit data...
configmgr Loading commit data...
connectivity Loading commit data...
cppcanvas Loading commit data...
cppu Loading commit data...
cppuhelper Loading commit data...
cpputools Loading commit data...
cui Loading commit data...
dbaccess Loading commit data...
desktop Loading commit data...
dictionaries @ ab55a4aa
distro-configs Loading commit data...
drawinglayer Loading commit data...
dtrans Loading commit data...
editeng Loading commit data...
embeddedobj Loading commit data...
embedserv Loading commit data...
eventattacher Loading commit data...
extensions Loading commit data...
external Loading commit data...
extras Loading commit data...
filter Loading commit data...
forms Loading commit data...
formula Loading commit data...
fpicker Loading commit data...
framework Loading commit data...
helpcompiler Loading commit data...
helpcontent2 @ aac176ce
hwpfilter Loading commit data...
i18nlangtag Loading commit data...
i18npool Loading commit data...
i18nutil Loading commit data...
icon-themes Loading commit data...
idl Loading commit data...
idlc Loading commit data...
include Loading commit data...
instsetoo_native Loading commit data...
io Loading commit data...
ios Loading commit data...
javaunohelper Loading commit data...
jurt Loading commit data...
jvmaccess Loading commit data...
jvmfwk Loading commit data...
l10ntools Loading commit data...
librelogo Loading commit data...
libreofficekit Loading commit data...
lingucomponent Loading commit data...
linguistic Loading commit data...
lotuswordpro Loading commit data...
m4 Loading commit data...
mysqlc Loading commit data...
nlpsolver Loading commit data...
o3tl Loading commit data...
odk Loading commit data...
offapi Loading commit data...
officecfg Loading commit data...
oovbaapi Loading commit data...
oox Loading commit data...
opencl Loading commit data...
osx Loading commit data...
package Loading commit data...
postprocess Loading commit data...
pyuno Loading commit data...
qadevOOo Loading commit data...
readlicense_oo Loading commit data...
registry Loading commit data...
remotebridges Loading commit data...
reportbuilder Loading commit data...
reportdesign Loading commit data...
ridljar Loading commit data...
rsc Loading commit data...
sal Loading commit data...
salhelper Loading commit data...
sax Loading commit data...
sc Loading commit data...
scaddins Loading commit data...
sccomp Loading commit data...
scp2 Loading commit data...
scripting Loading commit data...
sd Loading commit data...
sdext Loading commit data...
setup_native Loading commit data...
sfx2 Loading commit data...
shell Loading commit data...
slideshow Loading commit data...
smoketest Loading commit data...
solenv Loading commit data...
soltools Loading commit data...
sot Loading commit data...
starmath Loading commit data...
stoc Loading commit data...
store Loading commit data...
svgio Loading commit data...
svl Loading commit data...
svtools Loading commit data...
svx Loading commit data...
sw Loading commit data...
swext Loading commit data...
sysui Loading commit data...
test Loading commit data...
testtools Loading commit data...
toolkit Loading commit data...
tools Loading commit data...
translations @ f7efc4ec
tubes Loading commit data...
ucb Loading commit data...
ucbhelper Loading commit data...
udkapi Loading commit data...
unodevtools Loading commit data...
unoidl Loading commit data...
unoil Loading commit data...
unotest Loading commit data...
unotools Loading commit data...
unoxml Loading commit data...
ure Loading commit data...
uui Loading commit data...
vbahelper Loading commit data...
vcl Loading commit data...
winaccessibility Loading commit data...
wizards Loading commit data...
writerfilter Loading commit data...
writerperfect Loading commit data...
xmerge Loading commit data...
xmlhelp Loading commit data...
xmloff Loading commit data...
xmlreader Loading commit data...
xmlscript Loading commit data...
xmlsecurity Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.gitreview Loading commit data...
COPYING Loading commit data...
COPYING.LGPL Loading commit data...
COPYING.MPL Loading commit data...
Library_merged.mk Loading commit data...
Makefile.fetch Loading commit data...
Makefile.gbuild Loading commit data...
Makefile.in Loading commit data...
README.Solaris Loading commit data...
README.cross Loading commit data...
README.md Loading commit data...
Repository.mk Loading commit data...
RepositoryExternal.mk Loading commit data...
RepositoryFixes.mk Loading commit data...
RepositoryModule_build.mk Loading commit data...
RepositoryModule_host.mk Loading commit data...
TEMPLATE.SOURCECODE.HEADER Loading commit data...
autogen.sh Loading commit data...
config.guess Loading commit data...
config.sub Loading commit data...
config_host.mk.in Loading commit data...
config_host_lang.mk.in Loading commit data...
configure.ac Loading commit data...
download.lst Loading commit data...
g Loading commit data...
install-sh Loading commit data...
leak-suppress.txt Loading commit data...
lo.xcent.in Loading commit data...
logerrit Loading commit data...
unusedcode.README Loading commit data...
unusedcode.easy Loading commit data...
unusedcode.exclude Loading commit data...