Commit Graph

399 Commits

Author SHA1 Message Date
34180700b2 loplugin:removeunusedmethods, remove unused stuff
Change-Id: I35456b2a3ad2a84a1d045f09cdfb29e4c19b8350
2015-09-29 15:08:43 +02:00
ee7da352b8 Resolves: tdf#88206 replace cppu::WeakImplHelper* etc.
with the variadic variants.

Change-Id: I7154f9472f02fdf47d27ba715db55bb1ec669a8a
Reviewed-on: https://gerrit.libreoffice.org/18580
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
2015-09-15 06:19:28 +00:00
f5eeaaac7c loplugin:stringconstant: OUStringBuffer: appendAscii -> append
Change-Id: I98058ff0653a3aab3399735271d04b16a05a3684
2015-08-31 08:02:45 +02:00
7e318570dc tdf#39440 reduce scope of local variables
This addresses some cppcheck warnings.

Change-Id: Ie492fb9c106b37c3fe7b0105236ad6315f4f159e
Reviewed-on: https://gerrit.libreoffice.org/17921
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
2015-08-22 13:04:12 +00:00
2387c2a46e Give PyUNO structs/exceptions their own separate type
Change-Id: Ie4c42c623fae1cf39c2e4c643825c9655cd28daa
Reviewed-on: https://gerrit.libreoffice.org/17410
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
2015-07-30 05:55:32 +00:00
9c5a217681 Tweak introspection/invocation to be more useful to PyUNO
- Make introspection/invocation handle XNameReplace and
  XIndexReplace
- Make introspection handle XUnoTunnel
- Adapt PyUNO to take advantage of the additionally handled
  interfaces

Change-Id: Ie848d10fd2c31cad76fcc3a746262a490a2c9ae1
Reviewed-on: https://gerrit.libreoffice.org/17314
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
Tested-by: Matthew Francis <mjay.francis@gmail.com>
2015-07-27 07:40:34 +00:00
3458a25202 Fix PyUNO object hash to use the correct pointer
Change-Id: Id93cba88eaf0dca0784051507809bc849d046a03
Reviewed-on: https://gerrit.libreoffice.org/17337
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
2015-07-25 02:17:28 +00:00
a781abe326 Make PyUNO objects hashable
This allows them to be used as set members and dict keys

Change-Id: I10bd71788be6b508c6f491a27a8841e599e47e3a
Reviewed-on: https://gerrit.libreoffice.org/17248
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
Tested-by: Matthew Francis <mjay.francis@gmail.com>
2015-07-21 06:56:42 +00:00
7799d0749a coverity#1309066 Uncaught exception
Change-Id: If02a62e814051bb2d75a683877f8d17ec9201993
2015-07-02 11:39:32 +01:00
33776d143f PyUNO: Allow import of constant group by name
Change-Id: I0ea809a888187624261182552cf7fa0a9c96c648
2015-07-01 13:14:25 +08:00
3a6ec53eee Fix compilation with Python 2.7
Change-Id: I0dd118f0215e06fec0cccff9b46d80f13bd802cc
Reviewed-on: https://gerrit.libreoffice.org/16620
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
Tested-by: Matthew Francis <mjay.francis@gmail.com>
2015-07-01 04:18:48 +00:00
a1a7aa93a3 coverity#1308526 Uncaught exception
Change-Id: Ie0266c7e8ab5980dc25ce14edd42b3f599f71245
2015-06-28 17:55:54 +01:00
ce75e5b931 loplugin:implicitboolconversion
Change-Id: If495a415d4263d1932c03a31d07a517218533847
2015-06-26 14:10:03 +02:00
8811c41abc loplugin:cstylecast
Change-Id: I5f0bceb240a492c7c010b4356bc8efafdd83bf24
2015-06-26 14:07:54 +02:00
2a807ca137 loplugin:passstuffbyref
Change-Id: I66410932347b4f65c4b24b5316009ecffc8aef06
2015-06-26 14:06:45 +02:00
c44021f754 loplugin:salbool
Change-Id: I4875b12807aed36f758d81c731e2ac52a3a606e4
2015-06-26 14:05:44 +02:00
e29a7ff187 loplugin:salbool
Change-Id: I9975a87f6df2b7a79c376130864e9eb54bc3452b
2015-06-26 14:04:43 +02:00
7f9a65862b loplugin:loopvartoosmall
Change-Id: I19d801444e4d1db5576b5742c60fc138384d3b70
2015-06-26 14:03:46 +02:00
63e81af351 loplugin:stringconstant: handle OUString+=OUString(literal)
Change-Id: Id2efd6f38390bb73620cf40121430c4226024103
2015-06-26 13:55:33 +02:00
af8143bc40 Make PyUNO provide more Pythonic behaviour
- 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::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::container::XIndexAccess
com::sun::container::XIndexReplace
com::sun::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::container::XNameAccess
com::sun::container::XNameReplace
com::sun::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::container::XEnumerationAccess
- Objects provide Python iterable semantics
    for val in obj: ...         # Implicit iterator
    itr = iter(obj)             # Named iterator

