From 569af0f28841c658aac890bf0663d243e6b53b53 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 2 Oct 2005 18:25:39 +0000 Subject: [PATCH] * src/ReportUtils.py: add pronoun/name support to child strings * src/plugin/DetAncestralReport.py: Add support for ReportUtils * src/plugin/DetDescendantReport.py: Add support for ReportUtils * src/plugins/ImportGenweb.py: fix date handling to support date ranges and date modifiers. svn: r5265 --- gramps2/ChangeLog | 7 + gramps2/src/ReportUtils.py | 114 ++++++++++++---- gramps2/src/plugins/DetAncestralReport.py | 72 +++++----- gramps2/src/plugins/DetDescendantReport.py | 2 +- gramps2/src/plugins/ImportGeneWeb.py | 146 ++++++++++++++------- 5 files changed, 225 insertions(+), 116 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index d7f418d50..02df0b358 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,10 @@ +2005-10-02 Don Allingham + * src/ReportUtils.py: add pronoun/name support to child strings + * src/plugin/DetAncestralReport.py: Add support for ReportUtils + * src/plugin/DetDescendantReport.py: Add support for ReportUtils + * src/plugins/ImportGenweb.py: fix date handling to support + date ranges and date modifiers. + 2005-10-02 Martin Hawlisch * src/plugins/TestcaseGenerator.py: corrected options help dict diff --git a/gramps2/src/ReportUtils.py b/gramps2/src/ReportUtils.py index 8d3698e2b..dbe4a395d 100644 --- a/gramps2/src/ReportUtils.py +++ b/gramps2/src/ReportUtils.py @@ -703,46 +703,100 @@ marriage_also_only = { child_father_mother = { RelLib.Person.UNKNOWN: [ - _("This person is the child of %(father)s and %(mother)s."), - _("This person was the child of %(father)s and %(mother)s."), + [ + _("This person is the child of %(father)s and %(mother)s."), + _("This person was the child of %(father)s and %(mother)s."), + ], + [ + _("%(male_name)s is the child of %(father)s and %(mother)s."), + _("%(male_name)s was the child of %(father)s and %(mother)s."), + ], ], RelLib.Person.MALE : [ - _("He is the son of %(father)s and %(mother)s."), - _("He was the son of %(father)s and %(mother)s."), + [ + _("He is the son of %(father)s and %(mother)s."), + _("He was the son of %(father)s and %(mother)s."), + ], + [ + _("%(male_name)s is the child of %(father)s and %(mother)s."), + _("%(male_name)s was the child of %(father)s and %(mother)s."), + ] ], RelLib.Person.FEMALE : [ - _("She is the daughter of %(father)s and %(mother)s."), - _("She was the daughter of %(father)s and %(mother)s."), + [ + _("She is the daughter of %(father)s and %(mother)s."), + _("She was the daughter of %(father)s and %(mother)s."), + ], + [ + _("%(female_name)s is the child of %(father)s and %(mother)s."), + _("%(female_name)s was the child of %(father)s and %(mother)s."), + ], ] } child_father = { RelLib.Person.UNKNOWN : [ - _("This person is the child of %(father)s."), - _("This person was the child of %(father)s."), + [ + _("This person is the child of %(father)s."), + _("This person was the child of %(father)s."), + ], + [ + _("%(male_name)s is the child of %(father)s."), + _("%(male_name)s was the child of %(father)s."), + ], ], RelLib.Person.MALE : [ - _("He is the son of %(father)s."), - _("He was the son of %(father)s."), + [ + _("He is the son of %(father)s."), + _("He was the son of %(father)s."), + ], + [ + _("%(male_name)s is the child of %(father)s."), + _("%(male_name)s was the child of %(father)s."), + ], ], RelLib.Person.FEMALE : [ - _("She is the daughter of %(father)s."), - _("She was the daughter of %(father)s."), + [ + _("She is the daughter of %(father)s."), + _("She was the daughter of %(father)s."), + ], + [ + _("%(female_name)s is the child of %(father)s."), + _("%(female_name)s was the child of %(father)s."), + ], ], } child_mother = { RelLib.Person.UNKNOWN : [ - _("This person is the child of %(mother)s."), - _("This person was the child of %(mother)s."), + [ + _("This person is the child of %(mother)s."), + _("This person was the child of %(mother)s."), + ], + [ + _("%(male_name)s is the child of %(mother)s."), + _("%(male_name)s was the child of %(mother)s."), + ], ], RelLib.Person.MALE : [ - _("He is the son of %(mother)s."), - _("He was the son of %(mother)s."), + [ + _("He is the son of %(mother)s."), + _("He was the son of %(mother)s."), + ], + [ + _("%(male_name)s is the child of %(mother)s."), + _("%(male_name)s was the child of %(mother)s."), + ], ], RelLib.Person.FEMALE : [ - _("She is the daughter of %(mother)s."), - _("She was the daughter of %(mother)s."), + [ + _("She is the daughter of %(mother)s."), + _("She was the daughter of %(mother)s."), + ], + [ + _("%(female_name)s is the child of %(mother)s."), + _("%(female_name)s was the child of %(mother)s."), + ], ], } @@ -1630,7 +1684,7 @@ def married_rel_str(database,person,family,is_first=True): # child_str # #------------------------------------------------------------------------- -def child_str(person,father_name="",mother_name="",dead=0): +def child_str(person, father_name="", mother_name="", dead=0, person_name=0): """ Composes a string describing person being a child. @@ -1649,22 +1703,32 @@ def child_str(person,father_name="",mother_name="",dead=0): @returns: A composed string @rtype: unicode """ - + values = { - 'father' : father_name, - 'mother' : mother_name, + 'father' : father_name, + 'mother' : mother_name, + 'male_name' : person_name, + 'female_name' : person_name, } + if person_name == 0: + index = 0 + else: + index = 1 + + print person_name, index + gender = person.get_gender() if mother_name and father_name: - text = child_father_mother[gender][dead] % values + text = child_father_mother[gender][index][dead] % values elif mother_name: - text = child_mother[gender][dead] % values + text = child_mother[gender][index][dead] % values elif father_name: - text = child_father[gender][dead] % values + text = child_father[gender][index][dead] % values if text: text = text + " " + print text return text #------------------------------------------------------------------------- diff --git a/gramps2/src/plugins/DetAncestralReport.py b/gramps2/src/plugins/DetAncestralReport.py index 0efeac8c4..5891f6167 100644 --- a/gramps2/src/plugins/DetAncestralReport.py +++ b/gramps2/src/plugins/DetAncestralReport.py @@ -160,7 +160,7 @@ class DetAncestorReport(Report.Report): if self.pgbrk and generation > 0: self.doc.page_break() self.doc.start_paragraph("DAR-Generation") - text = _("Generation %d") % generation+1 + text = _("Generation %d") % (generation+1) self.doc.write_text(text) self.doc.end_paragraph() generation = generation + 1 @@ -192,18 +192,17 @@ class DetAncestorReport(Report.Report): self.doc.start_paragraph("DAR-First-Entry","%s." % str(key)) - name = _nd.display(person) - - if self.firstName: - firstName = person.get_primary_name().get_first_name() - elif person.get_gender() == RelLib.Person.MALE: - firstName = _("He") - else: - firstName = _("She") + name = _nd.display_formal(person) self.doc.start_bold() self.doc.write_text(name) + if name[-1:] == '.': + self.doc.write_text(" ") + else: + self.doc.write_text(". ") self.doc.end_bold() + # Output the global source references for this person + self.endnotes(person) if self.dupPerson: # Check for duplicate record (result of distant cousins marrying) @@ -218,35 +217,24 @@ class DetAncestorReport(Report.Report): self.doc.end_paragraph() return 1 # Duplicate person - # Output the global source references for this person - self.endnotes(person) # Check birth record + self.doc.write_text(ReportUtils.born_str(self.database,person,0, + self.EMPTY_DATE,self.EMPTY_PLACE)) + birth_handle = person.get_birth_handle() if birth_handle: - text = ReportUtils.born_str(self.database,person,"", - self.EMPTY_DATE,self.EMPTY_PLACE) - if text: - self.doc.write_text(text) - self.endnotes(self.database.get_event_from_handle(birth_handle)) - else: - self.doc.write_text('. ') - else: - self.doc.write_text('. ') + self.endnotes(self.database.get_event_from_handle(birth_handle)) - death_handle = person.get_death_handle() + self.doc.write_text(ReportUtils.died_str(self.database,person,0, + self.EMPTY_DATE,self.EMPTY_PLACE)) + death_handle = person.get_birth_handle() if death_handle: - age,units = self.calc_age(person) - text = ReportUtils.died_str(self.database,person,firstName, - self.EMPTY_DATE,self.EMPTY_PLACE,age,units) - if text: - self.doc.write_text(text) - self.endnotes(self.database.get_event_from_handle(death_handle)) + self.endnotes(self.database.get_event_from_handle(death_handle)) - text = ReportUtils.buried_str(self.database,person,firstName, - self.EMPTY_DATE,self.EMPTY_PLACE) - if text: - self.doc.write_text(text) - # Missing source reference for burial + self.doc.write_text(ReportUtils.buried_str(self.database,person,0, + self.EMPTY_DATE,self.EMPTY_PLACE)) + + firstName = person.get_primary_name().get_first_name() self.write_parents(person, firstName) self.write_marriage(person) @@ -339,9 +327,9 @@ class DetAncestorReport(Report.Report): else: father_name = "" - text = ReportUtils.child_str(person, - father_name,mother_name, - bool(person.get_death_handle())) + text = ReportUtils.child_str(person, father_name, mother_name, + bool(person.get_death_handle()), + firstName) if text: self.doc.write_text(text) @@ -776,16 +764,16 @@ class DetAncestorOptions(ReportOptions.ReportOptions): dialog.add_frame_option(_('Content'),'',self.first_name_option) dialog.add_frame_option(_('Content'),'',self.full_date_option) dialog.add_frame_option(_('Content'),'',self.list_children_option) - dialog.add_frame_option(_('Content'),'',self.include_notes_option) - dialog.add_frame_option(_('Content'),'',self.place_option) - dialog.add_frame_option(_('Content'),'',self.date_option) dialog.add_frame_option(_('Content'),'',self.age_option) dialog.add_frame_option(_('Content'),'',self.dupPersons_option) dialog.add_frame_option(_('Content'),'',self.childRef_option) - dialog.add_frame_option(_('Content'),'',self.image_option) - dialog.add_frame_option(_('Content'),'',self.include_names_option) - dialog.add_frame_option(_('Content'),'',self.include_events_option) - dialog.add_frame_option(_('Content'),'',self.include_sources_option) + dialog.add_frame_option(_('Include'),'',self.image_option) + dialog.add_frame_option(_('Include'),'',self.include_notes_option) + dialog.add_frame_option(_('Include'),'',self.include_names_option) + dialog.add_frame_option(_('Include'),'',self.include_events_option) + dialog.add_frame_option(_('Include'),'',self.include_sources_option) + dialog.add_frame_option(_('Missing information'),'',self.place_option) + dialog.add_frame_option(_('Missing information'),'',self.date_option) def parse_user_options(self,dialog): """ diff --git a/gramps2/src/plugins/DetDescendantReport.py b/gramps2/src/plugins/DetDescendantReport.py index 3eaaffc61..0cd0c0611 100644 --- a/gramps2/src/plugins/DetDescendantReport.py +++ b/gramps2/src/plugins/DetDescendantReport.py @@ -187,7 +187,7 @@ class DetDescendantReport(Report.Report): if self.pgbrk and generation > 0: self.doc.page_break() self.doc.start_paragraph("DDR-Generation") - text = _("Generation %d") % generation+1 + text = _("Generation %d") % (generation+1) self.doc.write_text(text) self.doc.end_paragraph() if self.childRef: diff --git a/gramps2/src/plugins/ImportGeneWeb.py b/gramps2/src/plugins/ImportGeneWeb.py index f560d492b..84ed39f29 100644 --- a/gramps2/src/plugins/ImportGeneWeb.py +++ b/gramps2/src/plugins/ImportGeneWeb.py @@ -46,11 +46,27 @@ import gtk.glade #------------------------------------------------------------------------- import Errors import RelLib +import Date import const from QuestionDialog import ErrorDialog from DateHandler import parser as _dp from htmlentitydefs import name2codepoint +_date_parse = re.compile('([~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?') +_text_parse = re.compile('0\((.*)\)') + +_mod_map = { + '>' : Date.MOD_AFTER, + '<' : Date.MOD_BEFORE, + '~' : Date.MOD_ABOUT, + } + +_cal_map = { + 'J' : Date.CAL_JULIAN, + 'H' : Date.CAL_HEBREW, + 'F' : Date.CAL_FRENCH, + } + #------------------------------------------------------------------------- # # @@ -242,7 +258,9 @@ class GeneWebParser: elif fields[1] == "f": (idx,child) = self.parse_person(fields,2,RelLib.Person.FEMALE,father_surname) else: - (idx,child) = self.parse_person(fields,1,None,father_surname) + (idx,child) = self.parse_person(fields,1,RelLib.Person.UNKNOWN,father_surname) + + print child.get_gender(),":",fields[1], child.get_primary_name().get_name() if child: self.current_family.add_child_handle(child.get_handle()) @@ -410,10 +428,8 @@ class GeneWebParser: name.set_first_name(firstname) name.set_surname(surname) person.set_primary_name(name) - if gender != None: + if person.get_gender() == RelLib.Person.UNKNOWN and gender != None: person.set_gender(gender) - else: - person.set_gender(RelLib.Person.UNKNOWN) self.db.commit_person(person,self.trans) personDataRe = re.compile("^[0-9<>~#\[({!].*$") dateRe = re.compile("^[0-9~<>?]+.*$") @@ -446,105 +462,107 @@ class GeneWebParser: if fields[idx][0] == '(': #print "Public Name: %s" % fields[idx] public_name = self.decode(fields[idx][1:-1]) - idx = idx + 1 + idx += 1 elif fields[idx][0] == '{': #print "Firstsname Alias: %s" % fields[idx] firstname_aliases.append(self.decode(fields[idx][1:-1])) - idx = idx + 1 + idx += 1 elif fields[idx][0] == '[': print "TODO: Titles: %s" % fields[idx] - idx = idx + 1 + idx += 1 elif fields[idx] == '#nick': - idx = idx + 1 + idx += 1 #print "Nick Name: %s" % fields[idx] nick_names.append(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#occu': - idx = idx + 1 + idx += 1 #print "Occupation: %s" % fields[idx] occu = self.create_event("Occupation",self.decode(fields[idx])) person.add_event_handle(occu.get_handle()) - self.db.commit_person(person,self.trans) - idx = idx + 1 + idx += 1 elif fields[idx] == '#alias': - idx = idx + 1 + idx += 1 #print "Name Alias: %s" % fields[idx] name_aliases.append(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#salias': - idx = idx + 1 + idx += 1 #print "Surname Alias: %s" % fields[idx] surname_aliases.append(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#image': - idx = idx + 1 + idx += 1 #print "Image: %s" % fields[idx] - idx = idx + 1 + idx += 1 elif fields[idx] == '#src': - idx = idx + 1 + idx += 1 #print "Source: %s" % fields[idx] source = self.get_or_create_source(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#bs': - idx = idx + 1 + idx += 1 #print "Birth Source: %s" % fields[idx] birth_source = self.get_or_create_source(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx][0] == '!': #print "Baptize at: %s" % fields[idx] bapt_date = self.parse_date(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#bp': - idx = idx + 1 + idx += 1 #print "Birth Place: %s" % fields[idx] birth_place = self.get_or_create_place(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#pp': - idx = idx + 1 + idx += 1 #print "Baptize Place: %s" % fields[idx] bapt_place = self.get_or_create_place(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#ps': - idx = idx + 1 + idx += 1 #print "Baptize Source: %s" % fields[idx] bapt_source = self.get_or_create_source(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#dp': - idx = idx + 1 + idx += 1 #print "Death Place: %s" % fields[idx] death_place = self.get_or_create_place(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#ds': - idx = idx + 1 + idx += 1 #print "Death Source: %s" % fields[idx] death_source = self.get_or_create_source(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#buri': - idx = idx + 1 + idx += 1 #print "Burial Date: %s" % fields[idx] - bur_date = self.parse_date(self.decode(fields[idx])) - idx = idx + 1 + try: + bur_date = self.parse_date(self.decode(fields[idx])) + except IndexError: + pass + idx += 1 elif fields[idx] == '#crem': - idx = idx + 1 + idx += 1 #print "Cremention Date: %s" % fields[idx] crem_date = self.parse_date(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#rp': - idx = idx + 1 + idx += 1 #print "Burial Place: %s" % fields[idx] bur_place = self.get_or_create_place(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#rs': - idx = idx + 1 + idx += 1 #print "Burial Source: %s" % fields[idx] bur_source = self.get_or_create_source(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 elif fields[idx] == '#apubl': #print "This is a public record" - idx = idx + 1 + idx += 1 elif fields[idx] == '#apriv': #print "This is a private record" - idx = idx + 1 + idx += 1 elif dateRe.match( fields[idx]): if not birth_date: #print "Birth Date: %s" % fields[idx] @@ -552,10 +570,10 @@ class GeneWebParser: else: #print "Death Date: %s" % fields[idx] death_date = self.parse_date(self.decode(fields[idx])) - idx = idx + 1 + idx += 1 else: print "Unknown field '%s' for person in line %d!" % (fields[idx],self.lineno) - idx = idx + 1 + idx += 1 if public_name: name = person.get_primary_name() @@ -633,8 +651,40 @@ class GeneWebParser: def parse_date(self,field): if field == "0": return None - date = _dp.parse(field) - return date + date = Date.Date() + matches = _text_parse.match(field) + if matches: + groups = matches.groups() + date.set_as_text(groups[0]) + date.set_modifier(Date.MOD_TEXTONLY) + return date + + matches = _date_parse.match(field) + if matches: + groups = matches.groups() + mod = _mod_map.get(groups[0],Date.MOD_NONE) + if groups[3] == "..": + mod = Date.MOD_SPAN + cal2 = _cal_map.get(groups[5],Date.CAL_GREGORIAN) + sub2 = self.sub_date(groups[4]) + else: + sub2 = (0,0,0) + cal1 = _cal_map.get(groups[2],Date.CAL_GREGORIAN) + sub1 = self.sub_date(groups[1]) + date.set(Date.QUAL_NONE,mod, cal1, + (sub1[0],sub1[1],sub1[2],None,sub2[0],sub2[1],sub2[2],None)) + return date + else: + return None + + def sub_date(self,data): + vals = data.split('/') + if len(vals) == 1: + return (0,0,int(vals[0])) + elif len(vals) == 2: + return (0,int(vals[0]),int(vals[1])) + else: + return (int(vals[0]),int(vals[1]),int(vals[2])) def create_event(self,type,desc=None,date=None,place=None,source=None): event = RelLib.Event()