ODFPY 1.2.0 |

All Classes Namespaces Files Functions Variables
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
odf.opendocument.OpenDocument Class Reference

A class to hold the content of an OpenDocument document Use the xml method to write the XML source to the screen or to a file. More...

## Public Member Functions
def | __init__
| the constructor More...
def | rebuild_caches
def | clear_caches
| Clears internal caches. More...
def | build_caches
| Builds internal caches; called from element.py. More...
def | toXml
| converts the document to a valid Xml format. More...
def | xml
| Generates the full document as an XML "file". More...
def | contentxml
| Generates the content.xml file. More...
def | metaxml
| Generates the meta.xml file. More...
def | settingsxml
| Generates the settings.xml file. More...
def | stylesxml
| Generates the styles.xml file. More...
def | addPicture
| Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures' If passed a file ptr, mediatype must be set. More...
def | addPictureFromFile
| Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures'. More...
def | addPictureFromString
| Add a picture from contents given as a Byte string. More...
def | addThumbnail
| Add a fixed thumbnail The thumbnail in the library is big, so this is pretty useless. More...
def | addObject
| Adds an object (subdocument). More...
def | save
| Save the document under the filename. More...
def | write
| User API to write the ODF file to an open file descriptor Writes the ZIP format. More...
def | createElement
| Inconvenient interface to create an element, but follows XML-DOM. More...
def | createTextNode
| Method to create a text node. More...
def | createCDATASection
| Method to create a CDATA section. More...
def | getMediaType
| Returns the media type. More...
def | getStyleByName
| Finds a style object based on the name. More...
def | getElementsByType
| Gets elements based on the type, which is function from text.py, draw.py etc. More...

## Public Attributes
| mimetype
| childobjects
| folder
| topnode
| Pictures
| meta
| scripts
| fontfacedecls
| settings
| styles
| automaticstyles
| masterstyles
| body
| element_dict
| manifest

## Static Public Attributes
| thumbnail = None

## Detailed Description

A class to hold the content of an OpenDocument document Use the xml method to write the XML source to the screen or to a file.

Example of use: d = OpenDocument(mimetype); fd.write(d.xml())

Definition at line 122 of file opendocument.py.

## Constructor & Destructor Documentation

def odf.opendocument.OpenDocument.__init__ | ( |  | self,
|  |  | mimetype,
|  |  | add_generator = `True`
| ) |  |

the constructor

Parameters

  mimetype | a unicode string
  add_generator | a boolean

Definition at line 131 of file opendocument.py.

## Member Function Documentation

def odf.opendocument.OpenDocument.addObject | ( |  | self,
|  |  | document,
|  |  | objectname = `None`
| ) |  |

Adds an object (subdocument).

The object must be an OpenDocument class

Parameters

  document | OpenDocument instance
  objectname | unicode string: the name of an object to add

Returns
  a unicode string: the folder name in the zipfile the object is stored in.

Definition at line 531 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.addPicture | ( |  | self,
|  |  | filename,
|  |  | mediatype = `None`,
|  |  | content = `None`
| ) |  |

Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures' If passed a file ptr, mediatype must be set.

Parameters

  filename | unicode string: name of a file for Pictures
  mediatype | unicode string: name of a media, None by default
  content | bytes: content of media, None by default

Returns
  a unicode string: the file name of the media, eventually created on the fly

Definition at line 436 of file opendocument.py.

def odf.opendocument.OpenDocument.addPictureFromFile | ( |  | self,
|  |  | filename,
|  |  | mediatype = `None`
| ) |  |

Add a picture It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures'.

If mediatype is not given, it will be guessed from the filename extension.

Parameters

  filesname | unicode string: name of an image file
  mediatype | unicode string: type of media, dfaults to None

Returns
  a unicode string, the name of the created file

Definition at line 471 of file opendocument.py.

def odf.opendocument.OpenDocument.addPictureFromString | ( |  | self,
|  |  | content,
|  |  | mediatype
| ) |  |

Add a picture from contents given as a Byte string.

It uses the same convention as OOo, in that it saves the picture in the zipfile in the subdirectory 'Pictures'. The content variable is a string that contains the binary image data. The mediatype indicates the image format.

Parameters

  content | bytes: content of media
  mediatype | unicode string: name of a media

Returns
  a unicode string, the name of the created file

Definition at line 499 of file opendocument.py.

def odf.opendocument.OpenDocument.addThumbnail | ( |  | self,
|  |  | filecontent = `None`
| ) |  |

Add a fixed thumbnail The thumbnail in the library is big, so this is pretty useless.

Parameters

  filecontent | bytes: the content of a file; defaults to None

Definition at line 514 of file opendocument.py.

def odf.opendocument.OpenDocument.build_caches | ( |  | self,
|  |  | elt
| ) |  |

Builds internal caches; called from element.py.

Parameters

  elt | an element.Element instance

Definition at line 185 of file opendocument.py.

Here is the call graph for this function:

Here is the caller graph for this function:

def odf.opendocument.OpenDocument.clear_caches | ( |  | self | ) |

Clears internal caches.

Definition at line 175 of file opendocument.py.

def odf.opendocument.OpenDocument.contentxml | ( |  | self | ) |

Generates the content.xml file.

