EOEC speeds up development, but given how complicated the OpenOffice.org API is in some parts it is also very important to facilitate code reuse, and this is why we have started to collect the most often used pieces of code in a supplemental API package. This is the util module that you can access from your extensions.
The functions in this module deal with UNO API related to Draw objects.
The unit of measurement used for coordinates in the UNO API is one thousandth of an inch. It is also used internally in OpenOffice.org and only integer coordinates are allowed.
Converts a color given in float representation to the format used in the UNO API. For example rgb(1.0, 0.0, 0.0) is red.
| Parameters: |
|
|---|---|
| Return type: | int |
| Returns: | the integer representation of the color suitable for use with the UNO API |
Converts a color given in integer representation to the format used in the UNO API. For example rgb(255, 0, 0) is red.
| Parameters: |
|
|---|---|
| Return type: | int |
| Returns: | the integer representation of the color suitable for use with the UNO API |
Moves and optionally resizes a Draw object.
| Parameters: |
|
|---|
Creates a new shape and adds it to the DrawPage.
The shape is created by:
model.createInstance( 'com.sun.star.drawing.%sShape'%shapetype )
| Parameters: |
|
|---|
Uses createShape to create a com.sun.star.drawing.PolyPolygonShape or com.sun.star.drawing.PolyLineShape. The “PolyPolygon” shape is made up of the combination of a number of polygons, each of which are a closed outline. (The polygons are implicitly closed, there is no need to duplicate the first point.) The “PolyLine” shape is a collection of line sequences.
| Parameters: |
|
|---|
Inserts the image into the document as an embedded image. As opposed to a linked image it will be saved into the document instead of becoming an external dependency.
| Parameters: |
|
|---|
The functions in this module deal with UNO API related to Writer documents.
Gets the word under the text cursor. Returns a cursor object for the word which you can then use to access and modify the word:
import util.writer
cursor = util.writer.getWord(self.getcontroller())
if cursor.String == 'something':
# replace something with something else
cursor.String = 'something else'
| Parameter: | view (com.sun.star.text.XTextViewCursorSupplier) – The current TextDocumentView typically as returned by extensioncore.ComponentBase.getcontroller(). |
|---|---|
| Return type: | com.sun.star.text.XTextViewCursor |
| Returns: | A cursor object for the word. |
Since the web contains such a large number of useful sources of information and services, an extension might want to make efficient use of it. The goal of this module is to help with this.
Retrieves the page with the given URL.
urllib2 is used and the User-agent HTTP header is set to:
Mozilla/5.0 (OpenOffice.org extension "My Extension" created with EuroOffice Extension Creator)
The extension name is injected by the create.py script. To use a different User-agent header, util/web.py will have to be modified.
| Parameter: | url (string) – URL of the page to retrieve |
|---|---|
| Return type: | string |
| Returns: | contents of the web page |
Retrieves the page with the given URL.
This function uses a global cache object. If the given URL has already been retrieved by getpage(), it will be served from a persistent cache. If it has not yet been cached, it is retrieved with loadpage() and added to the cache.
| Parameter: | url (string) – URL of the page to retrieve |
|---|---|
| Return type: | string |
| Returns: | contents of the web page |
Flatten a Beautiful Soup object. Sometimes nothing but the bare text content is wanted from part of a web page, and this function supplements the Beautiful Soup API to provide access to it.
| Parameter: | x – the Beautiful Soup object |
|---|---|
| Return type: | string |
| Returns: | the flattened string |
The maximal cache size. Once the cache reaches this size it is deleted and a new cache is started.
Defaults to 10MB.
The file name to use for the web cache. By default the file name './cache' is used, but this can depend highly on platform and OpenOffice.org build, so setting the cache file name is important.
If the file named does not exist a new file will be created. Take care, because if the file exists, but is not actually a cache file it will be overwritten with a cache file.