From 5f0138f0d9fdfec70e71eaccaee99adf4b96e5ac Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 14 Oct 2003 03:13:52 +0000 Subject: [PATCH] * src/GrampsParser.py: handle new witness format in XML file * src/WriteXML.py: handle new witness format in XML file * src/dialog.glade: removed unused callbacks svn: r2251 --- src/GrampsParser.py | 53 +++++++++++++++++++++++++++++++++------------ src/WriteXML.py | 26 ++++++++++++++-------- src/dialog.glade | 2 -- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/GrampsParser.py b/src/GrampsParser.py index 8e39945f6..b7988614e 100644 --- a/src/GrampsParser.py +++ b/src/GrampsParser.py @@ -61,6 +61,7 @@ class GrampsParser: self.in_note = 0 self.in_stext = 0 self.in_scomments = 0 + self.in_witness = 0 self.db = database self.base = base self.photo = None @@ -100,6 +101,7 @@ class GrampsParser: self.func_list = [None]*50 self.func_index = 0 self.func = None + self.witness_comment = "" self.func_map = { "address" : (self.start_address, self.stop_address), @@ -116,7 +118,9 @@ class GrampsParser: "childof" : (self.start_childof,None), "city" : (None, self.stop_city), "country" : (None, self.stop_country), + "comment" : (None, self.stop_comment), "created" : (self.start_created, None), + "ref" : (None, self.stop_ref), "database" : (None, None), "date" : (None, self.stop_date), "cause" : (None, self.stop_cause), @@ -267,9 +271,11 @@ class GrampsParser: self.locations = self.locations + 1 def start_witness(self,attrs): + self.in_witness = 1 if attrs.has_key('ref'): self.witness = RelLib.Witness(RelLib.Event.ID,attrs['ref']) if attrs.has_key('name'): + print "name",attrs['name'] self.witness = RelLib.Witness(RelLib.Event.NAME,attrs['name']) def start_coord(self,attrs): @@ -392,15 +398,16 @@ class GrampsParser: self.person.FamilyList.append(self.db.findFamilyNoMap(attrs["ref"])) def start_name(self,attrs): - self.name = RelLib.Name() - if attrs.has_key("type"): - self.name.setType(attrs["type"]) - if attrs.has_key("conf"): - self.name.conf = int(attrs["conf"]) - else: - self.name.conf = 2 - if attrs.has_key("priv"): - self.name.private = int(attrs["priv"]) + if not self.in_witness: + self.name = RelLib.Name() + if attrs.has_key("type"): + self.name.setType(attrs["type"]) + if attrs.has_key("conf"): + self.name.conf = int(attrs["conf"]) + else: + 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'): @@ -581,9 +588,21 @@ class GrampsParser: def stop_attribute(self,tag): self.attribute = None + def stop_comment(self,tag): + if tag.strip(): + self.witness_comment = tag + else: + self.witness_comment = "" + def stop_witness(self,tag): - self.witness.set_comment(tag) + if self.witness_comment: + self.witness.set_comment(self.witness_comment) + elif tag.strip(): + self.witness.set_comment(tag) + else: + self.witness.set_comment("") self.event.add_witness(self.witness) + self.in_witness = 0 def stop_attr_type(self,tag): self.attribute.setType(tag) @@ -622,10 +641,16 @@ class GrampsParser: self.event = None def stop_name(self,tag): - if self.name.getType() == "": - self.name.setType("Birth Name") - self.person.setPrimaryName (self.name) - self.name = None + if self.in_witness: + self.witness = RelLib.Witness(RelLib.Event.NAME,tag) + else: + if self.name.getType() == "": + self.name.setType("Birth Name") + self.person.setPrimaryName (self.name) + self.name = None + + def stop_ref(self,tag): + self.witness = RelLib.Witness(RelLib.Event.ID,tag) def stop_place(self,tag): if self.placeobj == None: diff --git a/src/WriteXML.py b/src/WriteXML.py index f9912bdea..e18263815 100644 --- a/src/WriteXML.py +++ b/src/WriteXML.py @@ -171,9 +171,9 @@ class XmlWriter: total = person_len + family_len + place_len + source_len - self.g.write('\n') + self.g.write('\n') self.g.write('\n') - self.g.write("\n") + self.g.write("\n") self.g.write("
\n") self.g.write(" \n") def fix(self,line): - l = string.strip(line) - l = string.replace(l,'&','&') - l = string.replace(l,'>','>') - l = string.replace(l,'<','<') - return string.replace(l,'"','"') + l = line.strip() + l = l.replace('&','&') + l = l.replace('>','>') + l = l.replace('<','<') + return l.replace('"','"') def write_note(self,val,note,indent=0): if not note: @@ -387,9 +387,17 @@ class XmlWriter: sp = " "*index com = self.fix(w.get_comment()) if w.get_type() == RelLib.Event.ID: - self.g.write('%s%s\n' % (sp,w.get_value(),com)) + self.g.write('%s\n' % sp) + self.g.write(' %s%s\n' % (sp,w.get_value())) + if com: + self.g.write(' %s%s\n' % (sp,com)) + self.g.write('%s\n' % sp) else: - self.g.write('%s%s\n' % (sp,w.get_value(),com)) + self.g.write('%s\n' % sp) + self.g.write(' %s%s\n' % (sp,w.get_value())) + if com: + self.g.write(' %s%s\n' % (sp,com)) + self.g.write('%s\n' % sp) def dump_my_event(self,name,event,index=1): if not event or event.is_empty(): diff --git a/src/dialog.glade b/src/dialog.glade index 7ef87e771..3cbd98743 100644 --- a/src/dialog.glade +++ b/src/dialog.glade @@ -3551,7 +3551,6 @@ True GTK_RELIEF_NORMAL -6 - @@ -3564,7 +3563,6 @@ True GTK_RELIEF_NORMAL -5 -