Page 1 of 1
Handling UNO objects, images, lists (in Python)
Posted: Wed Oct 02, 2013 7:44 pm
by _savage
These questions are somewhat Python related, but I'd think they can be answered for different languages as well.
- Is there a way, given an UNO object like a paragraph or text portion (each of which implements different interfaces), to read certain attributes from it using a generic method? For example, I can say par.CharHeight but is there something like read_attr(par, "CharHeight") or some such?
- When iterating over the paragraphs and text portions of a document, how do I recognize numbered/unordered lists?
- Same as above, how to I recognize images?
I feel like these questions I could answer myself by reading the API but I found it difficult to browse it (very complex). There's a Wiki which has an occasional answer but in general I find it difficult to dig through UNO. Where is a good and comprehensive document, if there is one?
Re: Handling UNO objects, images, lists (in Python)
Posted: Wed Oct 02, 2013 7:50 pm
by Villeroy
Install the MRI extension.
Read and understand
http://www.openoffice.org/udk/python/python-bridge.html
Of course, you should be fluent in Python.
Re: Handling UNO objects, images, lists (in Python)
Posted: Fri Oct 04, 2013 8:40 pm
by _savage
The document seems a little outdated, but it's an interesting introduction. Thanks!
It didn't really answer my questions though: how to I recognize images and numbered lists when I iterate over the paragraphs of a document? I also tried different ways of reading attributes (as described in the above document) but that's didn't really work either.
So I'm not any farther than before

Re: Handling UNO objects, images, lists (in Python)
Posted: Mon Oct 07, 2013 8:53 pm
by _savage
Well, it seems like lists (enumerations) are implemented by paragraph style "NumberingStyleName" different than an empty string, for example
Code: Select all
> par.NumberingStyleName
'WW8Num2'
indicates an element of a numbered list. Other properties like "ParaIsNumberingRestart" and "NumberingStartValue" and "NumberingLevel" give more information on the context of this paragraph list. So it seems, at least.
As for images, I am still unsure.
As for how to query random properties of a UNO object, I am still unsure.
I also assume that footnotes are handled as paragraph styles also?
Re: Handling UNO objects, images, lists (in Python)
Posted: Mon Oct 07, 2013 9:37 pm
by _savage
_savage wrote:As for how to query random properties of a UNO object, I am still unsure.
This is how it seems to work, although some more checks to make sure a particular interface is implemented by a UNO object would help:
Code: Select all
>>> type(par)
<class 'pyuno'>
>>> getattr(par, "ParaStyleName")
'Free Form'
>>> getattr(par, "CharFontName")
'Comic Sans MS'