diff --git a/src/HtmlDoc.py b/src/HtmlDoc.py index 7690aaf30..0304970ef 100644 --- a/src/HtmlDoc.py +++ b/src/HtmlDoc.py @@ -24,7 +24,6 @@ import string import re from TextDoc import * -from latin_utf8 import latin_to_utf8 import const _top = [ diff --git a/src/OpenOffice.py b/src/OpenOffice.py deleted file mode 100644 index ad994cbb1..000000000 --- a/src/OpenOffice.py +++ /dev/null @@ -1,136 +0,0 @@ -# -# 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 re -import time -import tempfile -import const - -meta_creator = re.compile(r"""\s*""") -dc_creator = re.compile(r"""\s*""") -meta_date = re.compile(r"""\s*""") -dc_date = re.compile(r"""\s*""") - -class OpenOfficeCore: - - def __init__(self,filename,template,ext,owner=""): - self.template = template - self.owner = owner - if filename[-4:] != ext: - self.filename = filename + ext - else: - self.filename = filename - self.first = [] - self.last = [] - self.file = None - self.image_list = [] - self.tempdir = "" - - def setup(self): - templateFile = open(self.template,"r") - lines = templateFile.readlines() - templateFile.close() - - in_last = 0 - t = time.localtime(time.time()) - time_str="%04d-%02d-%02dT%02d:%02d:%02d" % \ - (t[0],t[1],t[2],t[3],t[4],t[5]) - for line in lines: - if line[1:15] == "": - in_last = 1 - self.last.append(line); - elif in_last == 0: - if meta_creator.match(line): - self.first.append("" + self.owner + \ - "") - elif dc_creator.match(line): - self.first.append("" + self.owner + \ - "") - elif dc_date.match(line): - self.first.append("" + time_str + \ - "") - elif meta_date.match(line): - self.first.append("" + time_str + \ - "") - else: - self.first.append(line) - else: - self.last.append(line); - - 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.file = open(self.tempdir + os.sep + "Content.xml","w") - for line in self.first: - self.file.write(line) - return self.file - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def add_image(self,name): - self.image_list.append(name) - return self.tempdir + os.sep + "Pictures" + os.sep + name - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def end(self): - import shutil - - for line in self.last: - self.file.write(line) - - self.file.close() - tmpname = tempfile.mktemp() - - file = open(self.tempdir + os.sep + "META-INF" + os.sep + \ - "manifest.xml","w") - file.write('\n') - file.write('') - for image in self.image_list: - file.write('') - file.write('') - file.write('\n') - file.close() - os.system("cd " + self.tempdir + "; " + const.zipcmd + " " \ - + tmpname + " .") - if os.path.isfile(self.filename): - os.unlink(self.filename) - shutil.copy(tmpname,self.filename) - os.unlink(tmpname) - os.unlink(self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml") - os.unlink(self.tempdir + os.sep + "Content.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) - - diff --git a/src/OpenOfficeDoc.py b/src/OpenOfficeDoc.py index e4431a3d8..9c0131229 100644 --- a/src/OpenOfficeDoc.py +++ b/src/OpenOfficeDoc.py @@ -26,6 +26,11 @@ from TextDoc import * from latin_utf8 import latin_to_utf8 import const +try: + from codecs import * +except: + def EncodedFile(a,b,c): + return a class OpenOfficeDoc(TextDoc): @@ -54,7 +59,9 @@ class OpenOfficeDoc(TextDoc): 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") + fname = self.tempdir + os.sep + "content.xml" + self.f = EncodedFile(open(fname,"wb"),'latin-1','utf-8') + self.f.write('\n') self.f.write('\n') + def start_table(self,name,style_name): 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.style_list.keys(): style = self.style_list[key] self.f.write('') self.f.write(latin_to_utf8(text)) + def _write_photos(self): + + for file_tuple in self.photo_list: + file = file_tuple[0] + width = file_tuple[1] + height = file_tuple[2] + base = os.path.basename(file) + image_name = self.tempdir + os.sep + "Pictures" + os.sep + base + cmd = "%s -size %dx%d %s %s" % (const.convert,width,height,file,image_name) + os.system(cmd) + def _write_manifest(self): file = self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml" - self.f = open(file,"w") + self.f = EncodedFile(open(file,"wb"),'latin-1','utf-8') self.f.write('\n') self.f.write('') self.f.write('') + for image in self.photo_list: + i = image[0] + base = os.path.basename(i) + 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 = EncodedFile(open(file,"wb"),'latin-1','utf-8') self.f.write('\n') self.f.write('\n") total = len(personList) + len(familyList) diff --git a/src/build_po b/src/build_po index d017a6a4e..b61c52c12 100755 --- a/src/build_po +++ b/src/build_po @@ -7,4 +7,4 @@ echo "Working on python files" ./get_strings *.py >> glade.c echo "Building template.po" xgettext -C -s -a -o template.po glade.c -rm glade.c \ No newline at end of file +#rm glade.c diff --git a/src/plugins/EventCmp.py b/src/plugins/EventCmp.py index cfce59301..ec7ca8cb1 100644 --- a/src/plugins/EventCmp.py +++ b/src/plugins/EventCmp.py @@ -30,7 +30,6 @@ import re import sort import utils import string -import OpenOffice #------------------------------------------------------------------------ # @@ -49,6 +48,9 @@ from libglade import * import ListColors import Filter import const +from TextDoc import * +from OpenSpreadSheet import * + #------------------------------------------------------------------------ # @@ -68,43 +70,43 @@ FILTER = "x" # #------------------------------------------------------------------------ class TableReport: - def __init__(self,filename): + + def __init__(self,filename,doc): self.filename = filename - - def initialize(self): - pass - - def finalize(self): - pass - - def write_table_head(): - pass - - def set_row(self,val): - pass - - def write_table_data(): - pass - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class OpenOfficeTable(TableReport): - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def initialize(self): - templateFile = const.dataDir + os.sep + "table.sxc" + self.doc = doc - self.open_office = OpenOffice.OpenOfficeCore(self.filename,\ - templateFile,".sxc") - self.file = self.open_office.setup() - self.file.write('\n') + #-------------------------------------------------------------------- + # + # + # + #-------------------------------------------------------------------- + def initialize(self,cols): + + t = TableStyle() + t.set_columns(cols) + for index in range(0,cols): + t.set_column_width(index,4) + self.doc.add_table_style("mytbl",t) + + f = FontStyle() + f.set_type_face(FONT_SANS_SERIF) + f.set_size(12) + f.set_bold(1) + p = ParagraphStyle() + p.set_font(f) + p.set_background_color((0xcc,0xff,0xff)) + p.set_padding(0.1) + self.doc.add_style("head",p) + + f = FontStyle() + f.set_type_face(FONT_SANS_SERIF) + f.set_size(10) + p = ParagraphStyle() + p.set_font(f) + self.doc.add_style("data",p) + + self.doc.open(self.filename) + self.doc.start_page("Page 1","mytbl") #-------------------------------------------------------------------- # @@ -112,8 +114,8 @@ class OpenOfficeTable(TableReport): # #-------------------------------------------------------------------- def finalize(self): - self.file.write('\n') - self.open_office.end() + self.doc.end_page() + self.doc.close() #-------------------------------------------------------------------- # @@ -122,14 +124,13 @@ class OpenOfficeTable(TableReport): #-------------------------------------------------------------------- def write_table_data(self,data): length = len(data) - - self.file.write('\n') + + self.doc.start_row() for item in data: - self.file.write('\n') - self.file.write('' + item + '\n') - self.file.write('\n') - self.file.write('\n') + self.doc.start_cell("data") + self.doc.write_text(item) + self.doc.end_cell() + self.doc.end_row() #-------------------------------------------------------------------- # @@ -147,105 +148,13 @@ class OpenOfficeTable(TableReport): def write_table_head(self,data): length = len(data) self.prev = 3 - self.file.write('\n') - self.file.write('\n') + + self.doc.start_row() for item in data: - self.file.write('\n') - self.file.write('' + item + '\n') - self.file.write('\n') - self.file.write('\n') - - -#------------------------------------------------------------------------ -# -# -# -#------------------------------------------------------------------------ -class HtmlTable(TableReport): - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def __init__(self,file,template): - self.template = template - TableReport.__init__(self,file) - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def initialize(self): - if self.template == "": - self.template = const.dataDir + os.sep + "table.html" - - templateFile = open(self.template,"r") - lines = templateFile.readlines() - templateFile.close() - - self.last = [] - self.first = [] - in_last = 0 - for line in lines: - if line[0:14] == "": - in_last = 1 - self.last.append(line); - elif in_last == 0: - self.first.append(line) - else: - self.last.append(line); - - self.file = open(self.filename,"w") - for line in self.first: - self.file.write(line) - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def finalize(self): - - self.file.write("") - for line in self.last: - self.file.write(line) - self.file.close() - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_table_data(self,data): - length = len(data) - - self.file.write('\n') - for item in data: - self.file.write('\n') - if item == "": - self.file.write(' ') - else: - self.file.write(fix(item)) - self.file.write('\n\n') - self.file.write('\n') - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_table_head(self,data): - self.file.write('\n') - self.file.write('\n') - for item in data: - self.file.write('\n') - self.file.write('\n') + self.doc.start_cell("head") + self.doc.write_text(item) + self.doc.end_cell() + self.doc.end_row() #------------------------------------------------------------------------ # @@ -450,17 +359,14 @@ class EventComparison: for item in unsort_list: sort_list.append(item[1]) + event_titles = ["Person","Birth","Death"] + sort_list + name = self.form.get_widget("filename").get_text() - if self.form.get_widget("openoffice").get_active(): - spreadsheet = OpenOfficeTable(name) - elif self.form.get_widget("html").get_active(): - template = self.form.get_widget("htmlfile").get_text() - spreadsheet = HtmlTable(name,template) + doc = OpenSpreadSheet(PaperStyle("junk",10,10),PAPER_PORTRAIT) + spreadsheet = TableReport(name,doc) + spreadsheet.initialize(len(event_titles)) - spreadsheet.initialize() - - event_titles = ["Person","Birth","Death"] + sort_list spreadsheet.write_table_head(event_titles) diff --git a/src/plugins/IndivSummary.py b/src/plugins/IndivSummary.py index 545712a9f..326dfd76b 100644 --- a/src/plugins/IndivSummary.py +++ b/src/plugins/IndivSummary.py @@ -81,6 +81,7 @@ class IndivSummary: font.set_type_face(FONT_SANS_SERIF) font.set_size(16) p = ParagraphStyle() + p.set_alignment(PARA_ALIGN_CENTER) p.set_font(font) self.d.add_style("Title",p) @@ -132,64 +133,6 @@ class IndivSummary: def end(self): self.d.close() - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_header(self): - pass - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_spouse(self,person): - if person: - name = person.getPrimaryName().getRegularName() - else: - name = "unknown" - self.file.write('\n') - self.file.write('\n') - self.file.write('') - self.file.write(name) - self.file.write('\n') - self.file.write("\n") - self.file.write("\n") - self.file.write("\n") - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_general(self): - - self.file.write('\n') - self.file.write('\n') - self.file.write('\n') - - name = self.person.getPrimaryName().getRegularName() - self.write_simple_row("Name:",name) - if self.person.getGender() == RelLib.Person.male: - self.write_simple_row("Gender:","Male") - else: - self.write_simple_row("Gender:","Female") - family = self.person.getMainFamily() - if family: - father = family.getFather().getPrimaryName().getRegularName() - mother = family.getMother().getPrimaryName().getRegularName() - else: - father = "" - mother = "" - self.write_simple_row("Father:",father) - self.write_simple_row("Mother:",mother) - - self.file.write('\n') - #-------------------------------------------------------------------- # # @@ -227,29 +170,6 @@ class IndivSummary: self.d.end_cell() self.d.end_row() - - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def write_facts(self): - - self.file.write('') - self.file.write('\n') - self.file.write('\n') - self.file.write('\n') - - self.write_header_row("Individual Facts") - event_list = [ self.person.getBirth(), self.person.getDeath() ] - event_list = event_list + self.person.getEventList() - - for event in event_list: - self.write_fact(event) - - self.file.write('\n') - - #-------------------------------------------------------------------- # # @@ -316,24 +236,7 @@ class IndivSummary: # #-------------------------------------------------------------------- def write_report(self): -# photo_list = self.person.getPhotoList() -# if len(photo_list) > 0: -# import GdkImlib -# file = photo_list[0].getPath() -# image = GdkImlib.Image(file) -# height = image.rgb_height -# scale = float(height)/150.0 -# width = int(image.rgb_width * scale) -# height = int(height * scale) -# base = os.path.basename(file) -# image_name = self.open_office.add_image(base) -# cmd = const.convert + " -size " + str(width) + "x150 "\ -# + file + " " + image_name -# os.system(cmd) -# self.scale = float(height)/float(width) -# self.image = base -# else: -# self.image = "" + photo_list = self.person.getPhotoList() self.d.start_paragraph("Title") self.d.write_text('Summary of ') @@ -342,6 +245,13 @@ class IndivSummary: self.d.start_paragraph("Normal") self.d.end_paragraph() + + if len(photo_list) > 0: + file = photo_list[0].getPath() + self.d.start_paragraph("Normal") + self.d.add_photo(file,300,300) + self.d.end_paragraph() + self.d.start_table("one","IndTable") self.d.start_row() diff --git a/src/plugins/ReadGedcom.py b/src/plugins/ReadGedcom.py index e9548f7a1..fe9e99d3f 100644 --- a/src/plugins/ReadGedcom.py +++ b/src/plugins/ReadGedcom.py @@ -165,8 +165,8 @@ def importData(database, filename): total = len(allLines) value = 0 - for index in range(1,21): - value = value + total/20 + for index in range(1,51): + value = value + total/50 values[index] = value index = 1 @@ -179,9 +179,9 @@ def importData(database, filename): elif encoding == 2: line = latin_utf8.utf8_to_latin(line) - if currentLine == value and index <= 20: + if currentLine == value and index <= 50: index = index + 1 - if index <= 20: + if index <= 50: value = values[index] progressWindow.set_percentage(float(currentLine)/float(total)) while events_pending(): @@ -402,6 +402,13 @@ def importData(database, filename): inlocalNote = 0 person.setNote(user2note[noteId]) + regex_match = noterefRegexp.match(line) + if regex_match : + matches = regex_match.groups() + print "found note",matches[0] + person2note[person] = matches[0] + continue + regex_match = noteactRegexp.match(line) if regex_match : inlocalNote = 1 @@ -429,12 +436,6 @@ def importData(database, filename): mySource.setPage(matches[0]) continue - regex_match = noterefRegexp.match(line) - if regex_match : - matches = regex_match.groups() - person2note[person] = matches[0] - continue - regex_match = genderRegexp.match(line) if regex_match : matches = regex_match.groups() @@ -645,11 +646,10 @@ def on_ok_clicked(obj): statusWindow.destroy() except IOError, val: GnomeErrorDialog("Could not load " + name + "\n" + val[1]) + except: + GnomeErrorDialog("Could not load " + name + \ + "\n due to an unexpected internal error") statusWindow.destroy() -# except: -# GnomeErrorDialog("Could not load " + name + \ -# "\n due to an unexpected internal error") -# statusWindow.destroy() #------------------------------------------------------------------------- # diff --git a/src/plugins/eventcmp.glade b/src/plugins/eventcmp.glade index 1ca99a7ec..9ceb88bc4 100644 --- a/src/plugins/eventcmp.glade +++ b/src/plugins/eventcmp.glade @@ -71,6 +71,7 @@ Wed, 07 Mar 2001 04:12:28 GMT GNOME_STOCK_BUTTON_APPLY + GTK_RELIEF_NORMAL @@ -85,6 +86,7 @@ Tue, 06 Mar 2001 23:40:27 GMT GNOME_STOCK_BUTTON_CANCEL + GTK_RELIEF_NORMAL @@ -93,6 +95,7 @@ True True GNOME_STOCK_BUTTON_HELP + GTK_RELIEF_NORMAL @@ -344,6 +347,7 @@ Wed, 07 Mar 2001 02:55:00 GMT + GTK_RELIEF_NORMAL @@ -358,6 +362,7 @@ Wed, 07 Mar 2001 02:55:12 GMT + GTK_RELIEF_NORMAL @@ -366,6 +371,7 @@ True True + GTK_RELIEF_NORMAL @@ -380,6 +386,7 @@ Sun, 18 Mar 2001 13:52:32 GMT + GTK_RELIEF_NORMAL @@ -436,6 +443,7 @@ True True + GTK_RELIEF_NORMAL @@ -450,6 +458,7 @@ Thu, 15 Mar 2001 20:53:45 GMT + GTK_RELIEF_NORMAL @@ -464,6 +473,7 @@ Thu, 08 Mar 2001 16:10:16 GMT GNOME_STOCK_BUTTON_CLOSE + GTK_RELIEF_NORMAL @@ -693,6 +703,7 @@ GtkRadioButton html + False True toggled @@ -729,6 +740,7 @@ GtkLabel label11 + False GTK_JUSTIFY_CENTER False @@ -746,6 +758,7 @@ GnomeFileEntry htmltemplate + False False HtmlTemplate 10
\n') - self.file.write(fix(item)) - self.file.write('\n