Handling UNO objects, images, lists (in Python)

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Handling UNO objects, images, lists (in Python)

Post 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?
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Handling UNO objects, images, lists (in Python)

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Re: Handling UNO objects, images, lists (in Python)

Post 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 :)
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Re: Handling UNO objects, images, lists (in Python)

Post 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?
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
_savage
Posts: 198
Joined: Sun Apr 21, 2013 12:55 am

Re: Handling UNO objects, images, lists (in Python)

Post 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'
Mac 13.7 using LO 24.8.2.1, Ubuntu Linux using LO 24.8 headless.
Post Reply