ODFPY 1.2.0
 
Loading...
Searching...
No Matches
odf.opendocument.OpenDocument Class Reference

Public Member Functions

 __init__ (self, mimetype, add_generator=True)
 the constructor
 
 rebuild_caches (self, node=None)
 
 clear_caches (self)
 Clears internal caches.
 
 build_caches (self, elt)
 Builds internal caches; called from element.py.
 
 remove_from_caches (self, elt)
 Updates internal caches when an element has been removed.
 
 toXml (self, filename=u'')
 converts the document to a valid Xml format.
 
 xml (self)
 Generates the full document as an XML "file".
 
 contentxml (self)
 Generates the content.xml file.
 
 metaxml (self)
 Generates the meta.xml file.
 
 settingsxml (self)
 Generates the settings.xml file.
 
 stylesxml (self)
 Generates the styles.xml file.
 
 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.
 
 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'.
 
 addPictureFromString (self, content, mediatype)
 Add a picture from contents given as a Byte string.
 
 addThumbnail (self, filecontent=None)
 Add a fixed thumbnail The thumbnail in the library is big, so this is pretty useless.
 
 addObject (self, document, objectname=None)
 Adds an object (subdocument).
 
 save (self, outputfile, addsuffix=False)
 Save the document under the filename.
 
 write (self, outputfp)
 User API to write the ODF file to an open file descriptor Writes the ZIP format.
 
 createElement (self, elt)
 Inconvenient interface to create an element, but follows XML-DOM.
 
 createTextNode (self, data)
 Method to create a text node.
 
 createCDATASection (self, data)
 Method to create a CDATA section.
 
 getMediaType (self)
 Returns the media type.
 
 getStyleByName (self, name)
 Finds a style object based on the name.
 
 getElementsByType (self, elt)
 Gets elements based on the type, which is function from text.py, draw.py etc.
 

Public Attributes

 mimetype
 
 childobjects
 
 folder
 
 topnode
 
 Pictures
 
 meta
 
 scripts
 
 fontfacedecls
 
 settings
 
 styles
 
 automaticstyles
 
 masterstyles
 
 body
 
 element_dict
 
 manifest
 

Static Public Attributes

 thumbnail = None
 

Protected Member Functions

 _parseoneelement (self, top, stylenamelist)
 Finds references to style objects in master-styles and add the style name to the style list if not already there.
 
 _used_auto_styles (self, segments)
 Loop through the masterstyles elements, and find the automatic styles that are used.
 
 _savePictures (self, anObject, folder)
 saves pictures contained in an object
 
 _saveXmlObjects (self, anObject, folder)
 save xml objects of an opendocument to some folder
 

Protected Attributes

 _extra
 
 _styles_dict
 
 _styles_ooo_fix
 
 _z
 
 _now
 

Detailed Description

Definition at line 123 of file opendocument.py.

Constructor & Destructor Documentation

◆ __init__()

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

the constructor

Parameters
mimetypea unicode string
add_generatora boolean

Definition at line 131 of file opendocument.py.

Member Function Documentation

◆ _parseoneelement()

odf.opendocument.OpenDocument._parseoneelement (   self,
  top,
  stylenamelist 
)
protected

Finds references to style objects in master-styles and add the style name to the style list if not already there.

Recursive

Returns
the list of style names as unicode strings

Definition at line 363 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _savePictures()

odf.opendocument.OpenDocument._savePictures (   self,
  anObject,
  folder 
)
protected

saves pictures contained in an object

Parameters
anObjectinstance of OpenDocument containing pictures
folderunicode string: place to save pictures

Definition at line 558 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _saveXmlObjects()

odf.opendocument.OpenDocument._saveXmlObjects (   self,
  anObject,
  folder 
)
protected

save xml objects of an opendocument to some folder

Parameters
anObjectinstance of OpenDocument
folderunicode string place to save xml objects

Definition at line 688 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _used_auto_styles()

odf.opendocument.OpenDocument._used_auto_styles (   self,
  segments 
)
protected

Loop through the masterstyles elements, and find the automatic styles that are used.

These will be added to the automatic-styles

element in styles.xml
Returns
a list of element.Element instances

Definition at line 397 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addObject()

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

Adds an object (subdocument).

The object must be an OpenDocument class

Parameters
documentOpenDocument instance
objectnameunicode 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 540 of file opendocument.py.

◆ addPicture()

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
filenameunicode string: name of a file for Pictures
mediatypeunicode string: name of a media, None by default
contentbytes: content of media, None by default
Returns
a unicode string: the file name of the media, eventually created on the fly

Definition at line 450 of file opendocument.py.

◆ addPictureFromFile()

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
filesnameunicode string: name of an image file
mediatypeunicode string: type of media, dfaults to None
Returns
a unicode string, the name of the created file

Definition at line 483 of file opendocument.py.

◆ addPictureFromString()

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
contentbytes: content of media
mediatypeunicode string: name of a media
Returns
a unicode string, the name of the created file

Definition at line 510 of file opendocument.py.

◆ addThumbnail()

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

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

Parameters
filecontentbytes: the content of a file; defaults to None

Definition at line 524 of file opendocument.py.

◆ build_caches()

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

Builds internal caches; called from element.py.

Parameters
eltan element.Element instance

Definition at line 183 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_caches()

odf.opendocument.OpenDocument.clear_caches (   self)

Clears internal caches.

