From 37b8945a4741ff4ec3901c7086cf52cbd4855b89 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 4 Dec 2002 04:58:07 +0000 Subject: [PATCH] Surname prefix support svn: r1217 --- src/EditPerson.py | 12 +++++ src/GedcomInfo.py | 14 +++++- src/GrampsParser.py | 6 ++- src/ListModel.py | 5 +++ src/RelLib.py | 20 +++++++-- src/WriteXML.py | 10 ++++- src/data/gedcom.xml | 10 +++++ src/dialog.glade | 77 ++++++++++++++++++++++++------- src/edit_person.glade | 92 +++++++++++++++++++++++++++++--------- src/gramps_main.py | 1 + src/plugins/ReadGedcom.py | 2 +- src/plugins/WriteGedcom.py | 27 ++++++++--- src/sort.py | 12 ++--- 13 files changed, 231 insertions(+), 57 deletions(-) diff --git a/src/EditPerson.py b/src/EditPerson.py index 7d647bb25..e719161a4 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -179,10 +179,12 @@ class EditPerson: self.alt_last_field = self.get_widget("alt_last") self.alt_title_field = self.get_widget("alt_title") self.alt_suffix_field = self.get_widget("alt_suffix") + self.alt_prefix_field = self.get_widget("alt_prefix") self.name_type_field = self.get_widget("name_type") self.surname_field = self.get_widget("surname") self.ntype_field = self.get_widget("ntype") self.suffix = self.get_widget("suffix") + self.prefix = self.get_widget("prefix") self.given = self.get_widget("givenName") self.nick = self.get_widget("nickname") self.title = self.get_widget("title") @@ -774,6 +776,7 @@ class EditPerson: surname = self.surname_field.get_text() ntype = self.ntype_field.entry.get_text() suffix = self.suffix.get_text() + prefix = self.prefix.get_text() given = self.given.get_text() nick = self.nick.get_text() title = self.title.get_text() @@ -791,6 +794,8 @@ class EditPerson: changed = 1 if suffix != name.getSuffix(): changed = 1 + if prefix != name.getSurnamePrefix(): + changed = 1 if surname != name.getSurname(): changed = 1 if ntype != name.getType(): @@ -995,6 +1000,7 @@ class EditPerson: self.alt_title_field.set_text(name.getTitle()) self.alt_last_field.set_text(name.getSurname()) self.alt_suffix_field.set_text(name.getSuffix()) + self.alt_prefix_field.set_text(name.getSurnamePrefix()) self.name_type_field.set_text(name.getType()) if len(name.getSourceRefList()) > 0: psrc = name.getSourceRefList()[0] @@ -1010,6 +1016,7 @@ class EditPerson: self.alt_title_field.set_text('') self.alt_last_field.set_text('') self.alt_suffix_field.set_text('') + self.alt_prefix_field.set_text('') self.name_type_field.set_text('') self.name_src_field.set_text('') self.name_conf_field.set_text('') @@ -1104,6 +1111,7 @@ class EditPerson: surname = self.surname_field.get_text() suffix = self.suffix.get_text() + prefix = self.prefix.get_text() ntype = self.ntype_field.entry.get_text() given = self.given.get_text() nick = self.nick.get_text() @@ -1131,6 +1139,9 @@ class EditPerson: if suffix != name.getSuffix(): name.setSuffix(suffix) + if prefix != name.getSurnamePrefix(): + name.setSurnamePrefix(prefix) + if const.NameTypesMap.has_key(ntype): ntype = const.NameTypesMap[ntype] else: @@ -1382,6 +1393,7 @@ class EditPerson: name = GrampsCfg.nameof(self.person) self.get_widget("activepersonTitle").set_text(name) self.suffix.set_text(self.pname.getSuffix()) + self.prefix.set_text(self.pname.getSurnamePrefix()) self.surname_field.set_text(self.pname.getSurname()) self.given.set_text(self.pname.getFirstName()) diff --git a/src/GedcomInfo.py b/src/GedcomInfo.py index a2bb202b0..9b9a3cb4c 100644 --- a/src/GedcomInfo.py +++ b/src/GedcomInfo.py @@ -38,6 +38,8 @@ CALENDAR_NO = 0 CALENDAR_YES = 1 OBJE_NO = 0 OBJE_YES = 1 +PREFIX_NO = 0 +PREFIX_YES = 1 RESIDENCE_ADDR = 0 RESIDENCE_PLAC = 1 @@ -60,7 +62,8 @@ class GedcomDescription: self.resi = RESIDENCE_ADDR self.gramps2tag_map = {} self.tag2gramps_map = {} - + self.prefix = PREFIX_YES + def set_dest(self,val): self.dest = val @@ -73,6 +76,12 @@ class GedcomDescription: def get_adopt(self): return self.adopt + def set_prefix(self,val): + self.prefix=val + + def get_prefix(self): + return self.prefix + def set_conc(self,val): self.conc = val @@ -212,6 +221,9 @@ class GedInfoParser: elif tag == "object_support": if attrs['val'] == 'no': self.current.set_obje(OBJE_NO) + elif tag == "prefix": + if attrs['val'] == 'no': + self.current.set_obje(PREFIX_NO) elif tag == "residence": if attrs['val'] == 'place': self.current.set_resi(RESIDENCE_PLAC) diff --git a/src/GrampsParser.py b/src/GrampsParser.py index fa692f7e7..8ef5e6afd 100644 --- a/src/GrampsParser.py +++ b/src/GrampsParser.py @@ -303,6 +303,10 @@ class GrampsParser: self.name.conf = 2 if attrs.has_key("priv"): self.name.private = int(attrs["priv"]) + + def start_last(self,attrs): + if attrs.has_key('prefix'): + self.name.Prefix = attrs['prefix'] def start_note(self,attrs): self.in_note = 1 @@ -746,7 +750,7 @@ class GrampsParser: "first" : (None, stop_first), "gender" : (None, stop_gender), "header" : (None, None), - "last" : (None, stop_last), + "last" : (start_last, stop_last), "mother" : (start_mother,None), "name" : (start_name, stop_name), "nick" : (None, stop_nick), diff --git a/src/ListModel.py b/src/ListModel.py index 00fca8bcc..93719e276 100644 --- a/src/ListModel.py +++ b/src/ListModel.py @@ -74,6 +74,11 @@ class ListModel: def connect_model(self): self.tree.set_model(self.model) self.model.set_sort_column_id(0,gtk.SORT_ASCENDING) + + def sort(self): + val = self.model.get_sort_column_id() + self.model.set_sort_column_id(val[0],val[1]) + self.model.sort_column_changed() def get_selected(self): return self.selection.get_selected() diff --git a/src/RelLib.py b/src/RelLib.py index 7d037608a..cb4485712 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -821,12 +821,20 @@ class Name(DataObj): self.Suffix = source.Suffix self.Title = source.Title self.type = source.type + self.Prefix = source.Prefix else: self.FirstName = "" self.Surname = "" self.Suffix = "" self.Title = "" self.type = "" + self.Prefix = "" + + def getSurnamePrefix(self): + return self.Prefix + + def setSurnamePrefix(self,val): + self.Prefix = val def setType(self,type): """sets the type of the Name instance""" @@ -872,10 +880,16 @@ class Name(DataObj): """returns a name string built from the components of the Name instance, in the form of Surname, Firstname""" - if (self.Suffix == ""): - return "%s, %s" % (self.Surname, self.FirstName) + if self.Suffix: + if self.Prefix: + return "%s %s, %s %s" % (self.Prefix, self.Surname, self.FirstName, self.Suffix) + else: + return "%s, %s %s" % (self.Surname, self.FirstName, self.Suffix) else: - return "%s, %s %s" % (self.Surname, self.FirstName, self.Suffix) + if self.Prefix: + return "%s %s, %s" % (self.Prefix,self.Surname, self.FirstName) + else: + return "%s, %s" % (self.Surname, self.FirstName) def getRegularName(self): """returns a name string built from the components of the Name diff --git a/src/WriteXML.py b/src/WriteXML.py index 3da4442d6..17bfdad6e 100644 --- a/src/WriteXML.py +++ b/src/WriteXML.py @@ -437,6 +437,14 @@ class XmlWriter: else: self.g.write('>\n') + def write_last(self,name,indent=1): + p = name.Prefix + n = name.Surname + if p: + self.g.write('%s%s\n' % (' '*indent,p,self.fix(n))) + else: + self.g.write('%s%s\n' % (' '*indent,self.fix(n))) + def write_line(self,label,value,indent=1): if value: self.g.write('%s<%s>%s\n' % (' '*indent,label,self.fix(value),label)) @@ -486,7 +494,7 @@ class XmlWriter: else: self.g.write('%s<%s%s>\n' % (sp,label,conf_priv(name))) self.write_line("first",name.getFirstName(),index+1) - self.write_line("last",name.getSurname(),index+1) + self.write_last(name,index+1) self.write_line("suffix",name.getSuffix(),index+1) self.write_line("title",name.getTitle(),index+1) if name.getNote() != "": diff --git a/src/data/gedcom.xml b/src/data/gedcom.xml index 53923950f..1f55efb03 100644 --- a/src/data/gedcom.xml +++ b/src/data/gedcom.xml @@ -5,6 +5,7 @@ + @@ -16,6 +17,7 @@ + @@ -27,6 +29,7 @@ + @@ -42,6 +45,7 @@ + @@ -53,6 +57,7 @@ + @@ -63,6 +68,7 @@ + @@ -75,6 +81,7 @@ + @@ -86,6 +93,7 @@ + @@ -97,6 +105,7 @@ + @@ -108,6 +117,7 @@ + diff --git a/src/dialog.glade b/src/dialog.glade index 2c33bb13c..124c31218 100644 --- a/src/dialog.glade +++ b/src/dialog.glade @@ -2546,7 +2546,7 @@ True - 6 + 7 2 False 0 @@ -2617,8 +2617,8 @@ 0 1 - 2 - 3 + 3 + 4 fill @@ -2639,8 +2639,8 @@ 1 2 - 2 - 3 + 3 + 4 3 3 @@ -2751,8 +2751,8 @@ 0 1 - 4 - 5 + 5 + 6 fill @@ -2857,8 +2857,8 @@ 1 2 - 4 - 5 + 5 + 6 3 3 @@ -2882,8 +2882,8 @@ 0 1 - 3 - 4 + 4 + 5 fill @@ -2904,8 +2904,8 @@ 1 2 - 3 - 4 + 4 + 5 3 3 @@ -2926,12 +2926,59 @@ 1 2 - 5 - 6 + 6 + 7 fill + + + + True + Surname Prefix + False + False + GTK_JUSTIFY_CENTER + False + False + 1 + 0.5 + 5 + 8 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + 3 + 3 + + + False diff --git a/src/edit_person.glade b/src/edit_person.glade index f06bf7a7c..3ef1a8920 100644 --- a/src/edit_person.glade +++ b/src/edit_person.glade @@ -729,7 +729,7 @@ True - 6 + 7 3 False 0 @@ -778,8 +778,8 @@ 0 1 - 2 - 3 + 3 + 4 5 5 fill @@ -804,8 +804,8 @@ 0 1 - 3 - 4 + 4 + 5 5 5 fill @@ -830,8 +830,8 @@ 0 1 - 4 - 5 + 5 + 6 5 5 fill @@ -880,8 +880,8 @@ 1 3 - 4 - 5 + 5 + 6 3 3 @@ -927,8 +927,8 @@ 1 2 - 2 - 3 + 3 + 4 3 3 @@ -948,8 +948,8 @@ 2 3 - 2 - 3 + 3 + 4 3 3 @@ -972,8 +972,8 @@ 1 2 - 3 - 4 + 4 + 5 3 3 @@ -993,8 +993,8 @@ 2 3 - 3 - 4 + 4 + 5 3 3 fill @@ -1019,8 +1019,8 @@ 0 1 - 5 - 6 + 6 + 7 5 5 fill @@ -1105,8 +1105,8 @@ 1 3 - 5 - 6 + 6 + 7 3 3 @@ -1153,6 +1153,55 @@ + + + + True + Surname Prefix + False + False + GTK_JUSTIFY_CENTER + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 2 + 3 + 5 + 5 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 3 + 2 + 3 + 3 + 3 + + + @@ -1194,6 +1243,7 @@ + 275 True 0.5 0.5 diff --git a/src/gramps_main.py b/src/gramps_main.py index d558ff3d8..e82607f03 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -1217,6 +1217,7 @@ class Gramps: if change: self.change_active_person(person) self.goto_active_person() + model.sort() def redisplay_person_list(self,person): self.add_to_person_list(person,1) diff --git a/src/plugins/ReadGedcom.py b/src/plugins/ReadGedcom.py index ee4e0eeea..c519fe47a 100644 --- a/src/plugins/ReadGedcom.py +++ b/src/plugins/ReadGedcom.py @@ -1339,7 +1339,7 @@ class GedcomParser: elif matches[1] == "GIVN": name.setFirstName(matches[2]) elif matches[1] == "SPFX": - pass + name.setSurnamePrefix(matches[2]) elif matches[1] == "SURN": name.setSurname(matches[2]) self.db.addSurname(matches[2]) diff --git a/src/plugins/WriteGedcom.py b/src/plugins/WriteGedcom.py index 6872efe62..6eda24a14 100644 --- a/src/plugins/WriteGedcom.py +++ b/src/plugins/WriteGedcom.py @@ -379,7 +379,8 @@ class GedcomWriter: self.cal = self.target_ged.get_alt_calendar() self.obje = self.target_ged.get_obje() self.resi = self.target_ged.get_resi() - + self.prefix = self.target_ged.get_prefix() + if self.topDialog.get_widget("ansel").get_active(): self.cnvtxt = latin_to_ansel else: @@ -892,17 +893,33 @@ class GedcomWriter: def write_person_name(self,name,nick): firstName = self.cnvtxt(name.getFirstName()) surName = self.cnvtxt(name.getSurname()) + surPref = self.cnvtxt(name.getSurnamePrefix()) suffix = self.cnvtxt(name.getSuffix()) title = self.cnvtxt(name.getTitle()) if suffix == "": - self.g.write("1 NAME %s /%s/\n" % (firstName,surName)) + if surPref: + self.g.write("1 NAME %s /%s/\n" % (firstName,surName)) + else: + self.g.write("1 NAME %s /%s %s/\n" % (firstName,surPref,surName)) else: - self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName, suffix)) + if surPref: + self.g.write("1 NAME %s /%s %s/, %s\n" % (firstName,surPref,surName,suffix)) + else: + self.g.write("1 NAME %s /%s/, %s\n" % (firstName,surName,suffix)) if name.getFirstName() != "": self.g.write("2 GIVN %s\n" % firstName) - if name.getSurname() != "": - self.g.write("2 SURN %s\n" % surName) + if self.prefix: + if surPref: + self.g.write('2 SPFX %s\n' % surPref) + if surName != "": + self.g.write("2 SURN %s\n" % surName) + else: + if surPref: + self.g.write("2 SURN %s %s\n" % (surPref,surName)) + else if surName: + self.g.write("2 SURN %s\n" % surName) + if name.getSuffix() != "": self.g.write("2 NSFX %s\n" % suffix) if name.getTitle() != "": diff --git a/src/sort.py b/src/sort.py index 02974f24e..3d7ef49a5 100644 --- a/src/sort.py +++ b/src/sort.py @@ -39,8 +39,6 @@ import Date #------------------------------------------------------------------------- su = string.upper -sp = string.split - _plist = [ 'de', 'van', 'von', 'la', 'di', 'le', 'du' ] @@ -52,14 +50,10 @@ def build_sort_name(n): """Builds a name from a RelLib.Name instance that is suitable for use as a sort key in a GtkCList. The name is converted to upper case to provide for case-insenstive sorting""" - l = string.split(n.Surname) - if len(l) > 1 and _prefix.has_key(l[0].lower()): - return "%-25s%-30s%s" % (su(l[1]),su(n.FirstName),su(n.Suffix)) + if n.Surname: + return "%-25s%-30s%s" % (su(n.Surname),su(n.FirstName),su(n.Suffix)) else: - if n.Surname: - return "%-25s%-30s%s" % (su(n.Surname),su(n.FirstName),su(n.Suffix)) - else: - return "%s" % chr(255) + return "%s" % chr(255) def build_sort_date(n):