diff --git a/gramps/src/GrampsParser.py b/gramps/src/GrampsParser.py index 37661db45..03667eb9a 100644 --- a/gramps/src/GrampsParser.py +++ b/gramps/src/GrampsParser.py @@ -74,7 +74,6 @@ class GrampsParser(handler.ContentHandler): #--------------------------------------------------------------------- def __init__(self,database,callback,base): - self.call = None self.stext_list = [] self.scomments_list = [] self.note_list = [] @@ -202,11 +201,11 @@ class GrampsParser(handler.ContentHandler): #--------------------------------------------------------------------- def start_event(self,attrs): self.event = Event() - self.event_type = u2l(string.capwords(attrs["type"])) + self.event_type = u2l(attrs["type"]) if attrs.has_key("conf"): - self.event.confidence = string.atoi(attrs["conf"]) + self.event.confidence = int(attrs["conf"]) if attrs.has_key("priv"): - self.event.private = string.atoi(attrs["priv"]) + self.event.private = int(attrs["priv"]) #--------------------------------------------------------------------- # @@ -216,12 +215,12 @@ class GrampsParser(handler.ContentHandler): def start_attribute(self,attrs): self.attribute = Attribute() if attrs.has_key("conf"): - self.attribute.confidence = string.atoi(attrs["conf"]) + self.attribute.confidence = int(attrs["conf"]) if attrs.has_key("priv"): - self.attribute.privacy = string.atoi(attrs["priv"]) + self.attribute.privacy = int(attrs["priv"]) if attrs.has_key('type'): self.in_old_attr = 1 - self.attribute.setType(u2l(string.capwords(attrs["type"]))) + self.attribute.setType(u2l(attrs["type"])) else: self.in_old_attr = 0 if self.person: @@ -238,9 +237,9 @@ class GrampsParser(handler.ContentHandler): self.address = Address() self.person.addAddress(self.address) if attrs.has_key("conf"): - self.address.confidence = string.atoi(attrs["conf"]) + self.address.confidence = int(attrs["conf"]) if attrs.has_key("priv"): - self.address.private = string.atoi(attrs["priv"]) + self.address.private = int(attrs["priv"]) #--------------------------------------------------------------------- # @@ -257,7 +256,7 @@ class GrampsParser(handler.ContentHandler): # #--------------------------------------------------------------------- def start_person(self,attrs): - if self.count % self.increment == 0: + if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 self.person = self.db.findPersonNoMap(u2l(attrs["id"])) @@ -314,7 +313,7 @@ class GrampsParser(handler.ContentHandler): url.set_path(u2l(attrs["href"])) url.set_description(desc) if attrs.has_key("priv"): - url.setPrivacy(string.atoi(attrs['priv'])) + url.setPrivacy(int(attrs['priv'])) if self.person: self.person.addUrl(url) elif self.placeobj: @@ -328,7 +327,7 @@ class GrampsParser(handler.ContentHandler): # #--------------------------------------------------------------------- def start_family(self,attrs): - if self.count % self.increment == 0: + if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 self.family = self.db.findFamilyNoMap(u2l(attrs["id"])) @@ -379,9 +378,9 @@ class GrampsParser(handler.ContentHandler): def start_name(self,attrs): self.name = Name() if attrs.has_key("conf"): - self.name.confidence = string.atoi(attrs["conf"]) + self.name.confidence = int(attrs["conf"]) if attrs.has_key("priv"): - self.name.private = string.atoi(attrs["priv"]) + self.name.private = int(attrs["priv"]) #--------------------------------------------------------------------- # @@ -517,14 +516,15 @@ class GrampsParser(handler.ContentHandler): def stop_event(self,tag): self.event.name = self.event_type - if self.event_type == "Birth": - self.person.setBirth(self.event) - elif self.event_type == "Death": - self.person.setDeath(self.event) - elif self.person: - self.person.EventList.append(self.event) - else: + if self.family: self.family.EventList.append(self.event) + else: + if self.event_type == "Birth": + self.person.setBirth(self.event) + elif self.event_type == "Death": + self.person.setDeath(self.event) + else: + self.person.EventList.append(self.event) self.event = None #--------------------------------------------------------------------- @@ -884,6 +884,8 @@ class GrampsParser(handler.ContentHandler): func_map = { "address" : (start_address, stop_address), + "addresses" : (None,None), + "childlist" : (None,None), "aka" : (start_name, stop_aka), "attribute" : (start_attribute, stop_attribute), "attr_type" : (None,stop_attr_type), @@ -986,8 +988,6 @@ class GrampsParser(handler.ContentHandler): if self.func: self.data = self.data + data - - #------------------------------------------------------------------------- # # Gramps database parsing class. Derived from SAX XML parser @@ -1010,7 +1010,7 @@ class GrampsImportParser(GrampsParser): # #--------------------------------------------------------------------- def start_person(self,attrs): - if self.count % self.increment == 0: + if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 self.person = self.db.findPerson("x%s" % u2l(attrs["id"]),self.pmap) @@ -1048,7 +1048,7 @@ class GrampsImportParser(GrampsParser): # #--------------------------------------------------------------------- def start_family(self,attrs): - if self.count % self.increment == 0: + if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 self.family = self.db.findFamily(u2l(attrs["id"]),self.fmap) diff --git a/gramps/src/ReadXML.py b/gramps/src/ReadXML.py index d41b01e50..9acb4c471 100644 --- a/gramps/src/ReadXML.py +++ b/gramps/src/ReadXML.py @@ -106,7 +106,7 @@ def importData(database, filename, callback): # of data. # #------------------------------------------------------------------------- -def loadData(database, filename, callback): +def loadData(database, filename, callback=None): basefile = os.path.dirname(filename) database.smap = {} @@ -133,7 +133,8 @@ def loadData(database, filename, callback): else: xml_file = open(filename,"r") except IOError,msg: - GnomeErrorDialog(_("%s could not be opened\n") % filename + str(msg)) + filemsg = _("%s could not be opened\n") % filename + GnomeErrorDialog(filemsg + str(msg)) return 0 except: GnomeErrorDialog(_("%s could not be opened\n") % filename) @@ -149,7 +150,8 @@ def loadData(database, filename, callback): GnomeErrorDialog("%s\n%s" % (filemsg,errmsg)) return 0 except IOError,msg: - GnomeErrorDialog(_("Error reading %s") % filename + "\n" + str(msg)) + errmsg = "%s\n%s" % (_("Error reading %s"),filename,str(msg)) + GnomeErrorDialog(errmsg) import traceback traceback.print_exc() return 0 @@ -161,3 +163,16 @@ def loadData(database, filename, callback): xml_file.close() return 1 + + +if __name__ == "__main__": + import sys + import time + import profile + + database = RelDataBase() + t1 = time.time() + #profile.run('loadData(database, sys.argv[1])') + loadData(database,sys.argv[1]) + t2 = time.time() + print t2-t1 diff --git a/gramps/src/const.py b/gramps/src/const.py index d04757477..054ce8482 100644 --- a/gramps/src/const.py +++ b/gramps/src/const.py @@ -377,6 +377,14 @@ def save_fattr(st): # #------------------------------------------------------------------------- +_frel2def = { + _("Married") : _("A legal or common-law relationship between a husband and wife"), + _("Unmarried"): _("No legal or common-law relationship between man and woman"), + _("Partners") : _("An established relationship between members of the same sex"), + _("Unknown") : _("Unknown relationship between a man and woman"), + _("Other") : _("An unspecified relationship between a man and woman") +} + _fr_e2l = { "Married" : _("Married"), "Unmarried" : _("Unmarried"), @@ -389,6 +397,17 @@ _fr_l2e = {} for a in _fa_e2l.keys(): _fa_l2e[_fa_e2l[a]] = a +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def relationship_def(txt): + if _frel2def.has_key(txt): + return _frel2def[txt] + else: + return _("No definition available") + #------------------------------------------------------------------------- # # diff --git a/gramps/src/gramps.glade b/gramps/src/gramps.glade index 241437d60..9e10f8644 100644 --- a/gramps/src/gramps.glade +++ b/gramps/src/gramps.glade @@ -185,7 +185,7 @@ on_person_list1_activate Sun, 22 Oct 2000 23:07:54 GMT - + False @@ -209,7 +209,7 @@ on_pedegree1_activate Sun, 22 Oct 2000 23:08:36 GMT - + False @@ -233,7 +233,7 @@ on_places_activate Tue, 14 Aug 2001 13:39:34 GMT - + False @@ -3094,8 +3094,6 @@ GtkVBox vbox11 - 400 - 400 False 0 @@ -3110,7 +3108,7 @@ 0 0 - 10 + 5 False False @@ -3118,82 +3116,21 @@ GtkHSeparator - hseparator18 + hseparator21 - 10 + 5 False True - GtkHBox - hbox29 - False - 0 - - 0 - False - True - - - - GtkLabel - label228 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 10 - 10 - - 0 - False - False - - - - - GtkCombo - rel_combo - True - True - False - True - False - - - 10 - True - True - - - - GtkEntry - GtkCombo:entry - rel_type - True - - changed - on_rel_type_changed - Sat, 14 Jul 2001 15:29:20 GMT - - False - True - 0 - - - - - - - GtkScrolledWindow - scrolledwindow9 - GTK_POLICY_NEVER - GTK_POLICY_ALWAYS - GTK_UPDATE_CONTINUOUS - GTK_UPDATE_CONTINUOUS + GtkFrame + frame5 + 5 + + 0 + GTK_SHADOW_ETCHED_IN 0 True @@ -3201,46 +3138,251 @@ - GtkCList - spouseList + GtkScrolledWindow + scrolledwindow9 + 10 400 - 450 - True - - select_row - on_spouseList_select_row - Sun, 19 Nov 2000 00:44:36 GMT - + 200 + GTK_POLICY_NEVER + GTK_POLICY_ALWAYS + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + + GtkCList + spouseList + True + + select_row + on_spouseList_select_row + Sun, 19 Nov 2000 00:44:36 GMT + + 2 + 256,80 + GTK_SELECTION_SINGLE + True + GTK_SHADOW_IN + + + GtkLabel + CList:title + label65 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkLabel + CList:title + label66 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + + + GtkFrame + frame4 + 5 + + 0 + GTK_SHADOW_ETCHED_IN + + 5 + False + True + + + + GtkTable + table25 + 2 2 - 203,80 - GTK_SELECTION_SINGLE - True - GTK_SHADOW_IN + False + 5 + 5 GtkLabel - CList:title - label65 - + label235 + GTK_JUSTIFY_CENTER False - 0.5 + 1 0.5 - 0 - 0 + 5 + 5 + + 0 + 1 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + GtkLabel - CList:title - label66 - + label236 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 5 + 5 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + GtkEntry + given + True + True + True + 0 + + + 1 + 2 + 0 + 1 + 5 + 5 + True + False + False + False + True + False + + + + + GtkEntry + surname + True + True + True + 0 + + + 1 + 2 + 1 + 2 + 5 + 5 + True + False + False + False + True + False + + + + + + + GtkFrame + frame6 + 5 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + True + + + + GtkVBox + vbox40 + False + 0 + + + GtkCombo + rel_combo + 5 + True + True + False + True + False + + + 0 + False + False + + + + GtkEntry + GtkCombo:entry + rel_type + True + + changed + on_rel_type_changed + Sat, 14 Jul 2001 15:29:20 GMT + + False + True + 0 + + + + + + GtkLabel + reldef + GTK_JUSTIFY_CENTER False 0.5 0.5 - 0 - 0 + 5 + 5 + + 0 + False + False + @@ -3267,11 +3409,11 @@ True clicked - on_select_spouse_clicked + on_new_spouse_clicked spouseDialog - Sun, 19 Nov 2000 00:52:25 GMT + Thu, 23 Aug 2001 21:21:10 GMT - GNOME_STOCK_BUTTON_OK + GTK_RELIEF_NORMAL @@ -3282,10 +3424,19 @@ True clicked - destroy_passed_object + on_select_spouse_clicked spouseDialog - Sun, 22 Oct 2000 20:51:13 GMT + Thu, 23 Aug 2001 21:21:01 GMT + + GTK_RELIEF_NORMAL + + + + GtkButton + button117 + True + True GNOME_STOCK_BUTTON_CANCEL GTK_RELIEF_NORMAL diff --git a/gramps/src/gramps_main.py b/gramps/src/gramps_main.py index 3af8a4ad6..7984489d3 100755 --- a/gramps/src/gramps_main.py +++ b/gramps/src/gramps_main.py @@ -123,7 +123,9 @@ ODDFGCOLOR = "oddForeground" ODDBGCOLOR = "oddBackground" EVENFGCOLOR= "evenForeground" EVENBGCOLOR= "evenBackground" - +GIVEN = "g" +SURNAME = "s" +RELTYPE = "d" #------------------------------------------------------------------------- # # Short hand function to return either the person's birthday, or an empty @@ -250,15 +252,22 @@ def on_remove_child_clicked(obj): #------------------------------------------------------------------------- def on_add_sp_clicked(obj): spouseDialog = libglade.GladeXML(const.gladeFile, "spouseDialog") + spouseList = spouseDialog.get_widget("spouseList") spouseDialog.get_widget("rel_combo").set_popdown_strings(const.familyRelations) rel_type = spouseDialog.get_widget("rel_type") rel_type.set_data("d",spouseList) - spouseDialog.get_widget("spouseDialog").set_data("d",rel_type) + rel_type.set_data("x",spouseDialog.get_widget("reldef")) + + top = spouseDialog.get_widget("spouseDialog") + top.set_data(RELTYPE,rel_type) + top.set_data(GIVEN,spouseDialog.get_widget("given")) + top.set_data(SURNAME,spouseDialog.get_widget("surname")) spouseDialog.signal_autoconnect({ "on_spouseList_select_row" : on_spouseList_select_row, "on_select_spouse_clicked" : on_select_spouse_clicked, + "on_new_spouse_clicked" : on_new_spouse_clicked, "on_rel_type_changed" : on_rel_type_changed, "destroy_passed_object" : utils.destroy_passed_object }) @@ -519,7 +528,7 @@ def on_addchild_ok_clicked(obj): # must do an apply filter here to make sure the main window gets updated - apply_filter() + redisplay_person_list(person) load_family() utils.modified() utils.destroy_passed_object(obj) @@ -1358,6 +1367,56 @@ def on_select_spouse_clicked(obj): load_family() +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def on_new_spouse_clicked(obj): + global active_spouse + global select_spouse + global active_family + + select_spouse = Person() + database.addPerson(select_spouse) + name = Name() + select_spouse.setPrimaryName(name) + name.setSurname(string.strip(obj.get_data(SURNAME).get_text())) + name.setFirstName(string.strip(obj.get_data(GIVEN).get_text())) + + reltype = const.save_frel(obj.get_data(RELTYPE).get_text()) + if reltype == "Partners": + select_spouse.setGender(active_person.getGender()) + else: + if active_person.getGender() == Person.male: + select_spouse.setGender(Person.female) + else: + select_spouse.setGender(Person.male) + + utils.modified() + active_spouse = select_spouse + + family = database.newFamily() + active_family = family + + active_person.addFamily(family) + select_spouse.addFamily(family) + + if active_person.getGender() == Person.male: + family.setMother(select_spouse) + family.setFather(active_person) + else: + family.setFather(select_spouse) + family.setMother(active_person) + + family.setRelationship(const.save_frel(obj.get_data("d").get_text())) + + select_spouse = None + utils.destroy_passed_object(obj) + + redisplay_person_list(active_spouse) + load_family() + #------------------------------------------------------------------------- # # @@ -1474,8 +1533,12 @@ def on_rel_type_changed(obj): spouse_list = obj.get_data("d") spouse_list.clear() spouse_list.freeze() + deftxt = obj.get_data("x") + text = obj.get_text() + deftxt.set_text(const.relationship_def(text)) + gender = active_person.getGender() if text == _("Partners"): if gender == Person.male: