2007-02-05 Don Allingham <don@gramps-project.org>

* src/DataViews/_MediaView.py: view export support
	* src/DataViews/_RepositoryView.py: view export support
	* src/DataViews/_SourceView.py: view export support
	* src/DataViews/_EventView.py: view export support
	* src/DataViews/_FamilyList.py: view export support
	* src/DataViews/_PlaceView.py: view export support
	* src/DataViews/_PersonView.py: view export support
	* src/ViewManager.py: view export support
	* src/plugins/EventCmp.py: use new format
	* src/PageView.py: view export support
	* src/docgen/TabbedDoc.py: base class for tabular format
	* src/docgen/ODSTab.py: Open Document format for tabular format
	* src/docgen/CSVTab.py: Comma Separated Value format for tabular format



svn: r8060
This commit is contained in:
Don Allingham 2007-02-06 05:19:16 +00:00
parent 4dac15ad08
commit abf15c7712
15 changed files with 824 additions and 46 deletions

View File

@ -1,3 +1,18 @@
2007-02-05 Don Allingham <don@gramps-project.org>
* src/DataViews/_MediaView.py: view export support
* src/DataViews/_RepositoryView.py: view export support
* src/DataViews/_SourceView.py: view export support
* src/DataViews/_EventView.py: view export support
* src/DataViews/_FamilyList.py: view export support
* src/DataViews/_PlaceView.py: view export support
* src/DataViews/_PersonView.py: view export support
* src/ViewManager.py: view export support
* src/plugins/EventCmp.py: use new format
* src/PageView.py: view export support
* src/docgen/TabbedDoc.py: base class for tabular format
* src/docgen/ODSTab.py: Open Document format for tabular format
* src/docgen/CSVTab.py: Comma Separated Value format for tabular format
2007-02-05 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/GrampsDb/_GrampsBSDDB.py: load/save db owner info
* src/GrampsDb/_DbUtils.py (db_copy): copy also db owner

4
TODO
View File

@ -12,6 +12,10 @@
necessarily need multiple notes. Determine which ones should and
shouldn't.
* Split views
* Export to spreadsheet, print, CSV of views
* Date calculator. See
http://sourceforge.net/mailarchive/forum.php?thread_id=3252078&forum_id=1993

View File

@ -136,6 +136,11 @@ class EventView(PageView.ListView):
<menuitem action="EditBook"/>
</placeholder>
</menu>
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="EditMenu">
<placeholder name="CommonEdit">
<menuitem action="Add"/>

View File

@ -143,6 +143,11 @@ class FamilyListView(PageView.ListView):
def ui_definition(self):
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="EditMenu">
<placeholder name="CommonEdit">
<menuitem action="Add"/>

View File

@ -279,6 +279,11 @@ class MediaView(PageView.ListView):
def ui_definition(self):
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="EditMenu">
<placeholder name="CommonEdit">
<menuitem action="Add"/>

View File

