OOO+daisy+python=?

I have got a bit interested in the python macros for OpenOffice…

You can start by adding your python macros in the

$HOME/.openoffice.org/3/user/Scripts/python

folder. The files should end with a dot py, i.e., “.py”. This is quite elegant, because you can now use your favorite editor (which is not the vi) to change the python code directly, rather than going through the OpenOffice macro editor… The macros are accessed through the Tools > Macros > Run Macro > My Macros > …

A very simple script, but quite useful, to align all frames in a document to a certain width would be:


import uno
from com.sun.star.awt import Size
from com.sun.star.beans import PropertyValue
def daisyAlignFrames():
currentDoc = XSCRIPTCONTEXT.getDocument()
textPtr = currentDoc.Text
textWidth = 17000
color = 1221231
frameStyle = "Frame"
for i in range(0, currentDoc.TextFrames.getCount()):
activeFrame = currentDoc.TextFrames.getByIndex(i)
activeFrame.setPropertyValue( "FrameStyleName", frameStyle)
activeFrame.setSize(Size(textWidth, 1))
activeFrame.setPropertyValue( "BackColor", color)
activeFrame.setPropertyValue( "FrameIsAutomaticHeight", True )
g_exportedScripts = daisyAlignFrames,

And sorry for not being able to represent the so important python indention. The code from def downto g_exportedScripts should be indentend one step. Then all the activeFrame rows should be indented yet a step to be caught by the for loop. To illustrate further, I have for the fun of it also added a coloring of the frame… It would be trivial to add to the loop to search for only certain types of frames, etc.

Advertisements

One thought on “OOO+daisy+python=?

  1. And, of course, the width is in this case 17000 which corresponds to 17 cm. So, OpenOffice is using the good-old 10-um scale… The color is given in RGB-style.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s