Module fig :: Class File

Class File




Main class of the fig module, represents an XFig document.

Instance Methods
 
__init__(self, inputFile=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
append(self, object)
Adds the object to this document.
 
addColor(self, hexCode)
Adds a custom color to this document.
 
getColor(self, color, similarity=None)
Return a color object for the given color, adding a new custom color to this document if it does not yet exist.
 
colorRGB(self, colorIndex)
Return a the R,G,B tuple for the given color index.
 
gray(self, grayLevel)
Return a color representing the given graylevel (see getColor).
 
headerStr(self)
Return the first lines of the XFig file output, which contain global document information like orientation / units / ...
 
objectsStr(figfile)
Returns the part of the XFig file containing all objects (but not the custom colors).
 
__str__(self)
Return the contents of this file as string in the XFig file format.
 
save(figfile, filename= None)
Saves the contents of this file in the XFig file format to the file 'filename'.
 
fig2dev(figfile, input= None, output= None, lang= "eps")
Calls fig2dev on the file input to produce the file output.

Inherited from Container: __deepcopy__, allObjects, bounds, findObjects, layer, layers, remove

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, count, extend, index, insert, pop, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__

Properties
  centered
  colors
  comment
  filename
  landscape
  magnification
  metric
  paperSize
  ppi
  singlePage
  transparentColor

Inherited from object: __class__

Method Details

__init__(self, inputFile=None)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Returns:
new list

Overrides: list.__init__
(inherited documentation)

append(self, object)

 
Adds the object to this document. object is supposed to be a fig.Object-derived object. CustomColor objects are appended to self.colors as if addColor() was called.
Overrides: list.append

addColor(self, hexCode)

 
Adds a custom color to this document. hexCode may be either a hex code like #ffee00 or a CustomColor instance. Returns the new CustomColor object. See getColor, too.

getColor(self, color, similarity=None)

 

Return a color object for the given color, adding a new custom color to this document if it does not yet exist. The color can be given as tuple of R,G,B values or as hex string (e.g. (0, 255, 0) or '#00ff00' for green). The range of valid R,G,B values depends on the type: integer values are expected to be in the range 0..255, while float values are interpreted as percentage values in the closed interval [0.0, 1.0].

If a CustomColor object with the given color is already present, it will be returned. Otherwise, addColor will be called, and the new object is returned.

If the optional parameter similarity is > 0.0, getColor() will return the first color found whose RGB difference's magnitude is < similarity, if any (otherwise, it will call addColor(), exactly as if similarity was not used). This is useful if you expect many thousands of slightly different colors, which are not supported by XFig (the current format supports 512 custom colors).

If similarity is given, but not > 0.0, addColor() will not be called, but a KeyError will be raised, if the exact color cannot be returned.

colorRGB(self, colorIndex)

 
Return a the R,G,B tuple for the given color index. (With values from the range 0..255.)

gray(self, grayLevel)

 
Return a color representing the given graylevel (see getColor). grayLevel can be a float in the range 0.0 - 1.0 or a 0 - 255 integer.

objectsStr(figfile)

 
Returns the part of the XFig file containing all objects (but not the custom colors). This is the same as str(object) concatenated for each object in figfile.

__str__(self)
(Informal representation operator)

 
Return the contents of this file as string in the XFig file format. See save().
Overrides: object.__str__

save(figfile, filename= None)

 

Saves the contents of this file in the XFig file format to the file 'filename'. Equivalent to:

file(filename, "w").write(str(figfile))

If filename is not given, and figfile was constructed from an existing file, that one is overwritten (-> figfile.filename). If the filename does not end in '.fig', the extension is appended.

After saving, the filename becomes the new figfile.filename and would be used for the next save() without filename.

The return value is the output file written last, i.e. it depends on whether fig2dev was given:

  • if fig2dev == None (default), figfile.filename is returned
  • otherwise, the exported filename is returned (e.g. basename.eps)

fig2dev(figfile, input= None, output= None, lang= "eps")

 

Calls fig2dev on the file input to produce the file output. (Both default to the current figfile's filename and the same filename with the extension changed to lang.) Note that output must be a path relative to the `input` path! Returns the filename of the resulting file.

Usually, you just call sth. like

figfile = fig.File("myfigfile.fig")
...
figfile.save()
figfile.fig2dev(lang = "pdf")

to produce myfigfile.pdf. It is now even easier to use the following convenience shortcut:

figfile.save(fig2dev = "pdf")