Remove unused "SpreadSheet" document generators.

svn: r13942
This commit is contained in:
Brian Matherly 2009-12-29 19:38:07 +00:00
parent c2d99c34b3
commit 3f4c9b31ed
6 changed files with 1 additions and 1114 deletions

View File

@ -335,10 +335,7 @@ src/DateHandler/_Date_sv.py
src/DateHandler/__init__.py
# docgen directory
src/docgen/ODSDoc.py
src/docgen/ODSTab.py
src/docgen/OpenSpreadSheet.py
src/docgen/SpreadSheetDoc.py
src/docgen/TextBufDoc.py
# GrampsLocale package

View File

@ -7,10 +7,7 @@ docgendir=$(prefix)/share/gramps/docgen
docgen_PYTHON = \
__init__.py \
CSVTab.py \
ODSDoc.py \
ODSTab.py \
OpenSpreadSheet.py \
SpreadSheetDoc.py \
TabbedDoc.py \
TextBufDoc.py

View File

@ -1,510 +0,0 @@
k#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id:
#-------------------------------------------------------------------------
#
# Standard Python Modules
#
#-------------------------------------------------------------------------
import os
import tempfile
import zipfile
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.plug.docgen import FONT_SERIF
from docgen import SpreadSheetDoc
import const
import Errors
#-------------------------------------------------------------------------
#
# ODSDoc
#
#-------------------------------------------------------------------------
class ODSDoc(SpreadSheetDoc):
def __init__(self,type, orientation):
SpreadSheetDoc.__init__(self,type, orientation)
self.f = None
self.filename = None
self.level = 0
self.time = "0000-00-00T00:00:00"
def open(self,filename):
import time
t = time.localtime(time.time())
self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % t[:6]
if filename[-4:] != ".ods":
self.filename = filename + ".ods"
else:
self.filename = filename
try:
self.content_xml = tempfile.mktemp()
self.f = open(self.content_xml,"wb")
except IOError,msg:
raise Errors.ReportError(_("Could not create %s") % self.content_xml, msg)
except:
raise Errors.ReportError(_("Could not create %s") % self.content_xml)
self.f = open(self.content_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-content ')
self.f.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
self.f.write('xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ')
self.f.write('xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ')
self.f.write('xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ')
self.f.write('xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ')
self.f.write('xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
self.f.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
self.f.write('xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ')
self.f.write('xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ')
self.f.write('xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ')
self.f.write('xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ')
self.f.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
self.f.write('xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ')
self.f.write('xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ')
self.f.write('xmlns:dom="http://www.w3.org/2001/xml-events" ')
self.f.write('xmlns:xforms="http://www.w3.org/2002/xforms" ')
self.f.write('xmlns:xsd="http://www.w3.org/2001/XMLSchema" ')
self.f.write('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ')
self.f.write('office:version="1.0"> ')
self.f.write('<office:script/>\n')
self.f.write('<office:font-face-decls>\n')
self.f.write('<style:font-face style:name="Times New Roman" ')
self.f.write('svg:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('<style:font-face style:name="Arial" ')
self.f.write('svg:font-family="Arial" ')
self.f.write('style:font-family-generic="swiss" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('</office:font-face-decls>\n')
self.f.write('<office:automatic-styles>\n')
for key, table in self.table_styles.iteritems():
self.f.write('<style:style style:name="')
self.f.write(key)
self.f.write('" style:family="table" ')
self.f.write('style:master-page-name="Default"> \n')
self.f.write('<style:table-properties table:display="true" ')
self.f.write('style:writing-mode="lr-tb" /> \n')
self.f.write('</style:style>\n')
for index in range(0,table.get_columns()):
self.f.write('<style:style style:name="')
self.f.write(key + '_' + str(index))
self.f.write('" style:family="table-column">\n')
self.f.write('<style:table-column-properties fo:break-before="auto" ')
self.f.write('style:column-width="%.3fcm"/>\n' % table.get_column_width(index))
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="ro1" style:family="table-row">\n')
self.f.write('<style:table-row-properties fo:break-before="auto"/>\n')
self.f.write('</style:style>\n')
for key, style in self.style_list.iteritems():
font = style.get_font()
self.f.write('<style:style style:name="')
self.f.write(key)
self.f.write('" style:family="table-cell" ')
self.f.write('style:parent-style-name="Default">\n')
self.f.write('<style:table-cell-properties ')
self.f.write('fo:color="#%02x%02x%02x" ' % font.get_color())
bgcolor = style.get_background_color()
self.f.write('fo:background-color="#%02x%02x%02x" ' % bgcolor)
self.f.write('fo:padding-bottom="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-top="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-right="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-left="%.3fcm" ' % style.get_padding())
self.f.write('style:text-outline="false" ')
self.f.write('style:text-crossing-out="none" ')
if font.get_type_face() == FONT_SERIF:
self.f.write('style:font-name="Times New Roman" ')
else:
self.f.write('style:font-name="Arial" ')
self.f.write('fo:font-size="%dpt" ' % font.get_size())
if font.get_italic():
self.f.write('fo:font-style="italic" ')
else:
self.f.write('fo:font-style="normal" ')
self.f.write('fo:text-shadow="none" ')
self.f.write('style:text-underline="none" ')
if font.get_bold():
self.f.write('fo:font-weight="bold"/>\n')
else:
self.f.write('fo:font-weight="normal"/>\n')
self.f.write('</style:style>\n')
self.f.write('</office:automatic-styles>\n')
self.f.write('<office:body>\n')
self.f.write('<office:spreadsheet>\n')
def close(self):
self.f.write('</office:spreadsheet>\n')
self.f.write('</office:body>\n')
self.f.write('</office:document-content>\n')
self.f.close()
self._write_styles_file()
self._write_manifest()
self._write_meta_file()
self._write_mimetype_file()
self._write_zip()
def start_row(self):
self.f.write('<table:table-row table:style-name="')
self.f.write('ro1')
self.f.write('">\n')
def end_row(self):
self.f.write('</table:table-row>\n')
def start_cell(self,style_name,span=1):
self.content = 0
self.span = span
self.f.write('<table:table-cell table:style-name="')
self.f.write(style_name)
self.f.write('" table:value-type="string"')
if span > 1:
self.f.write(' table:number-columns-spanned="' + str(span) + '">\n')
else:
self.f.write('>\n')
def end_cell(self):
if self.content == 0:
self.f.write('<text:p/>\n')
else:
self.f.write('</text:p>\n')
self.f.write('</table:table-cell>\n')
for col in range(1,self.span):
self.f.write('<table:covered-table-cell/>\n')
def _write_zip(self):
try:
file = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED)
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
raise Errors.ReportError(errmsg)
except:
raise Errors.ReportError(_("Could not create %s") % self.filename)
file.write(self.manifest_xml,str("META-INF/manifest.xml"))
file.write(self.content_xml,str("content.xml"))
file.write(self.meta_xml,str("meta.xml"))
file.write(self.styles_xml,str("styles.xml"))
file.write(self.mimetype,str("mimetype"))
file.close()
os.unlink(self.manifest_xml)
os.unlink(self.content_xml)
os.unlink(self.meta_xml)
os.unlink(self.styles_xml)
def _write_styles_file(self):
self.styles_xml = tempfile.mktemp()
try:
self.f = open(self.styles_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.styles_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.styles_xml)
self.f = open(self.styles_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-styles ')
self.f.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
self.f.write('xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ')
self.f.write('xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ')
self.f.write('xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ')
self.f.write('xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ')
self.f.write('xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
self.f.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
self.f.write('xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ')
self.f.write('xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ')
self.f.write('xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ')
self.f.write('xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ')
self.f.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
self.f.write('xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ')
self.f.write('xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ')
self.f.write('xmlns:dom="http://www.w3.org/2001/xml-events" ')
self.f.write('office:version="1.0">')
self.f.write('<office:font-face-decls>\n')
self.f.write('<style:font-face style:name="Times New Roman" ')
self.f.write('svg:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('<style:font-face style:name="Arial" ')
self.f.write('svg:font-family="Arial" ')
self.f.write('style:font-family-generic="swiss" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('</office:font-face-decls>\n')
self.f.write('<office:styles>\n')
self.f.write('<style:default-style style:family="table-cell">\n')
self.f.write('<style:table-cell-properties style:decimal-places="2" />\n')
self.f.write('<style:paragraph-properties style:tab-stop-distance="0.2835inch"/>\n')
self.f.write('<style:text-properties style:font-name="Arial" />\n')
self.f.write('</style:default-style>\n')
self.f.write('<style:style style:name="Default" ')
self.f.write('style:family="table-cell" ')
self.f.write('style:data-style-name="N0"/>\n')
self.f.write('<style:default-style style:family="graphic">\n')
self.f.write('<style:text-properties fo:color="#000000" ')
self.f.write('fo:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-style-name="" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable" ')
self.f.write('fo:font-size="12pt" ')
self.f.write('fo:language="none" ')
self.f.write('fo:country="none" ')
self.f.write('style:text-autospace="ideograph-alpha" ')
self.f.write('style:punctuation-wrap="simple" ')
self.f.write('style:line-break="strict"/>\n')
self.f.write('</style:default-style>\n')
self.f.write('</office:styles>\n')
self.f.write('<office:automatic-styles>\n')
self.f.write('<style:page-layout style:name="pm1">\n')
self.f.write('<style:header-style>\n')
self.f.write('<style:header-footer-properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-bottom="0.0984inch"/>\n')
self.f.write('</style:header-style>\n')
self.f.write('<style:footer-style>\n')
self.f.write('<style:header-footer-properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-top="0.0984inch"/>\n')
self.f.write('</style:footer-style>\n')
self.f.write('</style:page-layout>\n')
self.f.write('<style:page-layout style:name="pm2">\n')
self.f.write('<style:header-style>\n')
self.f.write('<style:header-footer-properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-bottom="0.0984inch" ')
self.f.write('fo:border="0.0346inch solid #000000" ')
self.f.write('fo:border-top="0.0346inch solid #000000" ')
self.f.write('fo:border-bottom="0.0346inch solid #000000" ')
self.f.write('fo:border-left="0.0346inch solid #000000" ')
self.f.write('fo:border-right="0.0346inch solid #000000" ')
self.f.write('fo:padding="0.0071inch" ')
self.f.write('fo:padding-top="0.0071inch" ')
self.f.write('fo:padding-bottom="0.0071inch" ')
self.f.write('fo:padding-left="0.0071inch" ')
self.f.write('fo:padding-right="0.0071inch" ')
self.f.write('fo:background-color="#c0c0c0"/>\n')
self.f.write('</style:header-style>\n')
self.f.write('<style:footer-style>\n')
self.f.write('<style:header-footer-properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-top="0.0984inch" ')
self.f.write('fo:border="0.0346inch solid #000000" ')
self.f.write('fo:border-top="0.0346inch solid #000000" ')
self.f.write('fo:border-bottom="0.0346inch solid #000000" ')
self.f.write('fo:border-left="0.0346inch solid #000000" ')
self.f.write('fo:border-right="0.0346inch solid #000000" ')
self.f.write('fo:padding="0.0071inch" ')
self.f.write('fo:padding-top="0.0071inch" ')
self.f.write('fo:padding-bottom="0.0071inch" ')
self.f.write('fo:padding-left="0.0071inch" ')
self.f.write('fo:padding-right="0.0071inch" ')
self.f.write('fo:background-color="#c0c0c0"/>\n')
self.f.write('</style:footer-style>\n')
self.f.write('</style:page-layout>\n')
self.f.write('</office:automatic-styles>\n')
self.f.write('<office:master-styles>\n')
self.f.write('<style:master-page style:name="Default" ')
self.f.write('style:page-layout-name="pm1" >\n')
self.f.write('<style:header>\n')
self.f.write('<text:p><text:sheet-name>???</text:sheet-name></text:p>\n')
self.f.write('</style:header>\n')
self.f.write('<style:footer>\n')
self.f.write('<text:p>Page <text:page-number>1</text:page-number></text:p>\n')
self.f.write('</style:footer>\n')
self.f.write('</style:master-page>\n')
self.f.write('<style:master-page style:name="Report" ')
self.f.write('style:page-layout-name="pm2" >\n')
self.f.write('<style:header>\n')
self.f.write('<style:region-left>\n')
self.f.write('<text:p><text:sheet-name>???</text:sheet-name> ')
self.f.write('(<text:file-name>???</text:file-name>)</text:p>\n')
self.f.write('</style:region-left>\n')
self.f.write('<style:region-right>\n')
self.f.write('<text:p><text:date style:data-style-name="N2" ')
self.f.write('text:date-value="2001-05-16">05/16/2001</text:date>, ')
self.f.write('<text:time>10:53:17</text:time></text:p>\n')
self.f.write('</style:region-right>\n')
self.f.write('</style:header>\n')
self.f.write('<style:footer>\n')
self.f.write('<text:p>Page <text:page-number>1</text:page-number> / ')
self.f.write('<text:page-count>99</text:page-count></text:p>\n')
self.f.write('</style:footer>\n')
self.f.write('</style:master-page>\n')
self.f.write('</office:master-styles>\n')
self.f.write('</office:document-styles>\n')
self.f.close()
def start_page(self, name,style_name):
table = self.table_styles[style_name]
self.f.write('<table:table table:name="')
self.f.write(name)
self.f.write('" table:style-name="')
self.f.write(style_name)
self.f.write('">\n')
for col in range(0,table.get_columns()):
self.f.write('<table:table-column table:style-name="')
self.f.write(style_name + '_' + str(col) +'"/>\n')
def end_page(self):
self.f.write('</table:table>\n')
def write_text(self,text,mark=None):
if text == "":
return
if self.content == 0:
self.f.write('<text:p>')
self.content = 1
text = text.replace('&','&amp;') # Must be first
text = text.replace('<','&lt;')
text = text.replace('>','&gt;')
text = text.replace('\t','<text:tab-stop/>')
text = text.replace('\n','<text:line-break/>')
self.f.write(unicode(text))
def _write_manifest(self):
self.manifest_xml = tempfile.mktemp()
try:
self.f = open(self.manifest_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.manifest_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.manifest_xml)
self.f = open(self.manifest_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<manifest:manifest ')
self.f.write('xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">')
self.f.write('<manifest:file-entry ')
self.f.write('manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" ')
self.f.write('manifest:full-path="/"/>')
self.f.write('<manifest:file-entry manifest:media-type="" ')
self.f.write('manifest:full-path="Pictures/"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="content.xml"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="styles.xml"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="meta.xml"/>')
#self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
#self.f.write('manifest:full-path="settings.xml"/>')
self.f.write('</manifest:manifest>\n')
self.f.close()
def _write_meta_file(self):
self.meta_xml = tempfile.mktemp()
try:
self.f = open(self.meta_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.meta_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.meta_xml)
self.f = open(self.meta_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-meta ')
self.f.write('xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
self.f.write('xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ')
self.f.write('office:class="text" office:version="1.0">\n');
self.f.write('<office:meta>\n')
self.f.write('<meta:generator>')
self.f.write(const.PROGRAM_NAME + ' ' + const.VERSION)
self.f.write('</meta:generator>\n')
self.f.write('<meta:initial-creator>')
self.f.write(self.name)
self.f.write('</meta:initial-creator>\n')
self.f.write('<meta:creation-date>')
self.f.write(self.time)
self.f.write('</meta:creation-date>\n')
self.f.write('<dc:creator>')
self.f.write(self.name)
self.f.write('</dc:creator>\n')
self.f.write('<dc:date>')
self.f.write(self.time)
self.f.write('</dc:date>\n')
self.f.write('<meta:print-date>0-00-00T00:00:00</meta:print-date>\n')
self.f.write('<dc:language>en-US</dc:language>\n')
self.f.write('<meta:editing-cycles>1</meta:editing-cycles>\n')
self.f.write('<meta:editing-duration>PT0S</meta:editing-duration>\n')
self.f.write('<meta:user-defined meta:name="Info 0"/>\n')
self.f.write('<meta:user-defined meta:name="Info 1"/>\n')
self.f.write('<meta:user-defined meta:name="Info 2"/>\n')
self.f.write('<meta:user-defined meta:name="Info 3"/>\n')
self.f.write('</office:meta>\n')
self.f.write('</office:document-meta>\n')
self.f.close()
def _write_mimetype_file(self):
self.mimetype = tempfile.mktemp()
try:
self.f = open(self.mimetype,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.mimetype, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.mimetype)
self.f = open(self.mimetype,"w")
self.f.write('application/vnd.oasis.opendocument.spreadsheet')
self.f.close()

View File

@ -1,479 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id:OpenSpreadSheet.py 9912 2008-01-22 09:17:46Z acraphae $
#-------------------------------------------------------------------------
#
# Standard Python Modules
#
#-------------------------------------------------------------------------
import os
import tempfile
import zipfile
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.plug.docgen import FONT_SERIF
from SpreadSheetDoc import SpreadSheetDoc
import const
import Errors
#-------------------------------------------------------------------------
#
# OpenSpreadSheet
#
#-------------------------------------------------------------------------
class OpenSpreadSheet(SpreadSheetDoc):
def __init__(self,type, orientation):
SpreadSheetDoc.__init__(self,type, orientation)
self.f = None
self.filename = None
self.level = 0
self.time = "0000-00-00T00:00:00"
def open(self,filename):
import time
t = time.localtime(time.time())
self.time = "%04d-%02d-%02dT%02d:%02d:%02d" % t[:6]
if filename[-4:] != ".sxc":
self.filename = filename + ".sxc"
else:
self.filename = filename
try:
self.content_xml = tempfile.mktemp()
self.f = open(self.content_xml,"wb")
except IOError,msg:
raise Errors.ReportError(_("Could not create %s") % self.content_xml, msg)
except:
raise Errors.ReportError(_("Could not create %s") % self.content_xml)
self.f = open(self.content_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-content ')
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
self.f.write('xmlns:style="http://openoffice.org/2000/style" ')
self.f.write('xmlns:text="http://openoffice.org/2000/text" ')
self.f.write('xmlns:table="http://openoffice.org/2000/table" ')
self.f.write('xmlns:draw="http://openoffice.org/2000/drawing" ')
self.f.write('xmlns:fo="http://www.w3.org/1999/XSL/Format" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:number="http://openoffice.org/2000/datastyle" ')
self.f.write('xmlns:svg="http://www.w3.org/2000/svg" ')
self.f.write('xmlns:chart="http://openoffice.org/2000/chart" ')
self.f.write('xmlns:dr3d="http://openoffice.org/2000/dr3d" ')
self.f.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
self.f.write('xmlns:form="http://openoffice.org/2000/form" ')
self.f.write('xmlns:script="http://openoffice.org/2000/script" ')
self.f.write('office:class="spreadsheet" office:version="0.9">\n')
self.f.write('<office:script/>\n')
self.f.write('<office:font-decls>\n')
self.f.write('<style:font-decl style:name="Times New Roman" ')
self.f.write('fo:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('<style:font-decl style:name="Arial" ')
self.f.write('fo:font-family="Arial" ')
self.f.write('style:font-family-generic="swiss" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('</office:font-decls>\n')
self.f.write('<office:automatic-styles>\n')
for key, table in self.table_styles.iteritems():
self.f.write('<style:style style:name="')
self.f.write(key)
self.f.write('" style:family="table">\n')
self.f.write('<style:properties table:display="true" ')
self.f.write('table:page-style-name="Default"/>\n')
self.f.write('</style:style>\n')
for index in range(0,table.get_columns()):
self.f.write('<style:style style:name="')
self.f.write(key + '_' + str(index))
self.f.write('" style:family="table-column">\n')
self.f.write('<style:properties fo:break-before="auto" ')
self.f.write('style:column-width="%.3fcm"/>\n' % table.get_column_width(index))
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="ro1" style:family="table-row">\n')
self.f.write('<style:properties fo:break-before="auto"/>\n')
self.f.write('</style:style>\n')
for key, style in self.style_list.iteritems():
font = style.get_font()
self.f.write('<style:style style:name="')
self.f.write(key)
self.f.write('" style:family="table-cell" ')
self.f.write('style:parent-style-name="Default">\n')
self.f.write('<style:properties ')
self.f.write('fo:color="#%02x%02x%02x" ' % font.get_color())
bgcolor = style.get_background_color()
self.f.write('fo:background-color="#%02x%02x%02x" ' % bgcolor)
self.f.write('fo:padding-bottom="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-top="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-right="%.3fcm" ' % style.get_padding())
self.f.write('fo:padding-left="%.3fcm" ' % style.get_padding())
self.f.write('style:text-outline="false" ')
self.f.write('style:text-crossing-out="none" ')
if font.get_type_face() == FONT_SERIF:
self.f.write('style:font-name="Times New Roman" ')
else:
self.f.write('style:font-name="Arial" ')
self.f.write('fo:font-size="%dpt" ' % font.get_size())
if font.get_italic():
self.f.write('fo:font-style="italic" ')
else:
self.f.write('fo:font-style="normal" ')
self.f.write('fo:text-shadow="none" ')
self.f.write('style:text-underline="none" ')
if font.get_bold():
self.f.write('fo:font-weight="bold"/>\n')
else:
self.f.write('fo:font-weight="normal"/>\n')
self.f.write('</style:style>\n')
self.f.write('</office:automatic-styles>\n')
self.f.write('<office:body>\n')
self.f.write('<table:calculation-settings>\n')
self.f.write('<table:iteration table:maximum-difference="0.001"/>\n')
self.f.write('</table:calculation-settings>\n')
def close(self):
self.f.write('</office:body>\n')
self.f.write('</office:document-content>\n')
self.f.close()
self._write_styles_file()
self._write_manifest()
self._write_meta_file()
self._write_zip()
def start_row(self):
self.f.write('<table:table-row table:style-name="')
self.f.write('ro1')
self.f.write('">\n')
def end_row(self):
self.f.write('</table:table-row>\n')
def start_cell(self,style_name,span=1):
self.content = 0
self.span = span
self.f.write('<table:table-cell table:style-name="')
self.f.write(style_name)
self.f.write('" table:value-type="string"')
if span > 1:
self.f.write(' table:number-columns-spanned="' + str(span) + '">\n')
else:
self.f.write('>\n')
def end_cell(self):
if self.content == 0:
self.f.write('<text:p/>\n')
else:
self.f.write('</text:p>\n')
self.f.write('</table:table-cell>\n')
for col in range(1,self.span):
self.f.write('<table:covered-table-cell/>\n')
def _write_zip(self):
try:
the_file = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED)
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
raise Errors.ReportError(errmsg)
except:
raise Errors.ReportError(_("Could not create %s") % self.filename)
the_file.write(self.manifest_xml,str("META-INF/manifest.xml"))
the_file.write(self.content_xml,str("content.xml"))
the_file.write(self.meta_xml,str("meta.xml"))
the_file.write(self.styles_xml,str("styles.xml"))
the_file.close()
os.unlink(self.manifest_xml)
os.unlink(self.content_xml)
os.unlink(self.meta_xml)
os.unlink(self.styles_xml)
def _write_styles_file(self):
self.styles_xml = tempfile.mktemp()
try:
self.f = open(self.styles_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.styles_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.styles_xml)
self.f = open(self.styles_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-styles ')
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
self.f.write('xmlns:style="http://openoffice.org/2000/style" ')
self.f.write('xmlns:text="http://openoffice.org/2000/text" ')
self.f.write('xmlns:table="http://openoffice.org/2000/table" ')
self.f.write('xmlns:draw="http://openoffice.org/2000/drawing" ')
self.f.write('xmlns:fo="http://www.w3.org/1999/XSL/Format" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:number="http://openoffice.org/2000/datastyle" ')
self.f.write('xmlns:svg="http://www.w3.org/2000/svg" ')
self.f.write('xmlns:chart="http://openoffice.org/2000/chart" ')
self.f.write('xmlns:dr3d="http://openoffice.org/2000/dr3d" ')
self.f.write('xmlns:math="http://www.w3.org/1998/Math/MathML" ')
self.f.write('xmlns:form="http://openoffice.org/2000/form" ')
self.f.write('xmlns:script="http://openoffice.org/2000/script" ')
self.f.write('office:class="spreadsheet" office:version="0.9">\n')
self.f.write('<office:font-decls>\n')
self.f.write('<style:font-decl style:name="Times New Roman" ')
self.f.write('fo:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('<style:font-decl style:name="Arial" ')
self.f.write('fo:font-family="Arial" ')
self.f.write('style:font-family-generic="swiss" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('</office:font-decls>\n')
self.f.write('<office:styles>\n')
self.f.write('<style:default-style style:family="table-cell">\n')
self.f.write('<style:properties style:decimal-places="2" ')
self.f.write('style:font-name="Arial" ')
self.f.write('style:tab-stop-distance="0.2835inch"/>\n')
self.f.write('</style:default-style>\n')
self.f.write('<style:style style:name="Default" ')
self.f.write('style:family="table-cell" ')
self.f.write('style:data-style-name="N0"/>\n')
self.f.write('<style:default-style style:family="graphics">\n')
self.f.write('<style:properties fo:color="#000000" ')
self.f.write('fo:font-family="&apos;Times New Roman&apos;" ')
self.f.write('style:font-style-name="" ')
self.f.write('style:font-family-generic="roman" ')
self.f.write('style:font-pitch="variable" ')
self.f.write('fo:font-size="12pt" ')
self.f.write('fo:language="none" ')
self.f.write('fo:country="none" ')
self.f.write('style:text-autospace="ideograph-alpha" ')
self.f.write('style:punctuation-wrap="simple" ')
self.f.write('style:line-break="strict"/>\n')
self.f.write('</style:default-style>\n')
self.f.write('<style:style style:name="Standard" ')
self.f.write('style:family="paragraph" style:class="text"/>\n')
self.f.write('<office:automatic-styles>\n')
self.f.write('<style:page-master style:name="pm1">\n')
self.f.write('<style:header-style>\n')
self.f.write('<style:properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-bottom="0.0984inch"/>\n')
self.f.write('</style:header-style>\n')
self.f.write('<style:footer-style>\n')
self.f.write('<style:properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-top="0.0984inch"/>\n')
self.f.write('</style:footer-style>\n')
self.f.write('</style:page-master>\n')
self.f.write('<style:page-master style:name="pm2">\n')
self.f.write('<style:header-style>\n')
self.f.write('<style:properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-bottom="0.0984inch" ')
self.f.write('fo:border="0.0346inch solid #000000" ')
self.f.write('fo:border-top="0.0346inch solid #000000" ')
self.f.write('fo:border-bottom="0.0346inch solid #000000" ')
self.f.write('fo:border-left="0.0346inch solid #000000" ')
self.f.write('fo:border-right="0.0346inch solid #000000" ')
self.f.write('fo:padding="0.0071inch" ')
self.f.write('fo:padding-top="0.0071inch" ')
self.f.write('fo:padding-bottom="0.0071inch" ')
self.f.write('fo:padding-left="0.0071inch" ')
self.f.write('fo:padding-right="0.0071inch" ')
self.f.write('fo:background-color="#c0c0c0"/>\n')
self.f.write('</style:header-style>\n')
self.f.write('<style:footer-style>\n')
self.f.write('<style:properties fo:min-height="0.2957inch" ')
self.f.write('fo:margin-left="0inch" ')
self.f.write('fo:margin-right="0inch" ')
self.f.write('fo:margin-top="0.0984inch" ')
self.f.write('fo:border="0.0346inch solid #000000" ')
self.f.write('fo:border-top="0.0346inch solid #000000" ')
self.f.write('fo:border-bottom="0.0346inch solid #000000" ')
self.f.write('fo:border-left="0.0346inch solid #000000" ')
self.f.write('fo:border-right="0.0346inch solid #000000" ')
self.f.write('fo:padding="0.0071inch" ')
self.f.write('fo:padding-top="0.0071inch" ')
self.f.write('fo:padding-bottom="0.0071inch" ')
self.f.write('fo:padding-left="0.0071inch" ')
self.f.write('fo:padding-right="0.0071inch" ')
self.f.write('fo:background-color="#c0c0c0"/>\n')
self.f.write('</style:footer-style>\n')
self.f.write('</style:page-master>\n')
self.f.write('</office:automatic-styles>\n')
self.f.write('<office:master-styles>\n')
self.f.write('<style:master-page style:name="Default" ')
self.f.write('style:page-master-name="pm1" ')
self.f.write('style:next-style-name="">\n')
self.f.write('<style:header>\n')
self.f.write('<text:p><text:sheet-name>???</text:sheet-name></text:p>\n')
self.f.write('</style:header>\n')
self.f.write('<style:footer>\n')
self.f.write('<text:p>Page <text:page-number>1</text:page-number></text:p>\n')
self.f.write('</style:footer>\n')
self.f.write('</style:master-page>\n')
self.f.write('<style:master-page style:name="Report" ')
self.f.write('style:page-master-name="pm2" ')
self.f.write('style:next-style-name="">\n')
self.f.write('<style:header>\n')
self.f.write('<style:region-left>\n')
self.f.write('<text:p><text:sheet-name>???</text:sheet-name> ')
self.f.write('(<text:file-name>???</text:file-name>)</text:p>\n')
self.f.write('</style:region-left>\n')
self.f.write('<style:region-right>\n')
self.f.write('<text:p><text:date style:data-style-name="N2" ')
self.f.write('text:date-value="2001-05-16">05/16/2001</text:date>, ')
self.f.write('<text:time>10:53:17</text:time></text:p>\n')
self.f.write('</style:region-right>\n')
self.f.write('</style:header>\n')
self.f.write('<style:footer>\n')
self.f.write('<text:p>Page <text:page-number>1</text:page-number> / ')
self.f.write('<text:page-count>99</text:page-count></text:p>\n')
self.f.write('</style:footer>\n')
self.f.write('</style:master-page>\n')
self.f.write('</office:master-styles>\n')
self.f.write('</office:styles>\n')
self.f.write('</office:document-styles>\n')
self.f.close()
def start_page(self, name,style_name):
table = self.table_styles[style_name]
self.f.write('<table:table table:name="')
self.f.write(name)
self.f.write('" table:style-name="')
self.f.write(style_name)
self.f.write('">\n')
for col in range(0,table.get_columns()):
self.f.write('<table:table-column table:style-name="')
self.f.write(style_name + '_' + str(col) +'"/>\n')
def end_page(self):
self.f.write('</table:table>\n')
def write_text(self,text,mark=None):
if text == "":
return
if self.content == 0:
self.f.write('<text:p>')
self.content = 1
text = text.replace('&','&amp;') # Must be first
text = text.replace('<','&lt;')
text = text.replace('>','&gt;')
text = text.replace('\t','<text:tab-stop/>')
text = text.replace('\n','<text:line-break/>')
self.f.write(unicode(text))
def _write_manifest(self):
self.manifest_xml = tempfile.mktemp()
try:
self.f = open(self.manifest_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.manifest_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.manifest_xml)
self.f = open(self.manifest_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<manifest:manifest ')
self.f.write('xmlns:manifest="http://openoffice.org/2001/manifest">')
self.f.write('<manifest:file-entry ')
self.f.write('manifest:media-type="application/vnd.sun.xml.calc" ')
self.f.write('manifest:full-path="/"/>')
self.f.write('<manifest:file-entry manifest:media-type="" ')
self.f.write('manifest:full-path="Pictures/"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="content.xml"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="styles.xml"/>')
self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
self.f.write('manifest:full-path="meta.xml"/>')
#self.f.write('<manifest:file-entry manifest:media-type="text/xml" ')
#self.f.write('manifest:full-path="settings.xml"/>')
self.f.write('</manifest:manifest>\n')
self.f.close()
def _write_meta_file(self):
self.meta_xml = tempfile.mktemp()
try:
self.f = open(self.meta_xml,"wb")
except IOError,msg:
errmsg = "%s\n%s" % (_("Could not create %s") % self.meta_xml, msg)
raise Errors.ReportError(errmsg)
except:
pass
raise Errors.ReportError(_("Could not create %s") % self.meta_xml)
self.f = open(self.meta_xml,"w")
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
self.f.write('<office:document-meta ')
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
self.f.write('xmlns:xlink="http://www.w3.org/1999/xlink" ')
self.f.write('xmlns:dc="http://purl.org/dc/elements/1.1/" ')
self.f.write('xmlns:meta="http://openoffice.org/2000/meta" ')
self.f.write('office:class="text" office:version="0.9">\n');
self.f.write('<office:meta>\n')
self.f.write('<meta:generator>')
self.f.write(const.PROGRAM_NAME + ' ' + const.VERSION)
self.f.write('</meta:generator>\n')
self.f.write('<meta:initial-creator>')
self.f.write(self.name)
self.f.write('</meta:initial-creator>\n')
self.f.write('<meta:creation-date>')
self.f.write(self.time)
self.f.write('</meta:creation-date>\n')
self.f.write('<dc:creator>')
self.f.write(self.name)
self.f.write('</dc:creator>\n')
self.f.write('<dc:date>')
self.f.write(self.time)
self.f.write('</dc:date>\n')
self.f.write('<meta:print-date>0-00-00T00:00:00</meta:print-date>\n')
self.f.write('<dc:language>en-US</dc:language>\n')
self.f.write('<meta:editing-cycles>1</meta:editing-cycles>\n')
self.f.write('<meta:editing-duration>PT0S</meta:editing-duration>\n')
self.f.write('<meta:user-defined meta:name="Info 0"/>\n')
self.f.write('<meta:user-defined meta:name="Info 1"/>\n')
self.f.write('<meta:user-defined meta:name="Info 2"/>\n')
self.f.write('<meta:user-defined meta:name="Info 3"/>\n')
self.f.write('</office:meta>\n')
self.f.write('</office:document-meta>\n')
self.f.close()

View File

@ -1,117 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from gen.plug.docgen import FontStyle, ParagraphStyle, TableStyle,\
TableCellStyle,PAPER_PORTRAIT
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class SpreadSheetDoc(object):
def __init__(self,type, orientation=PAPER_PORTRAIT):
self.orientation = orientation
if orientation == PAPER_PORTRAIT:
self.width = type.get_width()
self.height = type.get_height()
else:
self.width = type.get_height()
self.height = type.get_width()
self.tmargin = 2.54
self.bmargin = 2.54
self.lmargin = 2.54
self.rmargin = 2.54
self.font = FontStyle()
self.actfont = self.font
self.style_list = {}
self.table_styles = {}
self.cell_styles = {}
self.name = ""
def get_usable_width(self):
return self.width - (self.rmargin + self.lmargin)
def get_usable_height(self):
return self.height - (self.tmargin + self.bmargin)
def creator(self, name):
self.name = name
def add_style(self, name,style):
self.style_list[name] = ParagraphStyle(style)
def add_table_style(self, name,style):
self.table_styles[name] = TableStyle(style)
def add_cell_style(self, name,style):
self.cell_styles[name] = TableCellStyle(style)
def change_font(self,font):
self.actfont = FontStyle(font)
def restore_font(self):
self.actfont = self.font
def get_default_font(self):
return self.font
def get_active_font(self):
return self.actfont
def open(self,filename):
pass
def close(self):
pass
def start_page(self, name,style_name):
pass
def end_page(self):
pass
def start_paragraph(self,style_name):
pass
def end_paragraph(self):
pass
def start_table(self, name,style_name):
pass
def end_table(self):
pass
def start_row(self):
pass
def end_row(self):
pass
def start_cell(self,style_name,span=1):
pass
def end_cell(self):
pass
def write_text(self,text,mark=None):
pass

View File

@ -23,5 +23,4 @@
from TabbedDoc import TabbedDoc
from ODSTab import ODSTab
from TextBufDoc import TextBufDoc
from CSVTab import CSVTab
from SpreadSheetDoc import SpreadSheetDoc
from CSVTab import CSVTab