From 1d225c91dbb4f47e0bbf3eff312e60c75fec92d0 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Mon, 29 May 2006 02:52:14 +0000 Subject: [PATCH] Add name keys for indexing in reports svn: r6809 --- ChangeLog | 4 + src/BaseDoc.py | 3 +- src/PluginUtils/_ReportUtils.py | 34 +++++++ src/docgen/AbiWord2Doc.py | 2 +- src/docgen/AsciiDoc.py | 2 +- src/docgen/HtmlDoc.py | 2 +- src/docgen/KwordDoc.py | 2 +- src/docgen/LPRDoc.py | 2 +- src/docgen/LaTeXDoc.py | 2 +- src/docgen/ODFDoc.py | 7 +- src/docgen/ODSDoc.py | 2 +- src/docgen/OpenOfficeDoc.py | 8 +- src/docgen/OpenSpreadSheet.py | 2 +- src/docgen/PSDrawDoc.py | 2 +- src/docgen/PdfDoc.py | 2 +- src/docgen/RTFDoc.py | 2 +- src/docgen/SpreadSheetDoc.py | 2 +- src/plugins/FamilyGroup.py | 151 ++++++++++++++++++++------------ 18 files changed, 159 insertions(+), 72 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ae71a4b8..6d5210cf6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ 2006-05-28 Brian Matherly * src/docgen/OpenOfficeDoc.py: Allow large cells to span pages (bug 0000165) + * src/BaseDoc.py: Add key to write_text. + * src/docgen/*: Add key to write_text. + * src/PluginUtils/_ReportUtils.py: Add get_name_key. + * src/plugins/FamilyGroup.py: insert name keys for indexing. 2006-05-27 Alex Roitman * src/plugins/Verify.py: More updates. diff --git a/src/BaseDoc.py b/src/BaseDoc.py index 5e2f9c38d..fbce01c3b 100644 --- a/src/BaseDoc.py +++ b/src/BaseDoc.py @@ -1409,12 +1409,13 @@ class BaseDoc: """ pass - def write_text(self, text): + def write_text(self, text, key=""): """ Writes the text in the current paragraph. Should only be used after a start_paragraph and before an end_paragraph. @param text: text to write. + @param key: key to use for indexing (if supported) """ pass diff --git a/src/PluginUtils/_ReportUtils.py b/src/PluginUtils/_ReportUtils.py index b11ee7551..416d6a342 100644 --- a/src/PluginUtils/_ReportUtils.py +++ b/src/PluginUtils/_ReportUtils.py @@ -2196,3 +2196,37 @@ def common_name(person,use_nick=False): return person.get_nick_name() else: return person.get_primary_name().get_first_name() + +#------------------------------------------------------------------------- +# +# Indexing function +# +#------------------------------------------------------------------------- +def get_person_key(db,person): + """ + Returns a key that can be used to index a person in a report + + @param db: the GRAMPS database instance + @param person: the the key is for + """ + name = person.get_primary_name().get_name() + birth = " " + death = " " + key = "" + + birth_ref = person.get_birth_ref() + if birth_ref: + birthEvt = db.get_event_from_handle(birth_ref.ref) + birth = DateHandler.get_date(birthEvt) + + death_ref = person.get_death_ref() + if death_ref: + deathEvt = db.get_event_from_handle(death_ref.ref) + death = DateHandler.get_date(deathEvt) + + if birth == " " and death == " ": + key = name + else: + key = "%s (%s - %s)" % (name,birth,death) + + return key diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py index 77bad3394..896e4048d 100644 --- a/src/docgen/AbiWord2Doc.py +++ b/src/docgen/AbiWord2Doc.py @@ -265,7 +265,7 @@ class AbiWordDoc(BaseDoc.BaseDoc): self.write_text(line) self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): text = text.replace('&','&'); # Must be first text = text.replace('<','<'); text = text.replace('>','>'); diff --git a/src/docgen/AsciiDoc.py b/src/docgen/AsciiDoc.py index ef0ddfa38..827866477 100644 --- a/src/docgen/AsciiDoc.py +++ b/src/docgen/AsciiDoc.py @@ -369,7 +369,7 @@ class AsciiDoc(BaseDoc.BaseDoc): # # Writes text. #-------------------------------------------------------------------- - def write_text(self,text): + def write_text(self,text,key=""): text = text.replace('','[') text = text.replace('',']') self.text = self.text + text diff --git a/src/docgen/HtmlDoc.py b/src/docgen/HtmlDoc.py index 0edb718ac..5807bc0c3 100644 --- a/src/docgen/HtmlDoc.py +++ b/src/docgen/HtmlDoc.py @@ -480,7 +480,7 @@ class HtmlDoc(BaseDoc.BaseDoc): self.write_text(line.strip().replace('\n',' ')) self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): text = text.replace('&','&'); # Must be first text = text.replace('<','<'); text = text.replace('>','>'); diff --git a/src/docgen/KwordDoc.py b/src/docgen/KwordDoc.py index f5b789d31..73a65857b 100644 --- a/src/docgen/KwordDoc.py +++ b/src/docgen/KwordDoc.py @@ -482,7 +482,7 @@ class KwordDoc(BaseDoc.BaseDoc): self.write_text(line) self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): text = text.replace('&','&'); # Must be first text = text.replace('<','<'); text = text.replace('>','>'); diff --git a/src/docgen/LPRDoc.py b/src/docgen/LPRDoc.py index 6fc16e4f1..2ca2664e1 100644 --- a/src/docgen/LPRDoc.py +++ b/src/docgen/LPRDoc.py @@ -778,7 +778,7 @@ class LPRDoc(BaseDoc.BaseDoc): y = y - height return (x,y) - def write_text(self,text): + def write_text(self,text,key=""): """Add the text to the paragraph""" self.brand_new_page = 0 # Take care of superscript tags diff --git a/src/docgen/LaTeXDoc.py b/src/docgen/LaTeXDoc.py index be725d0f5..333122ac6 100644 --- a/src/docgen/LaTeXDoc.py +++ b/src/docgen/LaTeXDoc.py @@ -484,7 +484,7 @@ class LaTeXDoc(BaseDoc.BaseDoc): self.f.write('\\end{verbatim}') self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): """Write the text to the file""" if text == '\n': text = '\\newline\n' diff --git a/src/docgen/ODFDoc.py b/src/docgen/ODFDoc.py index 89e54eff9..3b9e7f4b2 100644 --- a/src/docgen/ODFDoc.py +++ b/src/docgen/ODFDoc.py @@ -824,12 +824,17 @@ class ODFDoc(BaseDoc.BaseDoc): self.write_text(line) self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): """ Uses the xml.sax.saxutils.escape function to convert XML entities. The _esc_map dictionary allows us to add our own mappings. """ + if key != "": + key = escape(key,_esc_map) + key = key.replace('"','"') + self.cntnt.write('' % key) self.cntnt.write(escape(text,_esc_map)) def _write_manifest(self): diff --git a/src/docgen/ODSDoc.py b/src/docgen/ODSDoc.py index 3708252ba..e4cc6358a 100644 --- a/src/docgen/ODSDoc.py +++ b/src/docgen/ODSDoc.py @@ -395,7 +395,7 @@ class ODSDoc(SpreadSheetDoc): def end_page(self): self.f.write('\n') - def write_text(self,text): + def write_text(self,text,key=""): if text == "": return if self.content == 0: diff --git a/src/docgen/OpenOfficeDoc.py b/src/docgen/OpenOfficeDoc.py index 722128362..99616e0ee 100644 --- a/src/docgen/OpenOfficeDoc.py +++ b/src/docgen/OpenOfficeDoc.py @@ -727,12 +727,18 @@ class OpenOfficeDoc(BaseDoc.BaseDoc): self.write_text(line) self.end_paragraph() - def write_text(self,text): + def write_text(self,text,key=""): """ Uses the xml.sax.saxutils.escape function to convert XML entities. The _esc_map dictionary allows us to add our own mappings. """ + + if key != "": + key = escape(key,_esc_map) + key = key.replace('"','"') + self.cntnt.write('' % key) self.cntnt.write(escape(text,_esc_map)) def _write_manifest(self): diff --git a/src/docgen/OpenSpreadSheet.py b/src/docgen/OpenSpreadSheet.py index 2a41c320c..028459446 100644 --- a/src/docgen/OpenSpreadSheet.py +++ b/src/docgen/OpenSpreadSheet.py @@ -381,7 +381,7 @@ class OpenSpreadSheet(SpreadSheetDoc): def end_page(self): self.f.write('\n') - def write_text(self,text): + def write_text(self,text,key=""): if text == "": return if self.content == 0: diff --git a/src/docgen/PSDrawDoc.py b/src/docgen/PSDrawDoc.py index bcc03016b..881c9f8f7 100644 --- a/src/docgen/PSDrawDoc.py +++ b/src/docgen/PSDrawDoc.py @@ -138,7 +138,7 @@ class PSDrawDoc(BaseDoc.BaseDoc): if self.print_req: Report.run_print_dialog (self.filename) - def write_text(self,text): + def write_text(self,text,key=""): pass def start_page(self): diff --git a/src/docgen/PdfDoc.py b/src/docgen/PdfDoc.py index 819f3c71d..0a0bfaecc 100644 --- a/src/docgen/PdfDoc.py +++ b/src/docgen/PdfDoc.py @@ -403,7 +403,7 @@ class PdfDoc(BaseDoc.BaseDoc): else: self.story.append(Paragraph(line,current_para)) - def write_text(self,text): + def write_text(self,text,key=""): text = text.replace('&','&') # Must be first text = text.replace('<','<') text = text.replace('>','>') diff --git a/src/docgen/RTFDoc.py b/src/docgen/RTFDoc.py index fcafd231a..d3252ab79 100644 --- a/src/docgen/RTFDoc.py +++ b/src/docgen/RTFDoc.py @@ -401,7 +401,7 @@ class RTFDoc(BaseDoc.BaseDoc): # the form of \`XX. Make sure to escape braces. # #-------------------------------------------------------------------- - def write_text(self,text): + def write_text(self,text,key=""): if self.opened == 0: self.opened = 1 self.text = self.text + '{%s ' % self.font_type diff --git a/src/docgen/SpreadSheetDoc.py b/src/docgen/SpreadSheetDoc.py index 315d8723b..1a8480375 100644 --- a/src/docgen/SpreadSheetDoc.py +++ b/src/docgen/SpreadSheetDoc.py @@ -112,5 +112,5 @@ class SpreadSheetDoc: def end_cell(self): pass - def write_text(self,text): + def write_text(self,text,key=""): pass diff --git a/src/plugins/FamilyGroup.py b/src/plugins/FamilyGroup.py index 19d0074e0..6e5526240 100644 --- a/src/plugins/FamilyGroup.py +++ b/src/plugins/FamilyGroup.py @@ -35,7 +35,7 @@ import gtk # #------------------------------------------------------------------------ import RelLib -from PluginUtils import Report, ReportOptions, register_report +from PluginUtils import Report, ReportOptions, register_report, ReportUtils import BaseDoc import DateHandler import Utils @@ -181,56 +181,8 @@ class FamilyGroup(Report.Report): self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() - - def dump_parent_line(self,name,text): - self.doc.start_row() - self.doc.start_cell("FGR-TextContents") - self.doc.start_paragraph('FGR-Normal') - self.doc.write_text(name) - self.doc.end_paragraph() - self.doc.end_cell() - self.doc.start_cell("FGR-TextContentsEnd",2) - self.doc.start_paragraph('FGR-Normal') - self.doc.write_text(text) - self.doc.end_paragraph() - self.doc.end_cell() - self.doc.end_row() - - def dump_parent(self,title,person_handle): - - if not person_handle and not self.missingInfo: - return - elif not person_handle: - person = RelLib.Person() - else: - person = self.database.get_person_from_handle(person_handle) - - self.doc.start_table(title,'FGR-ParentTable') - self.doc.start_row() - self.doc.start_cell('FGR-ParentHead',3) - self.doc.start_paragraph('FGR-ParentName') - self.doc.write_text(title + ': ') - self.doc.write_text(person.get_primary_name().get_regular_name()) - self.doc.end_paragraph() - self.doc.end_cell() - self.doc.end_row() - - birth_ref = person.get_birth_ref() - birth = None - evtName = str(RelLib.EventType()) - if birth_ref: - birth = self.database.get_event_from_handle(birth_ref.ref) - if birth or self.missingInfo: - self.dump_parent_event(evtName,birth) - - death_ref = person.get_death_ref() - death = None - evtName = str(RelLib.EventType(RelLib.EventType.DEATH)) - if death_ref: - death = self.database.get_event_from_handle(death_ref.ref) - if death or self.missingInfo: - self.dump_parent_event(evtName,death) - + + def dump_parent_parents(self,person): family_handle = person.get_main_parents_family_handle() father_name = "" mother_name = "" @@ -270,12 +222,93 @@ class FamilyGroup(Report.Report): death = DateHandler.get_date( event ) if birth_ref or death_ref: mother_name = "%s (%s - %s)" % (mother_name,birth,death) + + if father_name != "": + self.doc.start_row() + self.doc.start_cell("FGR-TextContents") + self.doc.start_paragraph('FGR-Normal') + self.doc.write_text(_("Father")) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.start_cell("FGR-TextContentsEnd",2) + self.doc.start_paragraph('FGR-Normal') + key = ReportUtils.get_person_key(self.database,father) + self.doc.write_text(father_name,key) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() + elif self.missingInfo: + self.dump_parent_line(_("Father"),"") - if self.missingInfo or father_name != "": - self.dump_parent_line(_("Father"),father_name) + if mother_name != "": + self.doc.start_row() + self.doc.start_cell("FGR-TextContents") + self.doc.start_paragraph('FGR-Normal') + self.doc.write_text(_("Mother")) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.start_cell("FGR-TextContentsEnd",2) + self.doc.start_paragraph('FGR-Normal') + key = ReportUtils.get_person_key(self.database,mother) + self.doc.write_text(mother_name,key) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() + elif self.missingInfo: + self.dump_parent_line(_("Mother"),"") - if self.missingInfo or mother_name != "": - self.dump_parent_line(_("Mother"),mother_name) + def dump_parent_line(self,name,text): + self.doc.start_row() + self.doc.start_cell("FGR-TextContents") + self.doc.start_paragraph('FGR-Normal') + self.doc.write_text(name) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.start_cell("FGR-TextContentsEnd",2) + self.doc.start_paragraph('FGR-Normal') + self.doc.write_text(text) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() + + def dump_parent(self,title,person_handle): + + if not person_handle and not self.missingInfo: + return + elif not person_handle: + person = RelLib.Person() + else: + person = self.database.get_person_from_handle(person_handle) + name = person.get_primary_name().get_regular_name() + + self.doc.start_table(title,'FGR-ParentTable') + self.doc.start_row() + self.doc.start_cell('FGR-ParentHead',3) + self.doc.start_paragraph('FGR-ParentName') + self.doc.write_text(title + ': ') + key = ReportUtils.get_person_key(self.database,person) + self.doc.write_text(name,key) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() + + birth_ref = person.get_birth_ref() + birth = None + evtName = str(RelLib.EventType()) + if birth_ref: + birth = self.database.get_event_from_handle(birth_ref.ref) + if birth or self.missingInfo: + self.dump_parent_event(evtName,birth) + + death_ref = person.get_death_ref() + death = None + evtName = str(RelLib.EventType(RelLib.EventType.DEATH)) + if death_ref: + death = self.database.get_event_from_handle(death_ref.ref) + if death or self.missingInfo: + self.dump_parent_event(evtName,death) + + self.dump_parent_parents(person) if self.incParEvents: for event_ref in person.get_event_ref_list(): @@ -462,9 +495,12 @@ class FamilyGroup(Report.Report): self.doc.write_text(_("%dU") % index) self.doc.end_paragraph() self.doc.end_cell() + + name = person.get_primary_name().get_regular_name() + key = ReportUtils.get_person_key(self.database,person) self.doc.start_cell('FGR-ChildName',3) self.doc.start_paragraph('FGR-ChildText') - self.doc.write_text(person.get_primary_name().get_regular_name()) + self.doc.write_text(name,key) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row() @@ -534,7 +570,8 @@ class FamilyGroup(Report.Report): death = DateHandler.get_date(event) if birth_ref or death_ref: spouse_name = "%s (%s - %s)" % (spouse_name,birth,death) - self.doc.write_text(spouse_name) + key = ReportUtils.get_person_key(self.database,spouse) + self.doc.write_text(spouse_name,key) self.doc.end_paragraph() self.doc.end_cell() self.doc.end_row()