Definition at line 174 of file opendocument.py.

◆ contentxml()

odf.opendocument.OpenDocument.contentxml (   self)

Generates the content.xml file.

Returns
a bytestream in UTF-8 encoding

Definition at line 286 of file opendocument.py.

Here is the call graph for this function:

◆ createCDATASection()

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

Method to create a CDATA section.

Parameters
dataunicode string to include in the CDATA element
Returns
an instance of element.CDATASection

Definition at line 763 of file opendocument.py.

◆ createElement()

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
eltelement.Element instance
Returns
an element.Element instance whose grammar is not checked

Definition at line 739 of file opendocument.py.

◆ createTextNode()

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

Method to create a text node.

Parameters
dataunicode string to include in the Text element
Returns
an instance of element.Text

Definition at line 753 of file opendocument.py.

◆ getElementsByType()

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

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

Parameters
eltinstance of a function which returns an element.Element
Returns
a list of istances of element.Element

Definition at line 799 of file opendocument.py.

Here is the call graph for this function:

◆ getMediaType()

odf.opendocument.OpenDocument.getMediaType (   self)

Returns the media type.

Returns
a unicode string

Definition at line 772 of file opendocument.py.

◆ getStyleByName()

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

Finds a style object based on the name.

Parameters
nameunicode string the name of style to search
Returns
a syle as an element.Element instance

Definition at line 782 of file opendocument.py.

Here is the call graph for this function:

◆ metaxml()

odf.opendocument.OpenDocument.metaxml (   self)

Generates the meta.xml file.

Returns
a unicode string

Definition at line 327 of file opendocument.py.

Here is the call graph for this function:

◆ rebuild_caches()

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:

◆ remove_from_caches()

odf.opendocument.OpenDocument.remove_from_caches (   self,
  elt 
)

Updates internal caches when an element has been removed.

Parameters
eltan element.Element instance

Definition at line 204 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

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

Save the document under the filename.

If the filename is '-' then save to stdout

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

Definition at line 605 of file opendocument.py.

Here is the call graph for this function:

◆ settingsxml()

odf.opendocument.OpenDocument.settingsxml (   self)

Generates the settings.xml file.

Returns
a unicode string

Definition at line 342 of file opendocument.py.

Here is the call graph for this function:

◆ stylesxml()

odf.opendocument.OpenDocument.stylesxml (   self)

Generates the styles.xml file.

Returns
valid XML code as a unicode string

Definition at line 417 of file opendocument.py.

Here is the call graph for this function:

◆ toXml()

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

converts the document to a valid Xml format.

Parameters
filenameunicode 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 249 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

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

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

Parameters
outputfpopen file descriptor

Definition at line 621 of file opendocument.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xml()

odf.opendocument.OpenDocument.xml (   self)

Generates the full document as an XML "file".

Returns
a bytestream in UTF-8 encoding

Definition at line 271 of file opendocument.py.

Here is the call graph for this function:

Member Data Documentation

◆ _extra

odf.opendocument.OpenDocument._extra
protected

Definition at line 137 of file opendocument.py.

◆ _now

odf.opendocument.OpenDocument._now
protected

Definition at line 636 of file opendocument.py.

◆ _styles_dict

odf.opendocument.OpenDocument._styles_dict
protected

Definition at line 176 of file opendocument.py.

◆ _styles_ooo_fix

odf.opendocument.OpenDocument._styles_ooo_fix
protected

Definition at line 177 of file opendocument.py.

◆ _z

odf.opendocument.OpenDocument._z
protected

Definition at line 635 of file opendocument.py.

◆ automaticstyles

odf.opendocument.OpenDocument.automaticstyles

Definition at line 157 of file opendocument.py.

◆ body

odf.opendocument.OpenDocument.body

Definition at line 161 of file opendocument.py.

◆ childobjects

odf.opendocument.OpenDocument.childobjects

Definition at line 136 of file opendocument.py.

◆ element_dict

odf.opendocument.OpenDocument.element_dict

Definition at line 175 of file opendocument.py.

◆ folder

odf.opendocument.OpenDocument.folder

Definition at line 138 of file opendocument.py.

◆ fontfacedecls

odf.opendocument.OpenDocument.fontfacedecls

Definition at line 151 of file opendocument.py.

◆ manifest

odf.opendocument.OpenDocument.manifest

Definition at line 637 of file opendocument.py.

◆ masterstyles

odf.opendocument.OpenDocument.masterstyles

Definition at line 159 of file opendocument.py.

◆ meta

odf.opendocument.OpenDocument.meta

Definition at line 145 of file opendocument.py.

◆ mimetype

odf.opendocument.OpenDocument.mimetype

Definition at line 135 of file opendocument.py.

◆ Pictures

odf.opendocument.OpenDocument.Pictures

Definition at line 144 of file opendocument.py.

◆ scripts

odf.opendocument.OpenDocument.scripts

Definition at line 149 of file opendocument.py.

◆ settings

odf.opendocument.OpenDocument.settings

Definition at line 153 of file opendocument.py.

◆ styles

odf.opendocument.OpenDocument.styles

Definition at line 155 of file opendocument.py.

◆ thumbnail

odf.opendocument.OpenDocument.thumbnail = None
static

Definition at line 124 of file opendocument.py.

◆ topnode

odf.opendocument.OpenDocument.topnode

Definition at line 139 of file opendocument.py.


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