From e4f6e7482ccfe9f37380543a08c6cb7a5107df12 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 31 May 2001 21:57:54 +0000 Subject: [PATCH] Improved the GEDCOM import svn: r73 --- gramps/src/gramps_main.py | 1 - gramps/src/plugins/ReadGedcom.py | 176 +++++++--- gramps/src/plugins/gedcomimport.glade | 463 ++++++++++++++++++++++++-- 3 files changed, 552 insertions(+), 88 deletions(-) diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 30b792948..6736e6d4e 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -1573,7 +1573,6 @@ def on_filter_name_changed(obj): def on_spouselist_changed(obj): if active_person == None : return - display_marriage(obj.get_data("family")) #------------------------------------------------------------------------- diff --git a/gramps/src/plugins/ReadGedcom.py b/gramps/src/plugins/ReadGedcom.py index f99803965..e9ccac8cf 100644 --- a/gramps/src/plugins/ReadGedcom.py +++ b/gramps/src/plugins/ReadGedcom.py @@ -45,9 +45,6 @@ db = None callback = None glade_file = None clear_data = 0 -in_obje = 0 - -InvalidGedcom = "Invalid GEDCOM file" ged2rel = {} for val in const.personalConstantEvents.keys(): @@ -61,6 +58,14 @@ for val in const.familyConstantEvents.keys(): if key != "": ged2fam[key] = val +lineRE = re.compile(r"\s*(\d+)\s+(\S+)\s*(.*)$") +nameRegexp = re.compile(r"([\S\s]*\S)?\s*/([^/]+)?/\s*,?\s*([\S]+)?") + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- def find_file(fullname,altpath): if os.path.isfile(fullname): return fullname @@ -70,9 +75,6 @@ def find_file(fullname,altpath): else: return "" -lineRE = re.compile(r"\s*(\d+)\s+(\S+)\s*(.*)$") -nameRegexp = re.compile(r"([\S\s]*\S)?\s*/([^/]+)?/\s*,?\s*([\S]+)?") - #------------------------------------------------------------------------- # # @@ -90,12 +92,17 @@ def importData(database, filename): if clear_data == 1: database.new() - g = GedcomParser(database,filename) + statusTop = GladeXML(glade_file,"status") + statusWindow = statusTop.get_widget("status") + statusTop.get_widget("close").set_sensitive(0) + statusTop.signal_autoconnect({ + "destroy_passed_object" : utils.destroy_passed_object + }) + + g = GedcomParser(database,filename,statusTop) g.parse_gedcom_file() -# statusTop = GladeXML(glade_file,"status") -# statusWindow = statusTop.get_widget("status") -# progressWindow = statusTop.get_widget("progress") + statusTop.get_widget("close").set_sensitive(1) utils.modified() callback(1) @@ -140,7 +147,7 @@ class GedcomParser: # # #--------------------------------------------------------------------- - def __init__(self,db, file): + def __init__(self, db, file, window): self.db = db self.person = None self.pmap = {} @@ -150,9 +157,34 @@ class GedcomParser: f = open(file,"r") self.lines = f.readlines() f.close() + + self.file_obj = window.get_widget("file") + self.encoding_obj = window.get_widget("encoding") + self.created_obj = window.get_widget("created") + self.version_obj = window.get_widget("version") + self.families_obj = window.get_widget("families") + self.people_obj = window.get_widget("people") + self.errors_obj = window.get_widget("errors") + self.error_text_obj = window.get_widget("error_text") + self.error_count = 0 + self.error_text_obj.set_point(0) + self.error_text_obj.set_word_wrap(0) + + self.update(self.file_obj,file) + self.index = 0 self.code = 0 + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- + def update(self,field,text): + field.set_text(text) + while events_pending(): + mainiteration() + #--------------------------------------------------------------------- # # @@ -170,8 +202,18 @@ class GedcomParser: self.index = self.index + 1 return match.groups() + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def barf(self,level): - print "IGNORED (%d): %s" % (self.index, self.lines[self.index-1]) + msg = _("Warning: line %d was not understood, so it was ignored.") % self.index + self.error_text_obj.insert_defaults(msg) + msg = "\n\t%s\n" % self.lines[self.index-1] + self.error_text_obj.insert_defaults(msg) + self.error_count = self.error_count + 1 + self.update(self.errors_obj,str(self.error_count)) self.ignore_sub_junk(level) #--------------------------------------------------------------------- @@ -189,10 +231,14 @@ class GedcomParser: #--------------------------------------------------------------------- def parse_gedcom_file(self): self.index = 0 + self.fam_count = 0 + self.indi_count = 0 self.parse_header() self.parse_submitter() self.parse_record() self.parse_trailer() + self.update(self.families_obj,str(self.fam_count)) + self.update(self.people_obj,str(self.indi_count)) #--------------------------------------------------------------------- # @@ -274,13 +320,20 @@ class GedcomParser: # #--------------------------------------------------------------------- def parse_record(self): + index = 0 while 1: matches = self.get_next() if matches[2] == "FAM": + if self.fam_count % 10 == 0: + self.update(self.families_obj,str(self.fam_count)) + self.fam_count = self.fam_count + 1 self.family = self.db.findFamily(matches[1],self.fmap) self.parse_family() elif matches[2] == "INDI": + if self.indi_count % 10 == 0: + self.update(self.people_obj,str(self.indi_count)) + self.indi_count = self.indi_count + 1 self.person = self.db.findPerson(matches[1],self.pmap) self.parse_individual() elif matches[2] == "SUBM": @@ -290,7 +343,6 @@ class GedcomParser: elif matches[2] == "SOUR": self.parse_source(matches[1],1) elif matches[2] == "REPO": - print "REPO",matches[1] self.ignore_sub_junk(1) elif matches[2][0:4] == "NOTE": if self.nmap.has_key(matches[1]): @@ -335,32 +387,6 @@ class GedcomParser: else: self.barf(level+1) - #--------------------------------------------------------------------- - # - # - # - #--------------------------------------------------------------------- - def parse_source_citation(self,level): - while 1: - matches = self.get_next() - if int(matches[0]) < level: - self.backup() - return - elif matches[1] == "PAGE": - pass - elif matches[1] == "EVEN": - self.ignore_sub_junk(level+1) - elif matches[1] == "DATA": - self.ignore_sub_junk(level+1) - elif matches[1] == "QUAY": - pass - elif matches[1] == "NOTE": - note = matches[1] + self.parse_continue_data(level+1) - self.ignore_change_data(level+1) - pass - else: - self.barf(level+1) - #--------------------------------------------------------------------- # # @@ -386,6 +412,8 @@ class GedcomParser: pass elif matches[1] == "REFN" or matches[1] == "CHAN": self.ignore_sub_junk(2) + elif matches[1] == "SOUR": + self.ignore_sub_junk(2) elif matches[1] == "MARR": event = Event() event.setName("Marriage") @@ -487,7 +515,10 @@ class GedcomParser: type,note = self.parse_famc_type(2) family = self.db.findFamily(matches[2],self.fmap) if type == "" or type == "Birth": - self.person.setMainFamily(family) + if self.person.getMainFamily() == None: + self.person.setMainFamily(family) + else: + self.person.addAltFamily(family,"unknown") else: self.person.addAltFamily(family,type) elif matches[1] == "RESI": @@ -532,6 +563,11 @@ class GedcomParser: self.person.addEvent(event) self.parse_person_event(event,2) + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def parse_optional_note(self,level): note = "" while 1: @@ -549,6 +585,11 @@ class GedcomParser: else: self.barf(level+1) + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def parse_famc_type(self,level): type = "" note = "" @@ -560,6 +601,8 @@ class GedcomParser: return (string.capitalize(type),note) elif matches[1] == "PEDI": type = matches[2] + elif matches[1] == "_PRIMARY": + type = matches[1] elif matches[1] == "NOTE": if matches[2] and matches[2][0] != "@": note = matches[2] + self.parse_continue_data(level+1) @@ -569,6 +612,11 @@ class GedcomParser: else: self.barf(level+1) + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def parse_person_object(self,level): form = "" file = "" @@ -642,6 +690,11 @@ class GedcomParser: else: self.barf(level+1) + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def parse_address(self,address,level): first = 0 while 1: @@ -744,7 +797,9 @@ class GedcomParser: self.ignore_sub_junk(level+1) elif matches[1] == "STAT" or matches[1] == "TEMP": self.ignore_sub_junk(level+1) - elif matches[1] == "OBJE": + elif matches[1] == "HUSB" or matches[1] == "WIFE": + self.ignore_sub_junk(level+1) + elif matches[1] == "OBJE" or matches[1] == "QUAY": self.ignore_sub_junk(level+1) elif matches[1] == "SOUR": source_ref = SourceRef() @@ -769,6 +824,11 @@ class GedcomParser: else: self.barf(level+1) + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- def parse_source_reference(self,source,level): while 1: matches = self.get_next() @@ -777,7 +837,7 @@ class GedcomParser: self.backup() return elif matches[1] == "PAGE": - source.setPage(matches[2]) + source.setPage(matches[2] + self.parse_continue_data(level+1)) elif matches[1] == "DATA": date,text = self.parse_source_data(level+1) d = Date() @@ -802,6 +862,11 @@ class GedcomParser: self.barf(level+1) def parse_source_data(self,level): + #--------------------------------------------------------------------- + # + # + # + #--------------------------------------------------------------------- date = "" note = "" while 1: @@ -831,19 +896,21 @@ class GedcomParser: self.backup() return elif matches[1] == "NPFX": - name.setTitle(matches[1]) + name.setTitle(matches[2]) elif matches[1] == "GIVN": - name.setFirstName(matches[1]) + name.setFirstName(matches[2]) elif matches[1] == "SPFX": pass elif matches[1] == "SURN": - name.setSurname(matches[1]) + name.setSurname(matches[2]) elif matches[1] == "NSFX": - name.setSuffix(matches[1]) + name.setSuffix(matches[2]) elif matches[1] == "NICK": - self.person.setNickName(matches[1]) + self.person.setNickName(matches[2]) elif matches[1] == "SOUR": self.ignore_sub_junk(level+1) + elif matches[1] == "NOTE": + self.ignore_sub_junk(level+1) else: self.barf(level+1) @@ -871,15 +938,15 @@ class GedcomParser: self.backup() return elif matches[1] == "SOUR": - print "Source is",matches[2] + if self.created_obj.get_text() == "": + self.update(self.created_obj,matches[2]) elif matches[1] == "NAME": - print "Name is",matches[2] + self.update(self.created_obj,matches[2]) elif matches[1] == "VERS": - print "Version is",matches[2] + self.update(self.version_obj,matches[2]) elif matches[1] == "CORP": self.ignore_sub_junk(2) elif matches[1] == "DATA": - print "Data is",matches[2] self.parse_sub_data(3) elif matches[1] == "SUBM": pass @@ -898,12 +965,13 @@ class GedcomParser: elif matches[2] == "ANSEL": self.code = ANSEL self.ignore_sub_junk(2) + self.update(self.encoding_obj,matches[2]) elif matches[1] == "GEDC": self.ignore_sub_junk(2) elif matches[1] == "_SCHEMA": self.parse_ftw_schema(2) elif matches[1] == "LANG": - print "Language is",matches[2] + pass elif matches[1] == "PLAC": self.parse_place_form(2) elif matches[1] == "DATE": @@ -1028,9 +1096,7 @@ class GedcomParser: if int(matches[0]) < level: self.backup() return - elif matches[1] == "FORM": - print "FORM",matches[2] - else: + elif matches[1] != "FORM": self.barf(level+1) #--------------------------------------------------------------------- diff --git a/gramps/src/plugins/gedcomimport.glade b/gramps/src/plugins/gedcomimport.glade index b53c6c735..e77313ca4 100644 --- a/gramps/src/plugins/gedcomimport.glade +++ b/gramps/src/plugins/gedcomimport.glade @@ -18,21 +18,22 @@ GEDCOM Import Status GTK_WINDOW_TOPLEVEL GTK_WIN_POS_CENTER - False + True False True False GtkVBox - vbox2 + vbox5 False 0 GtkLabel - label2 - + label5 + 500 + GTK_JUSTIFY_CENTER False 0.5 @@ -40,50 +41,448 @@ 0 0 - 20 + 10 False False - GtkHBox - hbox1 - False - 0 + GtkHSeparator + hseparator4 - 20 + 0 False - False + True + + + + + GtkTable + table1 + 7 + 2 + False + 0 + 0 + + 0 + True + True - Placeholder - - - - GtkProgressBar - progress - 250 - 0 - 0 - 100 - GTK_PROGRESS_CONTINUOUS - GTK_PROGRESS_LEFT_TO_RIGHT - False - True - %P %% - 0.5 - 0.5 + GtkLabel + label6 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 - 20 - True - False + 0 + 1 + 0 + 1 + 0 + 0 + False + False + False + False + True + False - Placeholder + GtkLabel + label7 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label8 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 2 + 3 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label9 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 4 + 5 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label10 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 5 + 6 + 0 + 0 + False + False + False + False + True + False + + + + + GtkEntry + file + True + False + True + 0 + + + 1 + 2 + 0 + 1 + 5 + 5 + True + False + False + False + True + False + + + + + GtkEntry + created + True + False + True + 0 + + + 1 + 2 + 1 + 2 + 5 + 5 + True + False + False + False + True + False + + + + + GtkEntry + version + True + False + True + 0 + + + 1 + 2 + 2 + 3 + 5 + 5 + True + False + False + False + True + False + + + + + GtkEntry + families + True + False + True + 0 + + + 1 + 2 + 4 + 5 + 5 + 5 + True + False + False + False + True + False + + + + + GtkEntry + people + True + False + True + 0 + + + 1 + 2 + 5 + 6 + 5 + 5 + True + False + False + False + True + False + + + + + GtkLabel + label11 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 6 + 7 + 0 + 0 + False + False + False + False + True + False + + + + + GtkEntry + errors + True + False + True + 0 + + + 1 + 2 + 6 + 7 + 5 + 5 + True + False + False + False + True + False + + + + + GtkLabel + label12 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 3 + 4 + 0 + 0 + False + False + False + False + True + False + + + + + GtkEntry + encoding + True + False + True + 0 + + + 1 + 2 + 3 + 4 + 5 + 5 + True + False + False + False + True + False + + + + + + GtkScrolledWindow + scrolledwindow1 + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + 0 + True + True + + + + GtkText + error_text + 146 + True + False + + + + + + GtkHSeparator + hseparator5 + + 0 + True + True + + + + + GtkHButtonBox + hbuttonbox2 + GTK_BUTTONBOX_END + 30 + 85 + 27 + 7 + 0 + + 0 + True + True + + + + GtkButton + close + True + True + + clicked + destroy_passed_object + status + Thu, 31 May 2001 19:35:57 GMT + + GNOME_STOCK_BUTTON_CLOSE + GTK_RELIEF_NORMAL