@ -163,6 +163,7 @@ class PersonView(PageView.PersonNavView):
self.cmp_merge),
('FastMerge', None, _('_Fast merge'), None, None,
self.fast_merge),
('ExportTab', None, _('Export view'), None, None, self.export),
])
self.add_action_group(self.edit_action)
@ -346,6 +347,11 @@ class PersonView(PageView.PersonNavView):
"""
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="BookMenu">
<placeholder name="AddEditBook">
<menuitem action="AddBook"/>
@ -850,3 +856,92 @@ class PersonView(PageView.PersonNavView):
self.uistate.push_message(self.dbstate,
_("Delete selected person"))
def export(self, obj):
chooser = gtk.FileChooserDialog(
_("Export view as spreadsheet"),
self.uistate.window,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_do_overwrite_confirmation(True)
combobox = gtk.combo_box_new_text()
label = gtk.Label(_("Format:"))
label.set_alignment(1.0, 0.5)
box = gtk.HBox()
box.pack_start(label, True, True, padding=12)
box.pack_start(combobox, False, False)
combobox.append_text(_('CSV'))
combobox.append_text(_('Open Document Spreadsheet'))
combobox.set_active(0)
box.show_all()
chooser.set_extra_widget(box)
while True:
value = chooser.run()
fn = chooser.get_filename()
fl = combobox.get_active()
if value == gtk.RESPONSE_OK:
if fn:
chooser.destroy()
break
else:
chooser.destroy()
return
self.write_tabbed_file(fn, fl)
def write_tabbed_file(self, name, type):
"""
Writes a tabbed file to the specified name. The output file type is determined
by the type variable.
"""
# Select the correct output format
if type == 0:
from CSVTab import CSVTab as tabgen
else:
from ODSTab import ODSTab as tabgen
# build the active data columns, prepending 0 for the name column, then
# derive the column names fromt the active data columns
data_cols = [0] + [pair[1] \
for pair in self.dbstate.db.get_person_column_order() \
if pair[0]]
cnames = [column_names[i] for i in data_cols]
# create the output tabbed document, and open it
ofile = tabgen(len(cnames))
ofile.open(name)
# start the current page
ofile.start_page()
# open the header row, write the column names, and close the row
ofile.start_row()
for name in cnames:
ofile.write_cell(name)
ofile.end_row()
# The tree model works different from the rest of the list-based models,
# since the iterator method only works on top level nodes. So we must
# loop through based off of paths
path = (0,)
node = self.model.on_get_iter(path)
while node:
real_iter = self.model.get_iter(path)
for subindex in range(0, self.model.iter_n_children(real_iter)):
subpath = ((path[0],subindex))
row = self.model[subpath]
ofile.start_row()
for index in data_cols:
ofile.write_cell(row[index])
ofile.end_row()
node = self.model.on_iter_next(node)
path = (path[0]+1,)
ofile.end_page()
ofile.close()

View File

@ -174,6 +174,11 @@ class PlaceView(PageView.ListView):
def ui_definition(self):
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="BookMenu">
<placeholder name="AddEditBook">
<menuitem action="AddBook"/>

View File

@ -145,6 +145,11 @@ class RepositoryView(PageView.ListView):
def ui_definition(self):
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="BookMenu">
<placeholder name="AddEditBook">
<menuitem action="AddBook"/>

View File

@ -140,6 +140,11 @@ class SourceView(PageView.ListView):
def ui_definition(self):
return '''<ui>
<menubar name="MenuBar">
<menu action="FileMenu">
<placeholder name="LocalExport">
<menuitem action="ExportTab"/>
</placeholder>
</menu>
<menu action="BookMenu">
<placeholder name="AddEditBook">
<menuitem action="AddBook"/>

View File

@ -755,13 +755,6 @@ class ListView(BookMarkView):
for sig in self.signal_map:
db.connect(sig, self.signal_map[sig])
# if Config.get(Config.FILTER):
# search = EMPTY_SEARCH
# else:
# search = self.search_bar.get_value()
# self.model = self.make_model(self.dbstate.db, 0, search=search)
# self.list.set_model(self.model)
self.build_columns()
self.bookmarks.update_bookmarks(self.get_bookmarks())
if self.active:
@ -811,6 +804,7 @@ class ListView(BookMarkView):
self.DEL_MSG, self.remove),
('ColumnEdit', gtk.STOCK_PROPERTIES, _('_Column Editor'),
None, None, self.column_editor),
('ExportTab', None, _('Export view'), None, None, self.export),
])
self.add_action_group(self.edit_action)
@ -853,3 +847,67 @@ class ListView(BookMarkView):
def key_delete(self):
self.remove(None)
def export(self, obj):
chooser = gtk.FileChooserDialog(
_("Export view as spreadsheet"),
self.uistate.window,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_do_overwrite_confirmation(True)
combobox = gtk.combo_box_new_text()
label = gtk.Label(_("Format:"))
label.set_alignment(1.0, 0.5)
box = gtk.HBox()
box.pack_start(label, True, True, padding=12)
box.pack_start(combobox, False, False)
combobox.append_text(_('CSV'))
combobox.append_text(_('OpenOffice Spreadsheet'))
combobox.set_active(0)
box.show_all()
chooser.set_extra_widget(box)
while True:
value = chooser.run()
fn = chooser.get_filename()
fl = combobox.get_active()
if value == gtk.RESPONSE_OK:
if fn:
chooser.destroy()
break
else:
chooser.destroy()
return
self.write_tabbed_file(fn, fl)
def write_tabbed_file(self, name, type):
if type == 0:
from CSVTab import CSVTab as tabgen
else:
from ODSTab import ODSTab as tabgen
data_cols = [pair[1] for pair in self.column_order() if pair[0]]
column_names = [self.colinfo[i] for i in data_cols]
o = tabgen(len(column_names))
o.open(name)
o.start_page()
o.start_row()
for name in column_names:
o.write_cell(name)
o.end_row()
for row in self.model:
o.start_row()
for index in data_cols:
o.write_cell(row[index])
o.end_row()
o.end_page()
o.close()

View File

@ -105,6 +105,7 @@ uidefault = '''<ui>
<menuitem action="Import"/>
<menuitem action="SaveAs"/>
<menuitem action="Export"/>
<placeholder name="LocalExport"/>
<separator/>
<menuitem action="Abandon"/>
<menuitem action="Quit"/>

81
src/docgen/CSVTab.py Normal file
View File

@ -0,0 +1,81 @@
#
# 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:
import os
import csv
import codecs
from gettext import gettext as _
import TabbedDoc
class CSVTab(TabbedDoc.TabbedDoc):
def __init__(self, columns):
TabbedDoc.TabbedDoc.__init__(self, columns)
self.filename = None
self.f = None
self.dlist = []
self.writer = None
def open(self, filename):
if filename[-4:] != ".csv":
self.filename = filename + ".csv"
else:
self.filename = filename
self.f = open(filename, "wb")
self.writer = csv.writer(self.f)
def close(self):
assert(self.f)
self.f.close()
def start_row(self):
self.dlist = []
def end_row(self):
self.writer.writerow(self.dlist)
def write_cell(self, text):
self.dlist.append(text)
def start_page(self):
pass
def end_page(self):
pass
if __name__ == "__main__":
file = CSVTab(2, 3)
file.open("test.csv")
file.start_page()
for i in [ ('one', 'two', 'three'), ('fo"ur', 'fi,ve', 'six') ]:
file.start_row()
for j in i:
file.write_cell(j)
file.end_row()
file.end_page()
file.close()

460
src/docgen/ODSTab.py Normal file
View File

@ -0,0 +1,460 @@
#
# 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 TabbedDoc import *
import const
import Errors
#-------------------------------------------------------------------------
#
# OpenSpreadSheet
#
#-------------------------------------------------------------------------
class ODSTab(TabbedDoc):
def __init__(self, columns):
TabbedDoc.__init__(self, columns)
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[0],t[1],t[2],t[3],t[4],t[5])
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="Nimbus Sans L" ')
self.f.write('svg:font-family="\'Nimbus Sans L\'" style:font-family-generic="swiss" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('<style:font-face style:name="DejaVu Sans" ')
self.f.write('svg:font-family="\'DejaVu Sans\'" style:font-family-generic="system" ')
self.f.write('style:font-pitch="variable"/>\n')
self.f.write('</office:font-face-decls>\n')
self.f.write('<office:automatic-styles>\n')
self.f.write('<style:style style:name="co1" style:family="table-column">\n')
self.f.write('<style:table-column-properties fo:break-before="auto" style:column-width="3cm"/>\n')
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 style:row-height="0.189in" ')
self.f.write('fo:break-before="auto" style:use-optimal-row-height="true"/>\n')
self.f.write('</style:style>\n')
self.f.write('<style:style style:name="ta1" style:family="table" ')
self.f.write('style:master-page-name="Default">\n')
self.f.write('<style:table-properties table:display="true" style:writing-mode="lr-tb"/>\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 write_cell(self, text):
self.f.write('<table:table-cell office:value-type="string">')
self.f.write('>\n')
self.f.write('<text:p>')
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))
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):
self.f.write('<table:table table:name="ta1">')
for col in range(0,self.columns):
self.f.write('<table:table-column table:style-name="co1"/>\n')
def end_page(self):
self.f.write('</table:table>\n')
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()
if __name__ == "__main__":
file = ODSTab(3)
file.open("test")
file.start_page()
for i in [ ('one', 'two', 'three'), ('fo"ur', 'fi,ve', 'six') ]:
file.start_row()
for j in i:
file.write_cell(j)
file.end_row()
file.end_page()
file.close()

65
src/docgen/TabbedDoc.py Normal file
View File

@ -0,0 +1,65 @@
#
# 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
#
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class TabbedDoc:
def __init__(self, columns):
self.columns = columns
self.name = ""
def creator(self,name):
self.name = name
def open(self,filename):
pass
def close(self):
pass
def start_page(self):
pass
def end_page(self):
pass
def start_paragraph(self):
pass
def end_paragraph(self):
pass
def start_table(self):
pass
def end_table(self):
pass
def start_row(self):
pass
def end_row(self):
pass
def write_cell(self, text):
pass

View File

@ -47,8 +47,7 @@ import gtk.glade
from Filters import GenericFilter, build_filter_menu, Rules
import Sort
import Utils
import BaseDoc
import ODSDoc
import ODSTab
import const
import Errors
import DateHandler
@ -73,33 +72,8 @@ class TableReport:
self.doc = doc
def initialize(self,cols):
t = BaseDoc.TableStyle()
t.set_columns(cols)
for index in range(0,cols):
t.set_column_width(index,4)
t.set_column_width(1,1)
self.doc.add_table_style("mytbl",t)
f = BaseDoc.FontStyle()
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
f.set_size(12)
f.set_bold(1)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_background_color((0xcc,0xff,0xff))
p.set_padding(0.1)
self.doc.add_style("head",p)
f = BaseDoc.FontStyle()
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
f.set_size(10)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
self.doc.add_style("data",p)
self.doc.open(self.filename)
self.doc.start_page("Page 1","mytbl")
self.doc.start_page()
def finalize(self):
self.doc.end_page()
@ -110,11 +84,8 @@ class TableReport:
index = -1
for item in data:
index += 1
if index in skip_columns:
continue
self.doc.start_cell("data")
self.doc.write_text(item)
self.doc.end_cell()
if index not in skip_columns:
self.doc.write_cell(item)
self.doc.end_row()
def set_row(self,val):
@ -123,9 +94,7 @@ class TableReport:
def write_table_head(self,data):
self.doc.start_row()
for item in data:
self.doc.start_cell("head")
self.doc.write_text(item)
self.doc.end_cell()
self.doc.write_cell(item)
self.doc.end_row()
#------------------------------------------------------------------------
@ -419,10 +388,10 @@ class DisplayChart(ManagedWindow.ManagedWindow):
if status == gtk.RESPONSE_OK:
name = unicode(f.get_filename(),
sys.getfilesystemencoding())
pstyle = BaseDoc.PaperStyle("junk",10,10)
doc = ODSDoc.ODSDoc(pstyle,BaseDoc.PAPER_PORTRAIT)
doc = ODSTab.ODSTab(len(self.row_data))
doc.creator(self.db.get_researcher().get_name())
spreadsheet = TableReport(name,doc)
spreadsheet = TableReport(name, doc)
new_titles = []
skip_columns = []