diff --git a/gramps/src/OpenSpreadSheet.py b/gramps/src/OpenSpreadSheet.py new file mode 100644 index 000000000..8c9c2b5a0 --- /dev/null +++ b/gramps/src/OpenSpreadSheet.py @@ -0,0 +1,456 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 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 +# + +import os +import tempfile +import string + +from TextDoc import * +from SpreadSheetDoc import * + +from latin_utf8 import latin_to_utf8 +import const + +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[0],t[1],t[2],t[3],t[4],t[5]) + + if filename[-4:] != ".sxc": + self.filename = filename + ".sxc" + else: + self.filename = filename + + tempfile.tempdir = "/tmp" + self.tempdir = tempfile.mktemp() + os.mkdir(self.tempdir,0700) + os.mkdir(self.tempdir + os.sep + "Pictures") + os.mkdir(self.tempdir + os.sep + "META-INF") + + self.f = open(self.tempdir + os.sep + "content.xml","w") + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + for key in self.table_styles.keys(): + table = self.table_styles[key] + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + for index in range(0,table.get_columns()): + self.f.write('\n') + self.f.write('\n' % table.get_column_width(index)) + self.f.write('\n') + + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + + for key in self.style_list.keys(): + style = self.style_list[key] + font = style.get_font() + self.f.write('\n') + self.f.write('\n') + else: + self.f.write('fo:font-weight="normal"/>\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + + def close(self): + self.f.write('\n') + self.f.write('\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('\n') + + def end_row(self): + self.f.write('\n') + + def start_cell(self,style_name,span=1): + self.content = 0 + self.span = span + self.f.write(' 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('\n') + else: + self.f.write('\n') + self.f.write('\n') + for col in range(1,self.span): + self.f.write('\n') + + def _write_zip(self): + + if os.path.isfile(self.filename): + os.unlink(self.filename) + + os.system("cd " + self.tempdir + "; " + const.zipcmd + " " \ + + self.filename + " .") + + os.unlink(self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml") + os.unlink(self.tempdir + os.sep + "content.xml") + os.unlink(self.tempdir + os.sep + "meta.xml") + os.unlink(self.tempdir + os.sep + "styles.xml") +# for image in self.image_list: +# os.unlink(self.tempdir + os.sep + "Pictures" + os.sep + image) + os.rmdir(self.tempdir + os.sep + "Pictures") + os.rmdir(self.tempdir + os.sep + "META-INF") + os.rmdir(self.tempdir) + + def _write_styles_file(self): + file = self.tempdir + os.sep + "styles.xml" + self.f = open(file,"w") + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('???\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('Page 1\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('??? ') + self.f.write('(???)\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('05/16/2001, ') + self.f.write('10:53:17\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('Page 1 / ') + self.f.write('99\n') + self.f.write('\n') + self.f.write('\n') + self.f.write(' \n') + self.f.write('\n') + self.f.close() + + def start_page(self,name,style_name): + table = self.table_styles[style_name] + self.f.write('\n') + for col in range(0,table.get_columns()): + self.f.write('\n') + + def end_page(self): + self.f.write('\n') + + def write_text(self,text): + if text == "": + return + if self.content == 0: + self.f.write('') + self.content = 1 + text = string.replace(text,'\t','') + text = string.replace(text,'\n','') + self.f.write(latin_to_utf8(text)) + + def _write_manifest(self): + file = self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml" + self.f = open(file,"w") + self.f.write('\n') + self.f.write('') + self.f.write('') + self.f.write('') + self.f.write('') + self.f.write('') + self.f.write('') + #self.f.write('') + self.f.write('\n') + self.f.close() + + def _write_meta_file(self): + file = self.tempdir + os.sep + "meta.xml" + name = latin_to_utf8(self.name) + self.f = open(file,"w") + self.f.write('\n') + self.f.write('\n'); + self.f.write('\n') + self.f.write('') + self.f.write(const.progName + ' ' + const.version) + self.f.write('\n') + self.f.write('') + self.f.write(name) + self.f.write('\n') + self.f.write('') + self.f.write(self.time) + self.f.write('\n') + self.f.write('') + self.f.write(name) + self.f.write('\n') + self.f.write('') + self.f.write(self.time) + self.f.write('\n') + self.f.write('0-00-00T00:00:00\n') + self.f.write('en-US\n') + self.f.write('1\n') + self.f.write('PT0S\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + self.f.close() + +if __name__ == "__main__": + + doc = OpenSpreadSheet(PaperStyle("junk",21.59,27),PAPER_PORTRAIT) + + t = TableStyle() + t.set_columns(3) + t.set_column_width(0,4) + t.set_column_width(1,2) + t.set_column_width(2,1) + doc.add_table_style("mytblstyle",t) + + f = FontStyle() + f.set_type_face(FONT_SANS_SERIF) + f.set_size(16) + f.set_bold(1) + p = ParagraphStyle() + p.set_font(f) + p.set_background_color((0xcc,0xff,0xff)) + p.set_padding(0.5) + doc.add_style("p1",p) + + doc.open("/home/dona/test") + doc.start_page("Page 1","mytblstyle") + doc.start_row() + doc.start_cell("p1") + doc.write_text("Hello") + doc.end_cell() + doc.end_row() + doc.end_page() + doc.close() diff --git a/gramps/src/SpreadSheetDoc.py b/gramps/src/SpreadSheetDoc.py new file mode 100644 index 000000000..22804b1f7 --- /dev/null +++ b/gramps/src/SpreadSheetDoc.py @@ -0,0 +1,116 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 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 TextDoc import * + +#------------------------------------------------------------------------ +# +# +# +#------------------------------------------------------------------------ +class SpreadSheetDoc: + 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,orientation=None): + 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): + pass