com::sun::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::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::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/16272
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Matthew Francis <mjay.francis@gmail.com>
2015-06-26 09:41:11 +00:00
ad84b40b08 Typo: pyhton->python
Change-Id: I16d99991b8b88753c593a5a1ab9e32a8e0264514
2015-06-14 01:15:14 +02:00
3754474cde Typos
Change-Id: I21c352a63d668c174eef212dbfbe6346c678ce4d
2015-06-13 09:13:52 +02:00
22009c987b Typo: Adapater->Adapter
Change-Id: I696c0693dc7a69dc3a4b8df0c4e8571414d5b9a6
2015-06-12 23:57:33 +02:00
1ee5e1a17c pyuno: remove obsolete LC_NUMERIC to "C" mangling code
The CPython changelog says for version 2.4:

- Python no longer relies on the LC_NUMERIC locale setting to be
  the "C" locale; as a result, it no longer tries to prevent changing
  the LC_NUMERIC category.

Change-Id: I6d63c4dedca48c99bf81135d69285d9116a19740
2015-06-10 14:38:27 +02:00
5782f69c0c loplugin:cstylecast: deal with remaining pointer casts
Change-Id: Iffa346c16a6775b206c8f8613eee9e7201e3badb
2015-06-08 16:27:02 +02:00
6ef9f7e202 loplugin:loopvartoosmall
Change-Id: Ib4def3435eab4625645c5afe3b151f9f430564ac
2015-06-02 12:09:56 +02:00
10fe9ed22b loplugin:cstylecast: nop between pointer types of exactly same spelling
Change-Id: I0968c4b37b97bb89ebc8b873c78a96431245f480
2015-05-11 12:50:14 +02:00
9222f5d065 A UNO Any can't contain an Any
...and css::uno::makeAny<css::uno::Any>() was never meant to be used.  Introduce
css::uno::toAny for the (template-code) cases that shall return an Any for both
Any and non-Any inputs.

Change-Id: Ifa977d73f1da71b2fedde7e8140b19497c4a0257
2015-04-08 17:45:08 +02:00
714f4db8d3 Replace remaining getCppuType et al with cppu::UnoType
Change-Id: Id848d14133fee5104e79ba0683cbaf942598faa7
2015-04-01 08:40:15 +02:00
0bd502af47 Clean up remaining C-style casts among void pointers
Change-Id: I1b49c020d597b569e330482f4dbf20c15ccdae3f
2015-03-29 09:17:47 +02:00
8375ac0186 Clean up C-style casts from pointers to void
Change-Id: I3676d56e65dd2d5b36882073c63e571a79819fee
2015-03-28 19:09:23 +01:00
9bd2b842a5 const_cast: convert some C-style casts and remove some redundant ones
Change-Id: I71ebd11d850304772535cfb873086176d301172a
2015-03-26 15:33:33 +01:00
a251fe4d48 We require MSVC2013 (_MSC_VER == 1800) now
Change-Id: Ice8504041f22e00f2e5010813d9dff1d2987c8d6
2015-03-19 10:57:17 +02:00
e557b160fd pyuno, scripting: remove executable bits from python, js, bsh files
Change-Id: Id108693d84fbca7764614e126ee1b3b045baec17
2015-03-02 13:26:28 +01:00
7b83298667 Some more loplugin:cstylecast: pyuno
Change-Id: I80c9fdb45c9f58ac3cd1b0fab2631b903194e268
2015-01-20 09:06:50 +01:00
5484475fc1 include algorithm
Change-Id: I55abf17a1da2616ca2b1303747ca8cc7e402634e
2015-01-02 17:03:55 +00:00
fd1372ba8b boost::unordered_map->std::unordered_map
you can get debug stl this way

Change-Id: Ia70a3e7c7c452390e8bee34975d296c9318e4a19
2015-01-02 16:14:36 +00:00
3dfcc045dd pyuno: Use appropriate OUString functions on string constants
Change-Id: Ib507da6fc85d8bc81fd48108a98ef96d188643ac
2014-12-12 12:21:47 +01:00
8eb37e74ff pyuno: move "officehelper.py" from scripting to pyuno
... because at least in Fedora packages with system python it's a pain
to use officehelper.bootstrap() because unlike pyuno it is not installed
in the standard python directories but in libreoffice/program.