Returns
  a bytestream in UTF-8 encoding

Definition at line 273 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.createCDATASection | ( |  | self,
|  |  | data
| ) |  |

Method to create a CDATA section.

Parameters

  data | unicode string to include in the CDATA element

Returns
  an instance of element.CDATASection

Definition at line 759 of file opendocument.py.

def odf.opendocument.OpenDocument.createElement | ( |  | self,
|  |  | elt
| ) |  |

Inconvenient interface to create an element, but follows XML-DOM.

Does not allow attributes as argument, therefore can't check grammar.

Parameters

  elt | element.Element instance

Returns
  an element.Element instance whose grammar is not checked

Definition at line 733 of file opendocument.py.

def odf.opendocument.OpenDocument.createTextNode | ( |  | self,
|  |  | data
| ) |  |

Method to create a text node.

Parameters

  data | unicode string to include in the Text element

Returns
  an instance of element.Text

Definition at line 748 of file opendocument.py.

def odf.opendocument.OpenDocument.getElementsByType | ( |  | self,
|  |  | elt
| ) |  |

Gets elements based on the type, which is function from text.py, draw.py etc.

Parameters

  elt | instance of a function which returns an element.Element

Returns
  a list of istances of element.Element

Definition at line 798 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.getMediaType | ( |  | self | ) |

Returns the media type.

Returns
  a unicode string

Definition at line 769 of file opendocument.py.

def odf.opendocument.OpenDocument.getStyleByName | ( |  | self,
|  |  | name
| ) |  |

Finds a style object based on the name.

Parameters

  name | unicode string the name of style to search

Returns
  a syle as an element.Element instance

Definition at line 780 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.metaxml | ( |  | self | ) |

Generates the meta.xml file.

Returns
  a unicode string

Definition at line 314 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.rebuild_caches | ( |  | self,
|  |  | node = `None`
| ) |  |

Definition at line 164 of file opendocument.py.

Here is the call graph for this function:

Here is the caller graph for this function:

def odf.opendocument.OpenDocument.save | ( |  | self,
|  |  | outputfile,
|  |  | addsuffix = `False`
| ) |  |

Save the document under the filename.

If the filename is '-' then save to stdout

Parameters

  outputfile | unicode string: the special name '-' is for stdout; as an alternative, it can be an io.ByteIO instance which contains the ZIP content.
  addsuffix | boolean: whether to add a suffix or not; defaults to False

Definition at line 595 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.settingsxml | ( |  | self | ) |

Generates the settings.xml file.

Returns
  a unicode string

Definition at line 330 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.stylesxml | ( |  | self | ) |

Generates the styles.xml file.

Returns
  valid XML code as a unicode string

Definition at line 402 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.toXml | ( |  | self,
|  |  | filename = `u''`
| ) |  |

converts the document to a valid Xml format.

Parameters

  filename | unicode string: the name of a file, defaults to an empty string.

Returns
  if filename is not empty, the XML code will be written into it and the method returns None; otherwise the method returns a StringIO containing valid XML. Then a ".getvalue()" should return a unicode string.

Definition at line 234 of file opendocument.py.

def odf.opendocument.OpenDocument.write | ( |  | self,
|  |  | outputfp
| ) |  |

User API to write the ODF file to an open file descriptor Writes the ZIP format.

Parameters

  outputfp | open file descriptor

Definition at line 614 of file opendocument.py.

Here is the call graph for this function:

def odf.opendocument.OpenDocument.xml | ( |  | self | ) |

Generates the full document as an XML "file".

Returns
  a bytestream in UTF-8 encoding

Definition at line 257 of file opendocument.py.

Here is the call graph for this function:

## Member Data Documentation

odf.opendocument.OpenDocument.automaticstyles

Definition at line 157 of file opendocument.py.

odf.opendocument.OpenDocument.body

Definition at line 161 of file opendocument.py.

odf.opendocument.OpenDocument.childobjects

Definition at line 136 of file opendocument.py.

odf.opendocument.OpenDocument.element_dict

Definition at line 176 of file opendocument.py.

odf.opendocument.OpenDocument.folder

Definition at line 138 of file opendocument.py.

odf.opendocument.OpenDocument.fontfacedecls

Definition at line 151 of file opendocument.py.

odf.opendocument.OpenDocument.manifest

Definition at line 631 of file opendocument.py.

odf.opendocument.OpenDocument.masterstyles

Definition at line 159 of file opendocument.py.

odf.opendocument.OpenDocument.meta

Definition at line 145 of file opendocument.py.

odf.opendocument.OpenDocument.mimetype

Definition at line 135 of file opendocument.py.

odf.opendocument.OpenDocument.Pictures

Definition at line 144 of file opendocument.py.

odf.opendocument.OpenDocument.scripts

Definition at line 149 of file opendocument.py.

odf.opendocument.OpenDocument.settings

Definition at line 153 of file opendocument.py.

odf.opendocument.OpenDocument.styles

Definition at line 155 of file opendocument.py.

odf.opendocument.OpenDocument.thumbnail = None
| static

Definition at line 123 of file opendocument.py.

odf.opendocument.OpenDocument.topnode

Definition at line 139 of file opendocument.py.

The documentation for this class was generated from the following file:

- odf/opendocument.py