You might think that bootstrap() is not appropriate functionality for a
UNO langauge binding, but then why does ::cppu::bootstrap() exist?

Change-Id: I5fd4b344a811c087d32fb6304e55105ab3cb137e
Reviewed-on: https://gerrit.libreoffice.org/12968
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
2014-12-02 13:47:26 +00:00
2ad716f406 Revert "pyuno: set up fake command line in getComponentContext()"
This reverts commit 2386a92c1e6e8ec263edb4dc4fdcfeaa4673ce1f and its follow-ups
1acaa577b67158c060d2f57414f7aea86504a489 "sal: add special handling of argc==0
to osl_setCommandArgs()" and 01f27b5e5d428cc3c4aeabdcbbb8204494fbd435 "sal: fix
osl_setCommandArgs() on WNT."

The situation that osl_getCommandArgCount is called without a prior call to
osl_setCommandArgs should be considered as harmless and can legitimately not
only happen in the pyuno case discussed in the reverted commits, but also in
case binary UNO is bootstrapped from within a Java process, as happens in
test-javanative in ure/source/uretest/Makefile.

Change-Id: I2829db390e37dfe5daeda33a4c0659b7d35e565a
2014-11-25 23:22:13 +01:00
15b4ab8d19 cppuhelper: clean up public headers with include-what-you-use
Change-Id: I41ba46831f24b2960a1fe982b74a2b623e682e0b
2014-11-18 18:51:49 +01:00
6a0fe37dec sal: clean up public headers with include-what-you-use
Sadly cannot forward declare "struct {...} TimeValue;".

rtl/(u)?string.hxx still include sal/log.hxx but removing osl/diagnose.h
was painful enough for now...

Change-Id: Id41e17f3870c4f24c53ce7b11f2c40a3d14d1f05
2014-11-17 11:06:53 +01:00
da40cac540 Fix common typos. No automatic tools. Handmade…
Change-Id: I1ab4e23b0539f8d39974787f226e57a21f96e959
Reviewed-on: https://gerrit.libreoffice.org/12164
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
2014-11-12 11:04:11 +00:00
cd3204559c fix spelling implemenation -> implementation
Change-Id: I5ac499df1f4063a80a5d41f60778106a7b96940d
2014-11-10 13:36:03 +02:00
4d7c414a8d Add include
Change-Id: I0598e9d0c9c33c538aa02eabc2c09d96ec3c9b4d
2014-10-30 09:33:01 +01:00
922f2005f3 fdo#43157 - Clean up OSL_ASSERT, DBG_ASSERT
- Clean up OSL_ASSERT

Change-Id: I1f3a5dcfe08876da9bb4a8486311eb0ca9bab215
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
2014-10-29 12:37:17 +01:00
c353caee1c loplugin: cstylecast
Change-Id: I53b69a488c70769cbb841db519bc28fd211dc087
2014-09-29 12:50:35 +02:00
4e124fd140 Don't try to write Python bytecode files in case of a read-only installset
It causes annoying messages in the system log in the OS X sandboxed
case.

Change-Id: I8ae3eb34df2c045bdbdfc63cae9007f973c42537
2014-09-21 21:11:30 +03:00
e660e1ed73 pyuno: remove obsolete NOOPT comment about GCC 3.2
Change-Id: Ie280325ddc45a79f3b73ae10f6e9cf952657091b
2014-09-12 18:42:11 +02:00
6492c8576e Make the "Mac-like" or "canonical" app bundle structure always used on OS X
In other words, only executable files go in the MacOS folder. Dynamic
libraries and bundled frameworks (i.e., LibreOfficePython), and
nothing else, go in the Frameworks folder, and all other files go in
the Resources folder.

Especially, note that Java class files and rc (.ini) files also go in
Resources.

Such an app bundle structure is what Apple strongly suggests one
should use, and it has been hinted that future versions of code
signing and/or Gatekeeper will require such a structure.

There is still some ugliness thanks to traces of the historical
separation of URE from "the office". Like there are two separate
"unorc" files, one for URE, one for the LibreOffice application. IMHO,
this should be cleaned up, but is probably controversial.

(Eek! I now see there are actually *three* unorc files in the app
bundle. Not intentional. Need to fix that later.)

Change-Id: Idcf235038deb5b8e1d061734993e9f31869b7606
2014-09-09 13:55:23 +03:00